Skip to content

Add Options Object Support to StandardMaterial#constructor #7820

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kungfooman
Copy link
Collaborator

@kungfooman kungfooman commented Jul 4, 2025

This PR aligns StandardMaterial#constructor with other classes like Texture#constructor to accept an optional options object, allowing properties (e.g., diffuse, depthTest) to be set during instantiation without being forced to call additional methods like Material#update - reducing boilerplate code.

Example:

const entity = new pc.Entity("test");
entity.addComponent("render", {
    type: "box",
    material: new pc.StandardMaterial({diffuse: pc.Color.RED})
});

Basically, the aim is to keep the code short and readable and to reduce manual bookkeeping.

@mvaligursky I'm not entirely sure about the requirement for this.update() or if these property assignments should happen before e.g. this.reset()?

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

@mvaligursky
Copy link
Contributor

Thanks, I'll check into this, not sure about .reset(), not familiar with it.
calling update should not be needed, no problem there, it's only needed after material has been used to render, not when constructing I believe. Again - I'll double check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants