30 Sept 2020

How to Draw Triangle using Threejs?


Are you trying to create a Triangle using Threejs? Have you tried already? And Have you Drawn Triangle

If No,  then see codes.

Process to achieve Triangle:- 
  • Create geometry object.
  • Passing three vertices and one Face3 which takes 3 argument, index number of indices of triangle.
  • Create triangle Mesh object.
  • At end calling scene.add( triangle ) to render on screen.

  
  var geometry = new THREE.Geometry();
    geometry.vertices.push(new THREE.Vector3(1,0,0));
    geometry.vertices.push(new THREE.Vector3(0,1,0));
    geometry.vertices.push(new THREE.Vector3(-1,0,0));
    
    geometry.faces.push ( new THREE.Face3(0,1,2) );
    
    var triangle = new THREE.Mesh( geometry , new THREE.MeshBasicMaterial());
    
    scene.add(triangle );
    
  
  

Reaction:

No comments:

No Comments

COMMENT FROM MESSAGE