Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertex / Face colors #96

Open
markhats opened this issue Jul 19, 2013 · 11 comments
Open

Vertex / Face colors #96

markhats opened this issue Jul 19, 2013 · 11 comments

Comments

@markhats
Copy link

Just wondered if anyone had got vertex or face colors to work? Variations of the following code always seem to give me a white sphere:

Three.SphereGeometry spheregeometry = new Three.SphereGeometry(5.0, 10, 10);

spheregeometry.colors = new List<Three.Color>(spheregeometry.vertices.length);

// First, assign colors to vertices as desired
for (int i = 0; i < spheregeometry.vertices.length; i++) 
{
   spheregeometry.colors[i] = new Three.Color().setRGB(77, 115, 153);
}

for (int i = 0; i < spheregeometry.faces.length; i++) 
{
   var face = spheregeometry.faces[i];

   // face.color.setRGB(77, 115, 153);

   // Determine if face is a tri or a quad
   int numberofsides = (face is Three.Face3) ? 3 : 4;

   face.vertexColors = new List<Three.Color>(numberofsides);

   // Assign color to each vertex of current face
   for (int j = 0; j < numberofsides; j++)  
   {
      var vertexindex = face.indices[j];

      // Initialize color variable
      face.vertexColors[j] = spheregeometry.colors[vertexindex]; 
   }
}            

Three.Material material = new Three.MeshBasicMaterial( 
      color: 0xffffff, shading: Three.FlatShading, 
      vertexColors: Three.VertexColors);

Three.Mesh spheremesh = new Three.Mesh(spheregeometry, material);

scene.add(spheremesh);

Anything obvious I'm doing wrong?

@johndoe837
Copy link

what does spheregeometry.faces.length do?

@markhats
Copy link
Author

Gives you the number of faces in the sphere geometry I'm assuming. It's just a list.

@johndoe837
Copy link

thank you - by the way, how does it different from spheregeometry.vertices.length?

@markhats
Copy link
Author

So it steps through each face and determines whether it's a tri or a quad face and then steps through each vertex of the face and assigns a color to it. I think you should also be able to set a color to all the vertices in the face, which is the commented out line. However, this doesn't work either.

@markhats
Copy link
Author

spheregeometry.vertices.length is the total number of vertices that make up all the faces. Each face has 3 (tri) or 4 (quad) vertices.

@johndoe837
Copy link

very nice, thank you indeed. one more question, do you know how I can select the neighboring faces of the selected face?

@johndoe837
Copy link

i.e. if I select the face[38] I also want to get neighboring face such as face[36] face[37]

@markhats
Copy link
Author

I'm not sure if there is an easy way to do this. You may have to go through each face and test for adjacency of all the other faces which will be quite an expensive operation if you have a lot of faces.

Did you manage to get vertex/face colors working then as per the original issue?

@johndoe837
Copy link

not yet though. I just found out the indices of the neighboring faces have a pattern. For an example, if the index of the selected mesh is odd number X, the indices of the neighboring faces would go like X-1, X+1, X+1+20. In other case, if the index of the selected mesh is even number Y, the indices of the neighboring faces would go like Y-1, Y+1, Y-1+20. I think I will start from writing a new function from here which would be called recursively.

@markhats
Copy link
Author

OK - sounds good. Let me know if you manage to get the vertex colors working as I haven't had any success.

@johndoe837
Copy link

sure, I will do :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants