Jump to content

Check that the merger is possible "isMerged"


Dad72
 Share

Recommended Posts

Is it possible to verify that two objects can be merged before the merged.

for exemple:

if(BABYLON.Mesh.isMerged(myGroupObjets) == true) { // merge possible
    BABYLON.Mesh.MergeMeshes(myGroupObjets); 
}

I can not find isMerged or equivalent function. I think this could be an interesting feature to check that the object can be merged together because we merge objects that share the same textures.

Link to comment
Share on other sites

I have written a heterogeneous merge for Dialog extension.  Was assembling a "string" of Letter mesh clones, then would combine them until the material of the next letter was different.  Start a new merge after that.  If you did not care that they be "sequential" meshes, you could do a first pass to get all the unique materials first.  Then merge.

If someone is loading the same texture over and over in different materials, they need to start with just better organization.  If it helps, I made sure if a name of a material matches one already loaded, the reference to the first material is returned, skipping the 2nd load / material.

This is helpful for cross .babylon sharing of Materials.  For Blender exporter at least, the name of the .babylon file is prefixed, "filename.material", to avoid collision by default.  There is an option to over ride namespace.  If namespace was over ridden to be "shared", material would be "shared.material".

I think the function checking whether a single merge is possible is kind of a crutch.  This kind of thing should be known at the design time, or you should just do them in batches, like I do.

Link to comment
Share on other sites

I made this function. do you think this is enough?

    var isMerged = function(listeMeshes)
	{
		var result = false;
		for(var i = 0; i < listeMeshes.length; i++)
		{
			if(listeMeshes[0].material == listeMeshes.material) {
				result = true;
				continue;
			} else {
				result = false;
				break;
			}
		}
		return result;
	};

 

Link to comment
Share on other sites

Might be the language problem, but I think you mean "isMergeable".  The concept is right, but think there is are bugs in your program.  First, you never reference i.  Your test asks "is the reference of material of mesh 0 the same as the reference to the material of an array of meshes.

I do not write javascript for this reason.  This would never compile in Typescript.  My javascript is not good, but something like this should work:

var isMergeable = function(listMeshes)
	{
		var result = listMeshes.length > 1;
                var mat = listMeshes[0].material;
		for(var i = 1; i < listMeshes.length; i++)
		{
			if(listMeshes.material != mat) {
				result = false;
				break;
			}
		}
		return result;
	};

 

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