javascript Three.js 绘制简单的三角形
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16279557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Three.js Draw simple triangle
提问by Zheden
I'm trying to draw triangle with three.js:
我正在尝试用three.js绘制三角形:
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 100;
scene.add( camera );
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild( renderer.domElement );
var geom = new THREE.Geometry();
var v1 = new THREE.Vector3(0,0,0);
var v2 = new THREE.Vector3(30,0,0);
var v3 = new THREE.Vector3(30,30,0);
console.log(geom.vertices)
geom.vertices.push(new THREE.Vertex(v1));
geom.vertices.push(new THREE.Vertex(v2));
geom.vertices.push(new THREE.Vertex(v3));
geom.faces.push( new THREE.Face3( 0, 1, 2 ) );
geom.computeFaceNormals();
var mesh= new THREE.Mesh( geom, new THREE.MeshNormalMaterial() );
scene.add(mesh);
renderer.render( scene, camera );
But there is nothing on screen. However these examples are working: http://threejs.org/docs/58/#Manual/Introduction/Creating_a_scenehttps://github.com/tonylukasavage/jsstl(triangles here are created the same way I'm trying to do)
但是屏幕上什么都没有。但是,这些示例正在运行:http: //threejs.org/docs/58/#Manual/Introduction/Creating_a_scene https://github.com/tonylukasavage/jsstl(这里的三角形的创建方式与我正在尝试的方式相同)
Could you please help me to find a problem? Thanks, Ievgeniia
你能帮我找出问题吗?谢谢,叶夫根尼娅
回答by WestLangley
Do this, instead:
这样做,而不是:
geom.vertices.push( v1 );
geom.vertices.push( v2 );
geom.vertices.push( v3 );
Are you copying outdated code from the net -- or from an outdated book? Learn from the three.js examples that work with the current version of the library.
您是从网上复制过时的代码还是从过时的书中复制过时的代码?从与库的当前版本一起使用的three.js 示例中学习。
three.js r.58
三.js r.58