rainerpl

Assign a material to a mesh created using CreateLines

Recommended Posts

Hi,

I created a mesh using CreateLines function. The function works as it should, but the lines are drawn white. 
I tried giving it a material, but it throws an error, telling me there is no setter. 

I tried modifying using mesh.material.setColor3 and 4 and other properties, but they had no effect.
How can i change the color of the lines. And also give the lines some shading, just like wireframe materials do.

PS: i cant use regular mesh with wireframe material because it creates triangles and adds extra lines. E.g if i draw a square face, then wireframe view shows diagonals too.( like 2 triangles )

Share this post


Link to post
Share on other sites

I guess the Lines object doesn't support any material for now.

The color is set at creation time only (not sure)

NOTE to myself : add per vertex color on Lines and LineSystem, add color updates, etc ...

Share this post


Link to post
Share on other sites

mesh.color = new BABYLON.Color3(1, 0, 0)

This works, and assigns a color, but the lines/color is not shaded like it is when using wireframe material.

Is there an option to enable shading ?

Share this post


Link to post
Share on other sites

yuh yuh yuh... umm... no no no.  :)  Rainy... you cannot use LinesMesh to do what you seek. 

For example, if you "plotted" all 12 triangular faces of a box, using linesMesh, the box cannot be rendered solid.   Not easily.

It CAN be, but it requires a fancy converter that will be doing lots of guessing. 

The lines seen in a linesMesh... are not the same as the indices seen when a standard mesh has .material.wireframe = true.

"Plotting" a mesh... vertex by vertex... is often done using the vertexData object that is associated with most mesh.  The vertexData object has functions to make mesh shapes, and it stores that information in arrays, on the vertexData object.  Almost every BJS mesh... has a vertexData object as it's best friend and shape-holder.  Let's look at some basic mesh plotting (not using linesMesh at all)...

http://www.babylonjs-playground.com/#1UHFAP#67

There is some basic plotting.  That playground...

1. plots some vertices (positions), with little numbered boxes to assist
2. draws some indices (connects vertices together into triangles, counter-clockwise)
3. plots some badly-aimed lighting normals (they tell which way light bounces off vertex positions) (I just guessed the values, change at will)
4. sets some colors-per-vertex.  You could also set blankmesh.material = new BABYLON.StandardMaterial(etc etc)... but you can only set diffuseColor and emissiveColor, etc.  No diffuseTexture or emissiveTexture... because, nobody set any UV's on blankmesh's vertexData object.  UV's are needed so a texture knows how to map-onto a mesh.  So, if you add material, only COLORS can be set on that material.

Okay, heck, let's set some badly-programmed fake UVs, add a material to blankmesh, turn-off colorsPerVertex, and try some grass texture.

http://www.babylonjs-playground.com/#1UHFAP#68

Our grass is all over the place, but it works.  Changing the UV values in lines 93-100 will change the grass, but you need to know about UV's to truly master the texture mapping.  Manual plotting is not very easy, and that is why most people use math to assist.

That's enough about manual plotting for now.  Again, linesMesh was not made for plotting a solid mesh.  It can be used to create a "fake" wire-framed mesh, but that mesh cannot be solid-rendered or material-shaded like standard BJS primitive shapes. 

There is a lot to learn about plotting mesh... but it CAN be learned... with patience and persistence.  We're here to help, but for now, drop the idea of plotting solid mesh... using linesMesh.  LinesMesh were not invented for that purpose.

If you must want-to learn to plot mesh by hand, start with these two playgrounds... and experiment, experiment, experiment.  Cool?  Cool.  :)  We have many many functions to get/set all positions-kind, indices-kind, normals-kind, uvs-kind, and colors-kind array-based data... on a mesh's vertexData object.  Some of those kinds use 3 values for each vertex (positions, normals, indices), some use 2 values (uvs) and some use 4 values (colors).  SO much to learn, huh?   

Colors (vertexData colors-kind) are rarely used.  More often, the colors are set using a material.  I used color-per-vertex colors in MY plotting playground... because I think the color dithering is pretty.  :) 

Aw heck, let's keep the grass material active... AND turn ON the color-per-vertex colors again, and see what it looks like.  http://www.babylonjs-playground.com/#1UHFAP#69

Goooofy looking!  Rainbow grass.  :)  By the way, ignore all "Repeat 5 times" comments.  Those are old comments from a different playground.  I forgot to remove them.  There's no repeating happening in the grass texture, with these playground scenes.

 

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.