This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
-
Is there a way to set the scale and color of each instanced mesh? Can you provide a small code example of how to do it? Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
IRobot1
Apr 14, 2022
Replies: 1 comment
-
The following example shows how to set color and scale using instaned mesh <ngt-instanced-mesh #inst="ngtInstancedMesh" [args]="[data.length]" (ready)="ready(inst.mesh)">
<ngt-box-geometry></ngt-box-geometry>
<ngt-mesh-standard-material></ngt-mesh-standard-material>
</ngt-instanced-mesh> gap = 1.05
data = new Array(1000).fill(0).map((d, index) => ({
position: new Vector3(0, Math.floor(index / 30) * this.gap, (index % 30) * this.gap - 15),
scale: new Vector3(Math.random(), Math.random(), Math.random()),
color: new Color().setHex(Math.random() * 0xffffff) //.setColorName('white')
}));
ready(inst: InstancedMesh) {
this.data.forEach((item, index) => {
const matrix = new Matrix4();
matrix.setPosition(item.position);
matrix.scale(item.scale);
inst.setMatrixAt(index, matrix);
inst.setColorAt(index, item.color);
})
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
IRobot1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following example shows how to set color and scale using instaned mesh