node.js与jsonloader上的三个.js冲突
我还有最后一个问题。 在节点服务器中,我加载.json文件并放入场景以检测冲突 节点: 要检测碰撞,请执行以下操作:node.js与jsonloader上的三个.js冲突,json,node.js,three.js,collision-detection,Json,Node.js,Three.js,Collision Detection,我还有最后一个问题。 在节点服务器中,我加载.json文件并放入场景以检测冲突 节点: 要检测碰撞,请执行以下操作: var collisions, i, // Maximum distance from the origin before we consider collision distance = 32, // Get the obstacles array from our world ob
var collisions, i,
// Maximum distance from the origin before we consider collision
distance = 32,
// Get the obstacles array from our world
obstacles = GameEngine.getInstance().collidableMeshList;//basicScene.world.getObstacles();
// For each ray
for (i = 0; i < this.rays.length; i += 1) {
// We reset the raycaster to this direction
this.caster.set(this.design.position, this.rays[i]);
// Test if we intersect with any obstacle mesh
collisions = this.caster.intersectObjects(obstacles);
// And disable that direction if we do
if (collisions.length > 0 && collisions[0].distance <= distance) {
// Yep, this.rays[i] gives us : 0 => up, 1 => up-left, 2 => left, ...
if ((i === 0 || i === 1 || i === 7) && this.direction.z === 1) {
console.log("collisions"); //
} else if ((i === 3 || i === 4 || i === 5) && this.direction.z === -1) {
console.log("collisions");
}
if ((i === 1 || i === 2 || i === 3) && this.direction.x === 1) {
console.log("collisions");
} else if ((i === 5 || i === 6 || i === 7) && this.direction.x === -1) {
console.log("collisions");
}
}
}
当我在客户端像这样加载时,它是不正常的:
$.getJSON("essai/lobby.js", function(data) {
var model = loader.parse( data );
var mesh = new THREE.Mesh( model.geometry, new THREE.MeshBasicMaterial() );
mesh.scale.set(40,40,40);
scene.add(mesh);
animate();
});
没有错误,但没有显示任何内容
所以我认为服务器端也是如此,为什么冲突永远不会被检测到
在服务器端,我不使用animate(),因为我认为这不是必需的。
还有取下我车的计算器没问题
所以我想可能加载程序没有正确加载网格,或者我不能像在客户端那样进行检测冲突。
你觉得怎么样
Thx
要检测客户端上的冲突,我使用:
this.rays = [
new THREE.Vector3(0, 0, 1), //up
new THREE.Vector3(1, 0, 1), //up left
new THREE.Vector3(1, 0, 0), //left
new THREE.Vector3(1, 0, -1), // down left
new THREE.Vector3(0, 0, -1), //down
new THREE.Vector3(-1, 0, -1), // down right
new THREE.Vector3(-1, 0, 0), //rigth
new THREE.Vector3(-1, 0, 1) //up right
];
this.caster = new THREE.Raycaster();
this.direction = new THREE.Vector3(0, 0, 0);
当我启动时,我设置了方向:this.direction.set(0,0,1);
当我向下时,我设置方向:this.direction.set(0,0,-1);
...
更新:
经过多次测试后,碰撞检测到一个对象。
我发现Mesh在服务器端或客户端都是一样的,但没有考虑加载后json对象的规模
因此,在加载并更改比例后,我尝试在node.js服务器中创建一个scene.updateMatrix(),但都是一样的
你有什么办法来解决我的问题吗?嗯,想知道这里发生了什么有点困难。我的2美分:检查双方解析的json是否相同,具体看数字格式;此外,渲染网格后会进行一些three.js计算,因此您应该像客户端一样设置动画/渲染网格,以确保这一点。在
loaders/JSONLoader.js
和loaders/Loader.js
中添加一些调试语句也可以帮助解决这个问题。Thx,我已经尝试过检查,但我看不到网格的区别。我尝试将服务器的mesh发送到客户端以查看渲染器,但json出现循环错误。我将尝试调试更多。你认为,我可以使用文件夹“example”的ColladaLoader来加载node.js中的模块three.js,因为我不能用require()加载这个文件吗?(尝试使用.dae文件)应该是可能的,但您将遇到与此处的其他问题相同的问题(您需要阅读该文件,然后手动解析它)
$.getJSON("essai/lobby.js", function(data) {
var model = loader.parse( data );
var mesh = new THREE.Mesh( model.geometry, new THREE.MeshBasicMaterial() );
mesh.scale.set(40,40,40);
scene.add(mesh);
animate();
});
this.rays = [
new THREE.Vector3(0, 0, 1), //up
new THREE.Vector3(1, 0, 1), //up left
new THREE.Vector3(1, 0, 0), //left
new THREE.Vector3(1, 0, -1), // down left
new THREE.Vector3(0, 0, -1), //down
new THREE.Vector3(-1, 0, -1), // down right
new THREE.Vector3(-1, 0, 0), //rigth
new THREE.Vector3(-1, 0, 1) //up right
];
this.caster = new THREE.Raycaster();
this.direction = new THREE.Vector3(0, 0, 0);