Jump to content

New Metadata Cloning Issues


MackeyK24
 Share

Recommended Posts

Yo @Deltakosh ... I know you said you dont wanna add any code to the engine specifically for my toolkit.

But the last changes you made to metadata cloning is KILLING ME BRO... specifically the like in constructor babylon.mesh.ts:

this.metadata = source.metadata;

This is line is really setting a "POINTER" so to speak on the clone to the original metadata instead of making a COPY of the metadata.

I had tons of code for "Prefabs" or mesh cloning where I would do something like this:

mesh.metadata.clone = () => { return BABYLON.SceneManager.CloneMetadata(mesh.metadata); };

But somehow via the cloning framework, if you set: this.metadata = source.metadata ... that screws the whole thing up for me and a (almost) year worth of METADATA code I was using before that lone of code showed up.

Can we at least add some kind of switch so those us who need CUSTOM METADATA CLONING ... not just simply setting a "REFERENCE" to the the original metadata in the clone.

Something like this:

if (!BABYLON.Mesh.CUSTOM_METADATA_CLONING) {
    this.metadata = source.metadata;
}

Then I could set that STATIC switch to true to use custom metadata cloning like this:

// Setup metadata cloning
mesh.metadata.clone = () => { return BABYLON.SceneManager.CloneMetadata(mesh.metadata); };

If not, then I will have to use Custom Builds of babylon.js in the Toolkit... Which not be a bad ideal so I can keep the toolkit working to a Custom Build of the current stable release... What do you think... I just thought I would ask :)

Link to comment
Share on other sites

2 hours ago, Deltakosh said:

I'm against custom builds mostly for an officially hosted toolkit like yours :)

What if I do this:


if (mesh.metadata.clone) {
   this.metadata = mesh.metadata.clone();
} else {
   this.metadata = mesh.metadata;
}

?

 

This should work... trying is now in a custom build: in the babylon.mesh.ts constructor

// Metadata
if (source.metadata.clone) {
   this.metadata = source.metadata.clone();
} else {
   this.metadata = source.metadata;
}        

 

Link to comment
Share on other sites

Yo @Deltakosh ... it turns out we need to EXCLUDE metadata from Tools.DeepCopy if we are going to set this.metadata at all (even without the mod)

so this works perfect:

 

// Deep copy
Tools.DeepCopy(source, this, ["name", "material", "skeleton", "instances", "parent", "uniqueId", "source", "metadata"], ["_poseMatrix", "_source"]);

// Metadata
if (source.metadata.clone) {
    this.metadata = source.metadata.clone();
} else {
    this.metadata = source.metadata;
}             

 

I am going to PR this... Please ACCEPT :)

 

Link to comment
Share on other sites

@Deltakosh I'm getting "TypeError: Cannot read property 'clone' of null".  source.metadata is null.  I'm using CSG toMesh().
Should it not be:

if (source.metadata && source.metadata.clone) {
    this.metadata = source.metadata.clone();
} else {
    this.metadata = source.metadata;
} 

edit: can confirm my game loads with that change.  have done a PR.

Link to comment
Share on other sites

2 hours ago, brianzinn said:

@Deltakosh I'm getting "TypeError: Cannot read property 'clone' of null".  source.metadata is null.  I'm using CSG toMesh().
Should it not be:


if (source.metadata && source.metadata.clone) {
    this.metadata = source.metadata.clone();
} else {
    this.metadata = source.metadata;
} 

edit: can confirm my game loads with that change.  have done a PR.

Good Catch :)

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