js自定义旋转几何问题
Three.js custom geometry problems with rotation
我刚刚开始使用Javascript,特别是three.js。我有一个自定义的几何体,我用它来创建一个三角形的棱镜。它已经产生了正确的形状,但当它旋转时,一些面看起来不正确。其他内置几何(立方体几何,圆柱体几何…)工作得很好。它是否与我的自定义几何有关,还是与照明有关?或网格或材料?
下面是小提琴的一个例子:3D形状小提琴
相关代码如下:
function getTriPrismGeometry(){
var geometry = new THREE.Geometry()
geometry.vertices.push( new THREE.Vertex(new THREE.Vector3( -100, 100, 0 )) );
geometry.vertices.push( new THREE.Vertex(new THREE.Vector3( -100, -100, 0 ) ));
geometry.vertices.push( new THREE.Vertex(new THREE.Vector3( 100, -100, 0 )) );
geometry.vertices.push( new THREE.Vertex(new THREE.Vector3( -100, 100, -100 )) );
geometry.vertices.push( new THREE.Vertex(new THREE.Vector3( -100, -100, -100 ) ));
geometry.vertices.push( new THREE.Vertex(new THREE.Vector3( 100, -100, -100 )) );
geometry.faces.push( new THREE.Face3(0,1,2 ) );
geometry.faces.push( new THREE.Face3(3,4,0 ) );
geometry.faces.push( new THREE.Face3( 0, 1, 4 ) );
geometry.faces.push( new THREE.Face3( 1, 4, 5 ) );
geometry.faces.push( new THREE.Face3( 1, 2,5) );
geometry.faces.push( new THREE.Face3( 2, 0, 3 ) );
geometry.faces.push( new THREE.Face3( 2, 3, 5 ) );
geometry.faces.push( new THREE.Face3( 3,4, 5 ) );
geometry.computeCentroids();
geometry.computeFaceNormals();
geometry.computeVertexNormals();
init(geometry, true);
}
function init(geometry, isCustom) {
camera = new THREE.PerspectiveCamera( 75, width/height, 1, 10000 );
camera.position.z = 300;
scene = new THREE.Scene();
material = new THREE.MeshLambertMaterial( { color: 0xff0000 } );
mesh = new THREE.Mesh( geometry, material );
if (isCustom){
material.side = THREE.DoubleSide;
mesh.doubleSided = true;
}
scene.add( mesh );
ambient = new THREE.AmbientLight( 0x101010 );
ambient.position.set(0, -70, 100).normalize();
scene.add( ambient );
directionalLight = new THREE.DirectionalLight( 0xffffff );
directionalLight.position = camera.position;
scene.add( directionalLight );;
}
function animate() {
// note: three.js includes requestAnimationFrame shim
requestAnimationFrame( animate );
render();
}
function render(){
var delta = Date.now() - start;
directionalLight.position = camera.position;
//mesh.position.y = Math.abs( Math.sin( delta * 0.002 ) ) * 150;
mesh.rotation.x = delta * 0.0003;
mesh.rotation.z = delta * 0.0002;
renderer.render( scene, camera );
}
我对three.js非常陌生,尤其是3D渲染,任何帮助都很感激。提前感谢!
在自定义几何体中,您需要按逆时针顺序指定面顶点。
修复后,您的自定义几何就可以了。
还可以从当前的三个.js示例中学习。您的代码正在使用过时的模式。例如,Vertex
已弃用。这个新模式是:
geometry.vertices.push( new THREE.Vector3( -100, 100, 0 ) );
http://jsfiddle.net/JLKCU/3/three.js r.54
相关文章:
- 在指令控制器中使用$attrs时出现问题
- 将PHP变量传递给jQuery时遇到问题
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- 参数变量出现ngTable指令问题
- 剑道网格jQuery动画()问题
- 我的jQuery插件参数没有正确启动,遇到了问题
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- TableExport jquery插件:文件名和扩展名问题
- JavaScript Pub/Sub属性访问问题
- JavaScript异步问题
- 如何解决Yii中的页面刷新问题
- Safari(Mac OS)上的jQuery平滑滚动问题
- jqGrid树网格问题
- 使用正则表达式评估电子邮件地址时出现性能问题
- 如何消除代码中的未定义和其他问题
- Flexislider缩略图单击问题-中间问题
- JqGrid的问题和问题
- slideup函数不适用于动态问题(静态问题可以)
- 任何人都知道为什么 XHTML 中没有类型属性“text/css”的