Comparing version 0.0.101 to 0.0.102
{ | ||
"name": "ogl", | ||
"version": "0.0.101", | ||
"version": "0.0.102", | ||
"description": "WebGL Library", | ||
@@ -5,0 +5,0 @@ "exports": "./src/index.mjs", |
import { Transform } from '../core/Transform.js'; | ||
import { Mesh } from '../core/Mesh.js'; | ||
import { Vec4 } from '../math/Vec4.js'; | ||
@@ -15,2 +16,3 @@ export class InstancedMesh extends Mesh { | ||
this.instanceTransforms = null; | ||
this.instanceLightmapScaleOffset = null; | ||
this.totalInstanceCount = 0; | ||
@@ -27,4 +29,5 @@ this.frustumCullFunction = null; | ||
this.instanceTransforms = []; | ||
for (let i = 0; i < matrixData.length; i += 16) { | ||
for (let i = 0, j = 0; i < matrixData.length; i += 16, j++) { | ||
const transform = new Transform(); | ||
transform.index = j; | ||
transform.matrix.fromArray(matrixData, i); | ||
@@ -38,2 +41,10 @@ transform.decompose(); | ||
// Check for lightmap attributes - attach to transform | ||
if (!!this.geometry.attributes.lightmapScaleOffset) { | ||
const lightmapData = this.geometry.attributes.lightmapScaleOffset.data; | ||
for (let i = 0, j = 0; i < lightmapData.length; i += 4, j++) { | ||
this.instanceTransforms[j].lightmapData = new Vec4().fromArray(lightmapData, i); | ||
} | ||
} | ||
this.frustumCullFunction = ({ camera }) => { | ||
@@ -50,2 +61,8 @@ // frustum cull transforms each frame - pass world matrix | ||
transform.matrix.toArray(this.geometry.attributes.instanceMatrix.data, i * 16); | ||
// Update lightmap attr | ||
if (transform.lightmapData) { | ||
transform.lightmapData.toArray(this.geometry.attributes.lightmapScaleOffset.data, i * 4); | ||
this.geometry.attributes.lightmapScaleOffset.needsUpdate = true; | ||
} | ||
}); | ||
@@ -64,2 +81,8 @@ this.geometry.instancedCount = this.instanceRenderList.length; | ||
transform.matrix.toArray(this.geometry.attributes.instanceMatrix.data, i * 16); | ||
// Update lightmap attr | ||
if (transform.lightmapData) { | ||
transform.lightmapData.toArray(this.geometry.attributes.lightmapScaleOffset.data, i * 4); | ||
this.geometry.attributes.lightmapScaleOffset.needsUpdate = true; | ||
} | ||
}); | ||
@@ -66,0 +89,0 @@ this.geometry.attributes.instanceMatrix.needsUpdate = true; |
329050
9048