Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinyork committed Mar 23, 2024
2 parents 6d7bf7c + ec5778c commit d3c0b5b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions libs/scene/src/material/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ export class Material {
isBatchable(): boolean {
return false;
}
/** @internal */
get coreMaterial(): this {
return this;
}
/**
* Draws a primitive using this material
*
Expand Down
7 changes: 5 additions & 2 deletions libs/scene/src/material/meshmaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ export class MeshMaterial extends Material {
const instanceUniforms = (this.constructor as typeof MeshMaterial).INSTANCE_UNIFORMS;
const uniformsHolder = instanceUniforms.length > 0 ? new Float32Array(4 * instanceUniforms.length) : null;
const batchable = Application.instance.device.type !== 'webgl';
const coreMaterial = this.coreMaterial;
// Copy original uniform values
for (let i = 0; i < instanceUniforms.length; i++) {
const [prop, type] = instanceUniforms[i];
const value = this[prop];
const value = coreMaterial[prop];
switch (type) {
case 'float': {
uniformsHolder[i * 4] = Number(value);
Expand Down Expand Up @@ -223,6 +224,8 @@ export class MeshMaterial extends Material {
}
}
}
} else if (prop === 'coreMaterial') {
return target;
} else if (typeof prop === 'string') {
const index = instanceUniforms.findIndex((val) => val[0] === prop);
if (index >= 0) {
Expand Down Expand Up @@ -263,7 +266,7 @@ export class MeshMaterial extends Material {
}
}
};
return new Proxy(this, handler);
return new Proxy(coreMaterial, handler);
}
/** Draw context for shader creation */
get drawContext(): DrawContext {
Expand Down
4 changes: 2 additions & 2 deletions site/src/demo-5/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ instancingApp.ready().then(async () => {
const assetManager = new AssetManager();
(async function(){
for (let i = 0; i < 2000; i++) {
const stone1 = await assetManager.fetchModel(scene, 'assets/models/stone1.glb', { disableInstancing: false });
const stone1 = await assetManager.fetchModel(scene, 'assets/models/stone1.glb', { enableInstancing: true });
stone1.group.parent = batchGroup;
stone1.group.position.setXYZ(Math.random() * 100 - 50, Math.random() * 100 - 50, Math.random() * 100 - 50);
stone1.group.iterate(node => {
Expand All @@ -74,7 +74,7 @@ instancingApp.ready().then(async () => {
}
});
instanceCount++;
const stone2 = await assetManager.fetchModel(scene, 'assets/models/stone2.glb', { disableInstancing: false });
const stone2 = await assetManager.fetchModel(scene, 'assets/models/stone2.glb', { enableInstancing: true });
stone2.group.parent = batchGroup;
stone2.group.position.setXYZ(Math.random() * 100 - 50, Math.random() * 100 - 50, Math.random() * 100 - 50);
stone2.group.iterate(node => {
Expand Down
4 changes: 2 additions & 2 deletions test/src/instancing/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ instancingApp.ready().then(async () => {
const batchGroup = new BatchGroup(scene);
const assetManager = new AssetManager();
for (let i = 0; i < 2000; i++) {
assetManager.fetchModel(scene, 'assets/stone1.glb', { disableInstancing: false }).then((info) => {
assetManager.fetchModel(scene, 'assets/stone1.glb', { enableInstancing: true }).then((info) => {
info.group.parent = batchGroup;
info.group.position.setXYZ(
Math.random() * 100 - 50,
Expand All @@ -56,7 +56,7 @@ instancingApp.ready().then(async () => {
}
});
});
assetManager.fetchModel(scene, 'assets/stone2.glb', { disableInstancing: false }).then((info) => {
assetManager.fetchModel(scene, 'assets/stone2.glb', { enableInstancing: true }).then((info) => {
info.group.parent = batchGroup;
info.group.position.setXYZ(
Math.random() * 100 - 50,
Expand Down

0 comments on commit d3c0b5b

Please sign in to comment.