var>n// Load Camera Perspektivenvar>camera.position.set( 1, 1, 150 );//the position of the object x,y,zn// Load a Renderernvar>renderer.setSize(window.innerWidth, window.innerHeight);ndocument.body.appendChild(renderer.domElement);nwindow.addEventListener(\"resize\", function(){renderer.setSize(window.innerWidth,>n// Load the Orbitcontrollernvar>n// Load Lightnvar>scene.add( ambientLight );nvar>directionalLight.position.set( 0, 1, 1 ).normalize();nscene.add( directionalLight );nvar>n);nfunction animate(){requestAnimationFrame(animate);renderer.render(scene, camera);}nanimate();
我看不到你的代码在哪里旋转任何东西-保持对模型的引用为>,然后你可以将model.rotatio
完全更改为立方体或任何其他类型的网格。一旦一个网格被加载,它从哪里来就无关紧要了。@donmccurdy
这是对这个问题的交叉发布:nhttps://stackoverflow.com/q/50420083/4045502727
谢谢,如果我想让它在某个时间间隔后旋转,我就这样做怎么样?
要点如下:nvar model;loader.load( \"foo.gltf\", function ( gltf ) += 0.01;
要获得更具体的答案,您需要显示您现在尝试旋转的代码,以及您看到的任何错误。
谢谢您的精彩代码!!
这是可行的,但它给了我一个“无法读取属性”的位置“未定义”错误。我的gltf模型以“car”作为标识符。动画功能中的参考是当我得到错误时。nvar scene, camera, renderer;function = new THREE.DirectionalLight( 0xffffff, 2 );directionalLight.position.set( -12, 10, -8 );scene.add( directionalLight = THREE.BasicShadowMap;// Resize to the size of the screenwindow.addEventListener(\"resize\", function() = new THREE.GLTFLoader();carLoader.load(\"scenes/bp_scene_6_car.gltf\", function ( gltf =>nYou\"ll need to wait for the car to load before trying to animate it. For example,nif (car)>nEven better, if it\"s just a one-time thing, set the position in the loader callback rather than in the animate function.nBrilliant! Thanks DonnCould you let me know what is wrong here?ninit();animate();function init() = THREE.sRGBEncoding;document.body.appendChild(renderer.domElement);window.addEventListener(\"resize\", function() = = new THREE.DirectionalLight(0xffffff, 1);light.position.set(0, = new THREE.CubeTextureLoader().load([path + \"posx\" + format, path + \"negx\" + format,path + \"posy\" + format, path + \"negy\" + format,path + \"posz\" + format, path + \"negz\" + = Math.PI / 2;model.scale.set(0.05, 0.05, 0.05);model.traverse(function(child) {if !== null) {model.rotation.x += 0.01;model.rotation.y += 0.01;renderer.render(scene, camera);}}
谢谢!
一个活生生的例子会很有帮助。
你看到那个女孩的旋转了吗?简单的完整代码示例问题我已经试过了,没那么难。但这花了我一段时间,因为我尝试了更复杂的事情,就像我经常做的那样。我更新了这个例子。女孩从更高的盒子里跳出来,转身走到起始位置。[2020-04-22 14.39.12]输入数据用代码固定。//---数据输入=新建3.Box3().setFromObject(…
请参阅LoadGLTFmove 38
感谢您的链接–虽然它没有旋转功能。
我不知道您真正需要什么。
在我的示例视图中-资料来源:LoadGLTFmove 28
模型以gltf.scene.rotation.set( 0, yRotation, 0 );旋转。
因为它没有居中,所以你必须在之后计算所需的位置。n* gltf.scene.position.set( xPosition - cx, size.y / 2 - c.y, zPosition - cz );
我也尝试过这样做,但当我这样做时,模型消失了。n*if (model) {model.rotation.x += 0.01;model.rotation.y += 0.01;}/pre>海亚姆:
我也尝试过这样做但是当我这么做的时候,模型就消失了。
这就是我的时尚板旋转的方式。n
我在看–你能告诉我旋转兔子三js页面的名称吗?
明白了!是 啊!
我对这个例子做了一些改变。这使得移动模型时更清晰,计算工作量更少。
更新:https://hofk.de/main/discussion.threejs/2020/LoadGLTF/LoadGLTF.html36n;;;;LoadGLTFmove=新3.webgl渲染器({反别名:true});.setSize( 窗口宽度, 窗内高度);document.body.appendChild( D.DomeElement);.setClearColor(0xAAAAA,1=新三点灯(0xddff00,1);lightP.position.set( -1, 3, 5 );scene.add(lightP);//---数据输入=新建3.GLTFLoader();//konta johanna混音(抄送人)(许可证)//https://poly.google.com/view/7PNIMdmMSPDloader.load(“女孩/谷歌聚谷氨酸转移酶,过程+=0.005;t+=x0+=new3.Box3().setFromObject(gltf.scene);>n How to rotate a gltf model in a specific directionn