Reputation: 1214
Due to making some simple multiplayer game, I have chosen THREE.js for implementing graphics at browser side. At the browser everything works fine.
Then I thought: Server have to check out most of user actions. So I WILL need to have world copy on a server, interact it with users and then give it's state back to users.
So, As the good piece of code had been written for client side - I just made it node.js compatible and moved on. (Good collision detection, which could use object.geometry
- is what I wanted so bad)
As a result, collision detection code stopped working. On the server side Raycaster exits on the string
} else if ( object instanceof THREE.Mesh ) {
var geometry = object.geometry;
// Checking boundingSphere distance to ray
if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
sphere.copy( geometry.boundingSphere );
sphere.applyMatrix4( object.matrixWorld );
if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
return intersects; // _HERE_
}
And that happens, because object.matrixWorld
Is Identity matrix.
But object initialization is made. mesh.position
and mesh.rotation
are identical on server and client( in browser, raycaster works as a charm);
I thinking, that, object.matrixWorld
would update somewhere in renderer.render(self.three_scene, self.camera);
. But of course, that's not what I want to do at server side.
So the question is: How to make object.matrixWorld
update in each simulation tick on the server-side?
Or, maybe advice, if there's some other way to get something simular to what I want.
Upvotes: 0
Views: 578
Reputation: 1214
Okey.
That was simple.
renderer.render
updates matrices of the whole scene recursively. The entrance of the recursion is updateMatrixWorld()
function of Object3D instance.
So, before we use Raycaster on the server-side we should call this method for each mesh in collidable meshes list.
Upvotes: 1