Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 2 additions & 12 deletions examples/src/examples/physics/compound-collision.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions examples/src/examples/physics/falling-shapes.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 *******************

Expand Down
16 changes: 2 additions & 14 deletions examples/src/examples/physics/offset-collision.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
15 changes: 2 additions & 13 deletions examples/src/examples/physics/raycast.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion src/scene/materials/standard-material.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,9 @@ class StandardMaterial extends Material {
*
* // Notify the material that it has been modified
* material.update();
* @param {Partial<StandardMaterial>} [options] - Options for the material.
*/
constructor() {
constructor(options) {
super();

// storage for texture and cubemap asset references
Expand All @@ -588,6 +589,10 @@ class StandardMaterial extends Material {
this.shaderOptBuilder = new StandardMaterialOptionsBuilder();

this.reset();
if (options) {
Object.assign(this, options);
this.update();
}
}

reset() {
Expand Down