Note that there are some explanatory texts on larger screens.

plurals
  1. POThree.js custom geometry problems with rotation
    primarykey
    data
    text
    <p>I have just started working with Javascript and specifically three.js. I have a custom Geometry that i have used to create a triangular prism. It has produced the correct shape but when it is rotated some of the faces don't look right. The other built in geometries (CubeGeometry, CylinderGeometry...) work just fine. Does it have to do with my custom Geometry or does it have something to do with lighting? Or the Mesh or Material?</p> <p>Here is the fiddle for an example of what is happening: <a href="http://jsfiddle.net/JLKCU/1/" rel="nofollow" title="3D Shapes Fiddle">3D Shapes Fiddle</a></p> <p>Here is the relevant code:</p> <pre><code>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 ); } </code></pre> <p>I am pretty new to three.js and especially 3D rendering and any help is appreciated. Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload