Jump to content

Instances are broken.


Pryme8
 Share

Recommended Posts

Yea it works because it is just one, the demo demonstrates when instances break you have to do more then one of them.

Whats happening is I make a base mesh this is the only real mesh called, I then clone it to make 3 versions of it that can have different materials, then I am randomly picking from those three clones and creating an instance from one of the three and just placing them in the scene.

You will see the weird behavior the second a additional instance is made that is not the same as the first one created.

If you see here is the working version with just 1 instance being used: http://www.babylonjs-playground.com/#R35AE#0, then the second you start using the other ones it breaks.  This is the simplest PG I could think of to demonstrate.

You will see the second a different color sphere is picked from the first one made (red blue or green) all others that are not the same one disappear and they all like jump around trying to decided whos who it looks like.

Link to comment
Share on other sites

Ok that's fine and dandy, but what about when I run into the situation where I need to create instances of clones?  There is no reason why they should behave like this.  The reason I say that is what if I have a custom shape I want to load for example my hex block, and it has 64 different texture variations, you would need to be able to make instances of a clone.

and why would that break it? 

I mean thinking about it I guess its the same number of draw calls... but the behavior seems weird.

so how would I create multiple copy's of the loaded obj without clone also?

@adam, thanks by the way.


Its coming into play with my scene I am working on where:
 

lob.prototype._buildPresetHexs = function(){
	var hexList = ['Rock', 'Rock2Dirt']
	for(var p = 0; p<hexList.length; p++){		
	var ps = hexList[p];
	this.presets[ps] = [];	
	for (var i = 0; i<this.materials[ps].length; i++){	
		console.log(ps);	
		var nP = this.presets['hex'].clone(ps+i);		
		nP.material = this.materials[ps][i];
		nP.setEnabled(0);
		this.presets[ps].push(nP);
	}	
  }	
};

I am using clone to make fresh instances of the hex preset which was a loaded obj, is there a better way to do this?

Link to comment
Share on other sites

Ok so:

- Clones share the same geometry as their root

- Instances share everything with their root (including material)

- You can call CreateInstance on a clone but in this case all instances will have the initial geometry as root

 

You can still use clones but you then have to make them unique (kind of de-cloning):

http://www.babylonjs-playground.com/#R35AE#4

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