diff --git a/examples/src/examples/physics/compound-collision.example.mjs b/examples/src/examples/physics/compound-collision.example.mjs index 96abdfc4f42..65c1124b1fb 100644 --- a/examples/src/examples/physics/compound-collision.example.mjs +++ b/examples/src/examples/physics/compound-collision.example.mjs @@ -60,20 +60,10 @@ app.on('destroy', () => { }); app.scene.ambientLight = new pc.Color(0.2, 0.2, 0.2); -/** - * @param {pc.Color} color - The diffuse color. - * @returns {pc.StandardMaterial} The standard material. - */ -function createMaterial(color) { - const material = new pc.StandardMaterial(); - material.diffuse = color; - material.update(); - return material; -} // Create a couple of materials for our objects -const red = createMaterial(new pc.Color(0.7, 0.3, 0.3)); -const gray = createMaterial(new pc.Color(0.7, 0.7, 0.7)); +const red = new pc.StandardMaterial({ diffuse: new pc.Color(0.7, 0.3, 0.3) }); +const gray = new pc.StandardMaterial({ diffuse: new pc.Color(0.7, 0.7, 0.7) }); // Define a scene hierarchy in JSON format. This is loaded/parsed in // the parseScene function below diff --git a/examples/src/examples/physics/falling-shapes.example.mjs b/examples/src/examples/physics/falling-shapes.example.mjs index d59b941efb3..b5dd5824d4a 100644 --- a/examples/src/examples/physics/falling-shapes.example.mjs +++ b/examples/src/examples/physics/falling-shapes.example.mjs @@ -69,21 +69,10 @@ assetListLoader.load(() => { // Set the gravity for our rigid bodies app.systems.rigidbody.gravity.set(0, -9.81, 0); - /** - * @param {pc.Color} color - The color of the material. - * @returns {pc.StandardMaterial} The new material. - */ - function createMaterial(color) { - const material = new pc.StandardMaterial(); - material.diffuse = color; - // we need to call material.update when we change its properties - material.update(); - return material; - } // create a few materials for our objects - const red = createMaterial(new pc.Color(1, 0.3, 0.3)); - const gray = createMaterial(new pc.Color(0.7, 0.7, 0.7)); + const red = new pc.StandardMaterial({ diffuse: new pc.Color(1, 0.3, 0.3) }); + const gray = new pc.StandardMaterial({ diffuse: new pc.Color(0.7, 0.7, 0.7) }); // *********** Create our floor ******************* diff --git a/examples/src/examples/physics/offset-collision.example.mjs b/examples/src/examples/physics/offset-collision.example.mjs index 58ac3385712..1a6b80669ff 100644 --- a/examples/src/examples/physics/offset-collision.example.mjs +++ b/examples/src/examples/physics/offset-collision.example.mjs @@ -94,21 +94,9 @@ assetListLoader.load(() => { // Set the gravity for our rigid bodies app.systems.rigidbody.gravity.set(0, -9.81, 0); - /** - * @param {pc.Color} color - The color. - * @returns {pc.StandardMaterial} The material. - */ - function createMaterial(color) { - const material = new pc.StandardMaterial(); - material.diffuse = color; - // we need to call material.update when we change its properties - material.update(); - return material; - } - // create a few materials for our objects - const red = createMaterial(new pc.Color(1, 0.3, 0.3)); - const gray = createMaterial(new pc.Color(0.7, 0.7, 0.7)); + const red = new pc.StandardMaterial({ diffuse: new pc.Color(1, 0.3, 0.3) }); + const gray = new pc.StandardMaterial({ diffuse: new pc.Color(0.7, 0.7, 0.7) }); const floor = new pc.Entity(); floor.addComponent('render', { diff --git a/examples/src/examples/physics/raycast.example.mjs b/examples/src/examples/physics/raycast.example.mjs index f5b275676f0..ebde4e19809 100644 --- a/examples/src/examples/physics/raycast.example.mjs +++ b/examples/src/examples/physics/raycast.example.mjs @@ -67,20 +67,9 @@ assetListLoader.load(() => { app.scene.ambientLight = new pc.Color(0.2, 0.2, 0.2); - /** - * @param {pc.Color} color - The color. - * @returns {pc.StandardMaterial} - The material. - */ - function createMaterial(color) { - const material = new pc.StandardMaterial(); - material.diffuse = color; - material.update(); - return material; - } - // Create a couple of materials - const red = createMaterial(new pc.Color(1, 0, 0)); - const green = createMaterial(new pc.Color(0, 1, 0)); + const red = new pc.StandardMaterial({ diffuse: pc.Color.RED }); + const green = new pc.StandardMaterial({ diffuse: pc.Color.GREEN }); // Create light const light = new pc.Entity(); diff --git a/src/scene/materials/standard-material.js b/src/scene/materials/standard-material.js index d563a3415d9..364986ddce7 100644 --- a/src/scene/materials/standard-material.js +++ b/src/scene/materials/standard-material.js @@ -575,8 +575,9 @@ class StandardMaterial extends Material { * * // Notify the material that it has been modified * material.update(); + * @param {Partial} [options] - Options for the material. */ - constructor() { + constructor(options) { super(); // storage for texture and cubemap asset references @@ -588,6 +589,10 @@ class StandardMaterial extends Material { this.shaderOptBuilder = new StandardMaterialOptionsBuilder(); this.reset(); + if (options) { + Object.assign(this, options); + this.update(); + } } reset() {