Jump to content

how to assign mesh alpha for instances


davychen
 Share

Recommended Posts

hi guys,

i've a question, please help.

i have a tree mesh in the scene, and i created some instances of the tree to make a forest,

i expect when i walking through the forest, the trees far before my view to fade in from alpha 0 to alpha 1.

seting alpha of material works, but all instances has but one material,

i can't set separate trees to different alpha.

 

and if i set visibility of mesh, it doesn't work.

from this link:

http://doc.babylonjs.com/tutorials/Transparency_and_How_Meshes_Are_Rendered

i saw, to use mesh alpha, i need to export model with vertices alpha channel.

how can i do it with babylon exporter?

thank you.

Clipboard01.jpg

Link to comment
Share on other sites

48 minutes ago, Nabroski said:

camera.maxZ =
will do the trick in 99% 

here are more performance optimizations
http://doc.babylonjs.com/tutorials

playing around with alpha channel for trees ? 




 

 

thank you, Nabroski,

your tips really help.

it solves one of my problem,

my ground is large, and i can't cover all the area in sight with so many trees,

so thank you.

but i still want mesh alpha fading effect,

could you give more suggestions?:D

Link to comment
Share on other sites

57 minutes ago, Nabroski said:

Yes im out of time, its a value, you have to animate it in a certain way! Thank you Adam!

Bit sketchy and nooby:
http://www.babylonjs-playground.com/#1JZWGU#0

 

 

hi Nabroski,

thank you for the code sample,

but you know,

in this sample, transparent is set through alpha property of material.

in my case, all the trees are instances of one tree mesh,

all the instances share a common material,

if i set alpha of material,

all the trees will have same alpha level.:huh:

 

 

 

Link to comment
Share on other sites

I don't think you can on instances they would stay like their initial state , you would need to do a clone I believe.

(if im picking up what your laying down my bad if its off topic I was speed reading before work here)

and how are you setting the visibility? I would recomend using .setEnabled(false); on the mesh and drop it from the draw stack entirely.

Link to comment
Share on other sites

53 minutes ago, davychen said:

in my case, all the trees are instances of one tree mesh,

all the instances share a common material,

if i set alpha of material,

all the trees will have same alpha level.:huh:

 

This is my 296 Post in this Forum, and now you understand why

 

Link to comment
Share on other sites

Yeah so then

var originalMesh = getOriginalMesh();  
var newInstance = originalMesh.createInstance("index: " + index);

will make an exact duplicate of the object that shares a single reference to everything that is handled by draws like materials ect... things you can change are scale position and rotation.

now a

var newClone = originalMesh.clone("index: " + index);

Uses the same mesh for the draw but creates new references of materials so you can change them independently.  A clone is slightly more system intensive but is the way to reuse a mesh with a different material as apposed to doing a whole new draw call.

Link to comment
Share on other sites

23 hours ago, Pryme8 said:

Yeah so then


var originalMesh = getOriginalMesh();  

var newInstance = originalMesh.createInstance("index: " + index);

will make an exact duplicate of the object that shares a single reference to everything that is handled by draws like materials ect... things you can change are scale position and rotation.

now a


var newClone = originalMesh.clone("index: " + index);

Uses the same mesh for the draw but creates new references of materials so you can change them independently.  A clone is slightly more system intensive but is the way to reuse a mesh with a different material as apposed to doing a whole new draw call.

 

thank you, Pryme,

i think this will be the final solution.

thank you

 

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...