Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] When material is cloned, its custom parameters are copied as well #6844

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/scene/materials/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ class Material {
this.stencilBack = source.stencilFront === source.stencilBack ? this.stencilFront : source.stencilBack.clone();
}

// Shader parameters
this.clearParameters();
for (const name in source.parameters) {
if (source.parameters.hasOwnProperty(name)) {
this._setParameterSimple(name, source.parameters[name].data);
}
}

return this;
}

Expand Down Expand Up @@ -558,6 +566,18 @@ class Material {
return this.parameters[name];
}

_setParameterSimple(name, data) {
const param = this.parameters[name];
if (param) {
param.data = data;
} else {
this.parameters[name] = {
scopeId: null,
data: data
};
}
}

/**
* Sets a shader parameter on a material.
*
Expand All @@ -578,15 +598,7 @@ class Material {
data = uniformObject.value;
}

const param = this.parameters[name];
if (param) {
param.data = data;
} else {
this.parameters[name] = {
scopeId: null,
data: data
};
}
this._setParameterSimple(name, data);
}

/**
Expand Down