javascript - Issue with custom geometry and face normal -
i'm quite new threejs , have small issue (probably wrong usage). i'm trying create custom geometry , define faces normals myself.
i create 1 normal in 1 direction , other 1 in opposite direction, mesh not 2 sided expect see 1 of face, can see both of them... idea of i'm doing wrong ?
thanks!
<body> <script src="../build/three.js"></script> <script src="js/stats.js"></script> <script> var container, stats; var camera, scene, renderer; container = document.createelement( 'div' ); document.body.appendchild( container ); scene = new three.scene(); camera = new three.perspectivecamera( 45, window.innerwidth / window.innerheight, 1, 2000 ); camera.up.x = 0; camera.up.y = 0; camera.up.z = 1; camera.position.x = 300; camera.position.y = -1000; camera.position.z = 1000; camera.lookat(new three.vector3(300, 250, 0)); scene.add( camera ); var light, geometry, material; scene.add( new three.ambientlight( 0x404040 ) ); light = new three.directionallight( 0xffffff ); light.position.set( 0, 1, 0 ); scene.add( light ); material = new three.meshbasicmaterial( { color: 0xffff00, wireframe: false, transparent: false, opacity: 1 } ); geometry = new three.geometry(); geometry.vertices.push(new three.vector3(0,0,0)); geometry.vertices.push(new three.vector3(600,0,0)); geometry.vertices.push(new three.vector3(0,-500,0)); geometry.vertices.push(new three.vector3(600,-500,0)); var face; face = new three.face3(0,2,1); face.normal.set(0,0,-1); geometry.faces.push(face); face = new three.face3(2,3,1); face.normal.set(0,0,1); geometry.faces.push(face); geometry.computecentroids(); //geometry.computefacenormals(); //geometry.computetangents(); var mesh = new three.mesh(geometry, material); scene.add(mesh); renderer = new three.webglrenderer( { antialias: true } ); renderer.setsize( window.innerwidth, window.innerheight ); container.appendchild( renderer.domelement ); renderer.render( scene, camera ); </script> </body>
webglrenderer uses vertex order in created face defining orientation instead of normal. try doing this:
face = new three.face3(2,1,3);
Comments
Post a Comment