va3c / GHvA3C

Grasshopper plugin to export three.json files that can be loaded by the vA3C viewer
http://va3c.github.io/viewer/grasshopper2.html
20 stars 27 forks source link

Mesh with colored faces component #3

Closed bhowes-tt closed 9 years ago

bhowes-tt commented 9 years ago

Create a component that takes a mesh and a list of colors (as well as optional attribute names and values) and outputs a json representation of the mesh, and materials for all of the necessary materials.

We'll do typical GH iteration in the component - if there are fewer colors than faces, we'll use the last color for all remaining faces. IF there are fewer faces then colors, we'll ignore the extra colors.

This will be useful for displaying Ladybug/Honeybee meshes, for example.

bhowes-tt commented 9 years ago

This is working, but the output is super heavy and we need a post process function in the viewer side to actually make the colors show up. Took forevah to figure that out. The face materialindex properties were all set to 0, which made all faces the color of the first face. I think deep solution is related to a comment in #4 --- we need to be setting the faces' material indexes in the json file. Not sure if I'll include this one in the 0.2 release either ... If I can get a viewer out there in time, then maybe.

bhowes-tt commented 9 years ago

BUT! I need this for a project quick quick, and the one material per face model prooves to be super heavy with an 11k face mesh - slows the renderer to a crawl. We need to hack the face material index map into the json file somehow, and minimize the number of materials we include the MeshFaceMaterials.Materials array.

bhowes-tt commented 9 years ago

Improved! Much lighter when we only export unique materials. The code on the viewer side isn't too bad either ... not ideal, but good enough for now...

theo-armour commented 9 years ago

@bhowes-tt

Create a component that takes a mesh and a list of colors (as well as optional attribute names and values) and outputs a json representation of the mesh, and materials for all of the necessary materials.

It is not clear to me why you are trying to give each face its own material.

The usual way is to provide a mesh with a single material (or just a few ) and then assign colors to vertices.

To show you this, I have added to the Viewer Cookbook a Three.js models with vertex colors. See:

http://va3c.github.io/viewer/cookbook/vertex-colors/r1/vertex-colors-r1.html

I am now going to add export capability so you can see what the JSON representation of these models looks like. These, hopefully, will give you the clues as to what and how Grasshopper needs to do the export.

theo-armour commented 9 years ago

R2 is up

http://va3c.github.io/viewer/cookbook/vertex-colors/r2/vertex-colors-r2.html

Adds button to export geometry.

Exported geometry appears to load correctly in the vA3C Editor and the Three.js Editor.

bhowes-tt commented 9 years ago

@theo-armour thanks for this! Yeah I know I'm missing something here. I'm using the MeshFaceMaterial now, which does need an array of materials to work, but I thought there was also a way to do this with a typical lambert or basic material and set the colors on the three.js faces.

I think for the latter to work, I have to assign colors to vertices (and in this case maybe even materials to faces) as described in the format3 spec when authoring the json files, but I haven't taken the time to figure it out / give it a try. Seeing some json files with faces formatted like this would be super helpful, so again , thanks a bunch. related to comments in #4 as well.