Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding linear interpolation support to Object3DSync behavior #178

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Adding linear interpolation support to Object3DSync behavior #178

wants to merge 5 commits into from

Conversation

NGenesis
Copy link
Contributor

Updated Object3DSync behavior to support linear interpolation for position and scale updates, and spherical linear interpolation for rotation updates, which aids in smoothing out jerky object synchronization.

Interpolation is currently enabled by default, and can be explicitly enabled or disabled on creation of the behavior with config parameters. For example:
obj.addBehavior(Object3DSync({ position: true, rotation: true, scale: true, lerp: { position: true, rotation: true, scale: false, duration: 150 } }));

@smsithlord
Copy link

Just want to suggest that sometimes a "speed" is useful to use instead of a duration of the total lerp. This would allow an object to always lerp-sync at the same speed regardless of the distance of the lerp.

@NGenesis
Copy link
Contributor Author

NGenesis commented Dec 19, 2016

Thanks for the suggestion @smsithlord, I'll take a look at revising for speed over duration sometime this week.

I have also been debating whether the lerp algorithm should be applied by default. Is this going to cause any notable issues with existing apps that expect objects to snap from one position to another? Any thoughts on this?

@brianpeiris
Copy link
Contributor

Thanks for tacking this @NGenesis. I agree about lerping at a constant speed.
You shouldn't have to worry about breaking existing apps, since the SDK library is versioned. However, I would still opt for disabling lerping by default, since it could be quite surprising if all you want is a basic transform sync.

}
else {
object3d.scale.set(value.scale.x, value.scale.y, value.scale.z);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to separate this new code out into helper functions, since setupReceive is quite large at this point.

Also, you may be able to refactor a lot of the code into a shared helper, since the lerping operations are almost identical for position, rotation and scale.

Same applies to the code in update below.

@smsithlord
Copy link

Off by default might be best. If the coder is doing stuff like testing object distances to detect a game event, they probably expect the objects to snap to position on clients. I do expect most people to always use it though. The side-effects of lerp syncing on clients is minimal.

Another useful behavior to consider is a "lerpMove" behavior that animates object transforms on the local PC as well, but special care must be given to make a lerpMove behavior play nice with a lerpSync behavior on the same object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants