Jump to content

Multimaterial on PolygonMeshBuilder


AndyBeaulieu
 Share

Recommended Posts

Hello, it's been awhile since I've posted here but it's great to be back on a little babylon project!

Short version:

In this playground test, I would like to have the TOP side of any PolygonMesh to be colored Red, and the other sides Blue (as you can see, it is not correct yet)

     http://www.babylonjs-playground.com/index2_5.html#Y4KHN8

 

Longer version:

I am using PolygonMeshBuilder to create a Mesh from a set of 2D Vertices.  The number of vertices is not known until runtime.

I would like to set the TOP side of the extruded mesh to a different material, so I am creating a Multimaterial. But I am struggling with getting the parameters correct when applying the multimaterial to the subMeshes :(

        polygonMesh.subMeshes.push(new BABYLON.SubMesh(1, 0, verticesCount, 0, lastTopVertex, polygonMesh));
        polygonMesh.subMeshes.push(new BABYLON.SubMesh(0, 1, verticesCount, lastTopVertex, verticesCount + lastTopVertex, polygonMesh));
 

My fallback plan is to just create a separate Mesh for the Top, but this is bugging me :)

Thanks for any ideas.

Link to comment
Share on other sites

A new feature that uses polygonmeshbuilder has just been added called ExtrudePolygon

A PR has just been submitted that will allow the top sides and bottom to have different colors or textures using code such as

faceColors = [];
faceColors[0] = new BABYLON.Color4(1, 0, 0);
faceColors[1] = new BABYLON.Color4(0, 0, 1);
faceColors[2] = new BABYLON.Color4(0, 1, 0);
 
var polygonMesh = BABYLON.MeshBuilder.ExtrudePolygon("poly", {shape:shape, depth: height, faceColors: faceColors}, scene);

Adapting this to your PG gives

 

gfpic.jpg.276dd2bf8f16e745bb03f610778594eb.jpg

Unfortunately it might be a couple of days or so before PR goes live in the playground and I can give you working code in the PG.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...