Jerry Asher
Jerry Asher

Reputation: 886

How do I change the basic parameters of a Geometry in Three.js (for example, radius, number of vertices, etc.)

I create a tetrahedron of radius 3

   // create a tetrahedron
   var tetGeometry = new THREE.TetrahedronGeometry(3);
   var tetMaterial = new THREE.MeshLambertMaterial(
        {color: 0x20f020, transparent:true, opacity:0.6});
   tet = new THREE.Mesh(tetGeometry, tetMaterial);
   tet.name='tet';
   tet.castShadow = true;

Later, I want the tetrahedron to grow:

   // change hedron
   scene.getObjectByName('tet').radius = control.hedronRadius;

That doesn't work.

   // change vertices
   scene.getObjectByName('tet').detail = control.hedronVertices;

That doesn't work either.

   scene.getObjectByName('tet').verticesNeedUpdate;

And this doesn't help.

So how do I change the radius of a tetrahedron (or any Geometry) and how do I change the vertices.

In the documentation I see references to:

And also references to bones and skeletons and skinned meshes used to animate geometries.

How do I change these aspects of Geometries in general?
What's the most reasonable, suggested way then to grow the radius of a Tetrahedron, or change the number of vertices show it becomes a different number polyhedron?

Upvotes: 0

Views: 901

Answers (1)

MrFreeman555
MrFreeman555

Reputation: 98

To change geometry you need to use:

morphTargets: true

I've prepared an example using a tetrahedron as you mention in jsfiddle. Use sliders to change geometry.

To make some custom vertices and "fill" them by faces, you need to understand a lot of things from math, like; point, vector, etc.

I've done 2 simple flat objects, triangle and square in jsfiddle.

I hope that you'll easy understand how it works in general.

Upvotes: 1

Related Questions