Instancing offset models in LW2018

hurley

Active member
Not sure if this is a LW bug or a feature request. :)

My physics based plugins require meshes that are modeled centered on the origin in order to rotate correctly in the physics engine. I handle offset meshes in LW by changing the LW pivot point programmatically to the center of the mesh. This normally works fine, but when I'm instancing a mesh whose pivot point I have reset, the instance transforms don't respect the new pivot point of the source mesh and so don't work correctly. I can easily fix the translate part of the transform but I can't find any way to make the rotation part work correctly. Any ideas how I can get around this problem?
 

raw-m

Big fan of coffee
You could try parenting the object to a null, using the null as the pivot point. In the Instance Gen, point it at the null and click the little child/tree icon so it sees the object. (I may have misunderstood your issue, though!)
 

creacon

creacon
Without knowing exactly what you are doing, I wouldn't change the pivot, but (virtually) move the object to the center, add it to the physics engine and after the physic engine gives you the new position, move that back into place. Does that make sense?

creacon

Not sure if this is a LW bug or a feature request. :)

My physics based plugins require meshes that are modeled centered on the origin in order to rotate correctly in the physics engine. I handle offset meshes in LW by changing the LW pivot point programmatically to the center of the mesh. This normally works fine, but when I'm instancing a mesh whose pivot point I have reset, the instance transforms don't respect the new pivot point of the source mesh and so don't work correctly. I can easily fix the translate part of the transform but I can't find any way to make the rotation part work correctly. Any ideas how I can get around this problem?
 
Last edited:

hurley

Active member
No that wouldn't work for me. I'm using my own instance painter and I wouldn't want the user to have to jump through any hoops like that when using the tool.

In LW2015, instances are "parented" to the source item and I was able to get around this problem using some extra transformations but it doesn't work in LW2018.

Here's a video of the problem in LW2018

In LW2018, when I set the pivot point of the item being instanced, I need LW to remap the items's vertices to be relative to the new pivot point when I transform an instance of this item. But it doesn't do that, instead it uses the original vertices relative to the origin. In the video the red block works fine when modeled at the origin. The green block is offset to x = 3. You can see in the wireframe that I've reset it's pivot to be in the center of the mesh but when I paint green instances they are drawn in the wrong spot because LW sees their vertices as relative to the origin instead of their new pivot point.

Here's the code I'm using to transform the newly painted instance whose source mesh was not modeled on center

Code:
Pose pose = instance->spaceTime().worldTransform;
pose.scale(instance->spaceTime().scale);
Eigen::Vector3d pos = pose.translation().cast<double>();

// LW doesn't know that the source's pivot point has changed
// We can fix the position by subtracting the modeled offset
if (source->getState().hasModeledOffset())
{
	Affine3d t;
	t.translation() = pos + source->spaceTime().modeledOffset.cast<double>();
	t.linear() = pose.linear().cast<double>();
	//t.prerotate(t.linear());
	Eigen::Matrix3d rot = t.linear().cast<double>();

	pos -= source->spaceTime().modeledOffset.cast<double>();


	helpers.iFuncs->setMotionStepAuto(instID, helpers.time, step, pos.data(), rot.data());
}
 
Last edited:

hurley

Active member
Without knowing exactly what you are doing, I wouldn't change the pivot, but (virtually) move the object to the center, add it to the physics engine and after the physic engine gives you the new position, move that back into place. Does that make sense?

creacon

Nope, that won't work. The physics engine gives me back a new pose on every tick which I pass to the LW motion plugin. LW will rotate the mesh around it's pivot point so unless the mesh is modeled on center or the pivot point is changed, it just won't work.
 
Last edited:

creacon

creacon
The user doesn't have to jump through any hoops, you offset ( in code ) the object (the geometry) to the world's center. So it's like moving the pivot without moving the pivot.

creacon

No that wouldn't work for me. I'm using my own instance painter and I wouldn't want the user to have to jump through any hoops like that when using the tool.
 

hurley

Active member
The user doesn't have to jump through any hoops, you offset ( in code ) the object (the geometry) to the world's center. So it's like moving the pivot without moving the pivot.

creacon

Sorry, the "jump through hoops" was to raw-m's response.

I already automatically center each mesh in my own code before sending to the physics engine. The problem with what you're suggesting is that when I pass the rotation from the physics engine to LW MotionHandler it will rotate the vertices around the LW pivot point. So if the vertices aren't centered around the pivot point then the rotation will be wrong
 
Last edited:

jwiede

Electron wrangler
Sorry, the "jump through hoops" was to raw-m's response.

I already automatically center each mesh in my own code before sending to the physics engine. The problem with what you're suggesting is that when I pass the rotation from the physics engine to LW MotionHandler it will rotate the vertices around the LW pivot point. So if the vertices aren't centered around the pivot point then the rotation will be wrong

That it appears to be ignoring your programatic change of the pivot seems like a bug.

If you query the pivot after programmatically changing it, is it still reporting the original value?
 

hurley

Active member
That it appears to be ignoring your programatic change of the pivot seems like a bug.

If you query the pivot after programmatically changing it, is it still reporting the original value?

Hi John,

Setting the pivot point programmatically works fine generally. You can see that in the above video when I'm tweaking the green box with the new pivot point and it's rotating correctly. The problem is when instancing an object whose pivot point has been changed, LW does not remap the vertices of that object to be relative to the new pivot point. So when an instance receives a rotation matrix, it rotates the vertices around the original modeled pivot point and not the new pivot point and the instance is not drawn where the plugin wants to place it as in the above video
 

jwiede

Electron wrangler
So I take it this wasn't fixed in 2018.0.7?

Appears this wasn't fixed in LW2019 series either. Any chance of a fix in 2020.0?

Quite a few of us would really like to have AP plugin working again.

And if in the area fixing this for 2020, please also take a look at updating/completing the LWITEMINSTANCERFUNCS_GLOBAL APIs documentation? As in fix the modifyInstance reference, provide proper documentation on how to use/configure steps, and so forth? Explicitly stating instancer lifecycle rules (when creation & deletion are safe/unsafe, etc.) would also be useful, of course.
 
Last edited:
Top Bottom