Skip to content

Commit ea86f96

Browse files
committed
Added SceneModel.createDTXLayer #1213
1 parent ea4272a commit ea86f96

File tree

1 file changed

+79
-18
lines changed

1 file changed

+79
-18
lines changed

src/viewer/scene/model/SceneModel.js

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ export class SceneModel extends Component {
11411141
this._vboInstancingLayers = {};
11421142
this._vboBatchingLayers = {};
11431143
this._dtxLayers = {};
1144+
this._dtxPrebuiltLayers = {}; // Created with #createdtxLayer
11441145

11451146
this._meshList = [];
11461147

@@ -2210,6 +2211,41 @@ export class SceneModel extends Component {
22102211
}
22112212
}
22122213

2214+
/**
2215+
* Creates a data layer within this SceneModel.
2216+
*
2217+
* @param {Object} cfg Data layer configuration.
2218+
* @param {String} cfg.id
2219+
* @param {String} cfg.primitive
2220+
* @param {Uint16Array} cfg.positionsCompressed
2221+
* @param cfg.metallicRoughness: Uint8Array;
2222+
* @param cfg.indices8Bits: Uint8Array;
2223+
* @param cfg.indices16Bits: Uint16Array;
2224+
* @param cfg.indices32Bits: Uint32Array;
2225+
* @param cfg.edgeIndices8Bits: Uint8Array;
2226+
* @param cfg.edgeIndices16Bits: Uint16Array;
2227+
* @param cfg.edgeIndices32Bits: Uint32Array;
2228+
* @param cfg.perObjectColors: Uint8Array;
2229+
* @param cfg.perObjectPickColors: Uint8Array;
2230+
* @param cfg.perObjectSolid: Uint8Array;
2231+
* @param cfg.perObjectOffsets: Uint32Array;
2232+
* @param cfg.perObjectPositionsDecodeMatrices: Uint32Array;
2233+
* @param cfg.perObjectInstancePositioningMatrices: Uint32Array;
2234+
* @param cfg.perObjectVertexBases: Uint32Array;
2235+
* @param cfg.perObjectIndexBaseOffsets: Uint32Array;
2236+
* @param cfg.perObjectEdgeIndexBaseOffsets: Uint32Array;
2237+
* @param cfg.perTriangleNumberPortionId8Bits: Uint32Array;
2238+
* @param {Uint32Array} cfg.perTriangleNumberPortionId16Bits
2239+
* @param {Uint32Array} cfg.perTriangleNumberPortionId32Bits
2240+
* @param {Uint8Array} cfg.perEdgeNumberPortionId8Bits
2241+
* @param {Uint16Array} cfg.perEdgeNumberPortionId16Bits
2242+
* @param {Uint32Array} cfg.perEdgeNumberPortionId32Bits
2243+
*/
2244+
createDTXLayer(cfg) {
2245+
2246+
// this._dtxPrebuiltLayers[cfg.id] = new TrianglesDataTextureLayer(...);
2247+
}
2248+
22132249
/**
22142250
* Creates a reusable geometry within this SceneModel.
22152251
*
@@ -2564,9 +2600,11 @@ export class SceneModel extends Component {
25642600
*
25652601
* @param {object} cfg Object properties.
25662602
* @param {String} cfg.id Mandatory ID for the new mesh. Must not clash with any existing components within the {@link Scene}.
2603+
* @param {String} [cfg.dtxLayerId] Optional ID of a data later previously created with {@link SceneModel#createDTXLayer"}. The data layer will override all other geometry and material parameters given to this method.
2604+
* @param {Number} [cfg.dtxLayerPortionId] Index of a portion within the data layer if given. Mandatory with `dtxLayerId`.
25672605
* @param {String|Number} [cfg.textureSetId] ID of a texture set previously created with {@link SceneModel#createTextureSet"}.
25682606
* @param {String|Number} [cfg.geometryId] ID of a geometry to instance, previously created with {@link SceneModel#createGeometry"}. Overrides all other geometry parameters given to this method.
2569-
* @param {String} cfg.primitive The primitive type. Accepted values are 'points', 'lines', 'triangles', 'solid' and 'surface'.
2607+
* @param {String} [cfg.primitive] The primitive type. Accepted values are 'points', 'lines', 'triangles', 'solid' and 'surface'.
25702608
* @param {Number[]} [cfg.positions] Flat array of uncompressed 3D vertex positions positions. Required for all primitive types. Overridden by ````positionsCompressed````.
25712609
* @param {Number[]} [cfg.positionsCompressed] Flat array of quantized 3D vertex positions. Overrides ````positions````, and must be accompanied by ````positionsDecodeMatrix````.
25722610
* @param {Number[]} [cfg.positionsDecodeMatrix] A 4x4 matrix for decompressing ````positionsCompressed````. Must be accompanied by ````positionsCompressed````.
@@ -2601,10 +2639,26 @@ export class SceneModel extends Component {
26012639
return;
26022640
}
26032641

2642+
const dtxLayer = (cfg.dtxLayerId !== undefined);
26042643
const instancing = (cfg.geometryId !== undefined);
26052644
const batching = !instancing;
26062645

2607-
if (batching) {
2646+
if (dtxLayer) {
2647+
2648+
// Data layer
2649+
2650+
if (cfg.dtxLayerPortionId === null || cfg.dtxLayerPortionId === undefined) {
2651+
this.error(`Param expected: 'dtxLayerPortionId' (required with 'dtxLayerId')`);
2652+
return null;
2653+
}
2654+
2655+
cfg.dtxLayer = this._dtxPrebuiltLayers[cfg.dtxLayerId];
2656+
if (!cfg.dtxLayer) {
2657+
this.error(`Data layer not found: '${cfg.dtxLayerId}')`);
2658+
return null;
2659+
}
2660+
2661+
} else if (batching) {
26082662

26092663
// Batched geometry
26102664

@@ -2856,22 +2910,29 @@ export class SceneModel extends Component {
28562910
cfg.worldAABB = math.collapseAABB3();
28572911
cfg.aabb = cfg.worldAABB; /// Hack for VBOInstancing layer
28582912
cfg.solid = (cfg.primitive === "solid");
2859-
mesh.origin = math.vec3(cfg.origin);
2860-
switch (cfg.type) {
2861-
case DTX:
2862-
mesh.layer = this._getDTXLayer(cfg);
2863-
break;
2864-
case VBO_BATCHED:
2865-
mesh.layer = this._getVBOBatchingLayer(cfg);
2866-
break;
2867-
case VBO_INSTANCED:
2868-
mesh.layer = this._getVBOInstancingLayer(cfg);
2869-
break;
2870-
}
2871-
mesh.portionId = mesh.layer.createPortion(cfg);
2872-
mesh.aabb = cfg.worldAABB;
2873-
mesh.numPrimitives = cfg.numPrimitives;
2874-
math.expandAABB3(this._aabb, mesh.aabb);
2913+
2914+
if (cfg.dtxLayer) {
2915+
mesh.layer = cfg.dtxLayer;
2916+
mesh.portionId = cfg.dtxLayerPortionId;
2917+
2918+
} else {
2919+
mesh.origin = math.vec3(cfg.origin);
2920+
switch (cfg.type) {
2921+
case DTX:
2922+
mesh.layer = this._getDTXLayer(cfg);
2923+
break;
2924+
case VBO_BATCHED:
2925+
mesh.layer = this._getVBOBatchingLayer(cfg);
2926+
break;
2927+
case VBO_INSTANCED:
2928+
mesh.layer = this._getVBOInstancingLayer(cfg);
2929+
break;
2930+
}
2931+
mesh.portionId = mesh.layer.createPortion(cfg);
2932+
mesh.aabb = cfg.worldAABB;
2933+
mesh.numPrimitives = cfg.numPrimitives;
2934+
math.expandAABB3(this._aabb, mesh.aabb);
2935+
}
28752936
this._meshes[cfg.id] = mesh;
28762937
this._meshList.push(mesh);
28772938
}

0 commit comments

Comments
 (0)