【发布时间】:2020-02-07 01:11:41
【问题描述】:
我正在用 Three.js 开发一个小型原型。我需要将 3D JSON 模型添加到长方体的其中一个面。我可以将 3D 模型加载到场景中,但无法将该模型添加到立方体的特定面。
三个.js 脚本
boxGeometry = new THREE.BoxGeometry(25, 25, 90, 7, 7, 7);
var material = [
new THREE.MeshBasicMaterial({ color: "#000000", wireframe:true}),
new THREE.MeshBasicMaterial({ color: "#000000", wireframe:true}),
new THREE.MeshBasicMaterial({ color: "#000000", wireframe:true}),
new THREE.MeshBasicMaterial({ color: "#666699", wireframe:false}),
// load 3D truck model to the mesh here, instead of the image
new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader().load( 'https://raw.githubusercontent.com/SatheeshKS10/MockRest/master/truck-front.png'), wireframe:false } ),
new THREE.MeshBasicMaterial({ color: "#000000", wireframe:true})
];
完整代码可见here
【问题讨论】:
-
您正在尝试将 3D 模型加载到材质中?您是什么意思“将该模型添加到脸部”?你为什么不改变模型的位置,让它坐在你想要的脸上?然后,您可以使用
THREE.Group将立方体和卡车组合在一起。 -
是的,我尝试改变模型的 x、y、z 轴的位置。但是我无法以正确的方式旋转对象以将其与长方体对齐,从而导致模型和长方体都处于不同的位置。你能告诉我如何将它们对齐吗?我将尝试使用 Three.Group 功能。
-
实际上“将该模型添加到脸部”的意思是,目前我将图像加载到长方体的脸部。我想用 3D 模型替换它。
标签: three.js model 3d load cube