Skip to content

Commit

Permalink
Streaming support, tidy ups
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Apr 2, 2024
1 parent bbcda94 commit e0bab71
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 115 deletions.
8 changes: 8 additions & 0 deletions packages/scene/src/SceneMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export class SceneMesh {
*/
object: SceneObject | null;

/**
* TODO
*/
streamLayerIndex: number;

#color: FloatArrayParam;
#matrix: FloatArrayParam;
#metallic: number;
Expand All @@ -70,6 +75,7 @@ export class SceneMesh {
roughness?: number;
metallic?: number;
origin?: FloatArrayParam;
streamLayerIndex?: number;
}) {
this.id = meshParams.id;
this.#matrix = meshParams.matrix ? createMat4(meshParams.matrix) : identityMat4();
Expand All @@ -81,6 +87,7 @@ export class SceneMesh {
this.roughness = (meshParams.roughness !== null && meshParams.roughness !== undefined) ? meshParams.roughness : 1;
this.opacity = (meshParams.opacity !== undefined && meshParams.opacity !== null) ? meshParams.opacity : 1.0;
this.origin = new Float32Array(meshParams.origin !== undefined ? meshParams.origin : [0, 0, 0]);
this.streamLayerIndex = meshParams.streamLayerIndex !== undefined ? meshParams.streamLayerIndex : 0;
}

/**
Expand Down Expand Up @@ -242,6 +249,7 @@ export class SceneMesh {
*/
getJSON(): SceneMeshParams {
const meshParams = <SceneMeshParams>{
streamLayerIndex: this.streamLayerIndex || 0,
id: this.id,
geometryId: this.geometry.id,
color: Array.from(this.#color),
Expand Down
9 changes: 7 additions & 2 deletions packages/scene/src/SceneMeshParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import type {FloatArrayParam} from "@xeokit/math";
*/
export interface SceneMeshParams {

/**
* TODO
*/
streamLayerIndex?: number;

/**
* ID for the new {@link @xeokit/scene!SceneMesh}, unique within the {@link @xeokit/scene!SceneModel}.
*/
Expand All @@ -21,7 +26,7 @@ export interface SceneMeshParams {
geometryId: string;

/**
* Optional ID of a {@link Transform} previously created with {@link @xeokit/scene!SceneModel.createTransform | SceneModel.createTransform}.
* Optional ID of a {@link SceneTransform} previously created with {@link @xeokit/scene!SceneModel.createTransform | SceneModel.createTransform}.
*/
transformId?: string;

Expand Down Expand Up @@ -97,4 +102,4 @@ export interface SceneMeshParams {
* Optional RTC coordinate origin for the new {@link @xeokit/scene!SceneMesh}.
*/
origin?:FloatArrayParam;
}
}
14 changes: 13 additions & 1 deletion packages/scene/src/SceneModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {SceneModelParams} from "./SceneModelParams";
import type {Scene} from "./Scene";
import type {SceneModelStats} from "./SceneModelStats";
import {composeMat4, eulerToQuat, identityMat4, identityQuat} from "@xeokit/matrix";
import {SceneModelStreamParams} from "./SceneModelStreamParams";

// DTX texture types

Expand Down Expand Up @@ -88,6 +89,14 @@ TEXTURE_ENCODING_OPTIONS[OCCLUSION_TEXTURE] = {
*/
export class SceneModel extends Component {

/**
* Indicates what renderer resources will need to be allocated in a {@link @xeokit/viewer!Viewer | Viewer's}
* {@link @xeokit/viewer!Renderer | Renderer} to support progressive loading for the {@link @xeokit/scene!SceneModel | SceneModel}.
*
* See {@link "@xeokit/scene" | @xeokit/scene} for usage.
*/
public streamParams?: SceneModelStreamParams;

/**
* The {@link @xeokit/scene!Scene} that contains this SceneModel.
*/
Expand Down Expand Up @@ -222,6 +231,7 @@ export class SceneModel extends Component {
this.#numObjects = 0;
this.#meshUsedByObject = {};

this.streamParams = sceneModelParams.streamParams;
this.id = sceneModelParams.id || "default";
this.layerId = sceneModelParams.layerId;
this.edgeThreshold = 10;
Expand Down Expand Up @@ -952,7 +962,9 @@ export class SceneModel extends Component {
meshes: [],
objects: []
};

if (this.streamParams) {
sceneModelParams.streamParams = this.streamParams;
}
Object.entries(this.geometries).forEach(([key, value]) => {
sceneModelParams.geometriesCompressed.push((<SceneGeometry>value).getJSON());
});
Expand Down
10 changes: 9 additions & 1 deletion packages/scene/src/SceneModelParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import type {FloatArrayParam} from "@xeokit/math";
import type {SceneGeometryCompressedParams} from "./SceneGeometryCompressedParams";
import type {SceneTextureParams} from "./SceneTextureParams";
import type {SceneTextureSetParams} from "./SceneTextureSetParams";
import type {SceneObject} from "./SceneObject";

import type {SceneMeshParams} from "./SceneMeshParams";
import type {SceneGeometryParams} from "./SceneGeometryParams";
import type {SceneObjectParams} from "./SceneObjectParams";
import {SceneModelStreamParams} from "./SceneModelStreamParams";


/**
Expand All @@ -16,6 +17,13 @@ import type {SceneObjectParams} from "./SceneObjectParams";
*/
export interface SceneModelParams {


/**
* Indicates what renderer resources will need to be allocated in a {@link @xeokit/viewer!Viewer | Viewer's}
* {@link @xeokit/viewer!Renderer | Renderer} to support progressive loading for a {@link @xeokit/scene!SceneModel | SceneModel}.
*/
streamParams?: SceneModelStreamParams;

/**
* Unique ID for the SceneModel.
*
Expand Down
33 changes: 33 additions & 0 deletions packages/scene/src/SceneModelStreamLayerParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

/**
* Indicates storage to allocate in a renderer layer.
*
* Stored in {@link @scene/SceneModelStreamParams.layers | SceneModelStreamParams.layers}.
*/
export interface SceneModelStreamLayerParams {

/**
* Number of 32-bit geometry indices to allocate in the renderer layer.
*/
numIndices32Bits: number;

/**
* Number of 16-bit geometry indices to allocate in the renderer layer.
*/
numIndices16Bits: number;

/**
* Number of 8-bit geometry indices to allocate in the renderer layer.
*/
numIndices8Bits: number;

/**
* Number of geometry vertices to allocate in the renderer layer.
*/
numVertices: number;

/**
* Number of submeshes to allocate in the renderer layer.
*/
numSubMeshes: number;
}
17 changes: 17 additions & 0 deletions packages/scene/src/SceneModelStreamParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {SceneModelStreamLayerParams} from "./SceneModelStreamLayerParams";

/**
* Indicates what renderer resources will need to be allocated in a {@link @xeokit/viewer!Viewer | Viewer's}
* {@link @xeokit/viewer!Renderer | Renderer} to support progressive loading for a {@link @xeokit/scene!SceneModel | SceneModel}.
*
* See {@link "@xeokit/scene" | @xeokit/scene} for usage.
*/
export interface SceneModelStreamParams {

/**
* Indicates what renderer layers will need to be allocated.
*/
streamLayers: SceneModelStreamLayerParams[];
}


9 changes: 8 additions & 1 deletion packages/scene/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@
* const buffers = thetexture.buffers; // ArrayBuffer[]
* ````
*
* ### Preparing a SceneModel for Progressive Loading
*
* TODO: Create in separate tutorial - too complex for here
*
* @module @xeokit/scene
*/

Expand Down Expand Up @@ -410,4 +414,7 @@ export * from "./SceneGeometryParams";
export * from "./SceneModelParams";
export * from "./compressGeometryParams";

export * from "./getSceneObjectGeometry";
export * from "./getSceneObjectGeometry";

export * from "./SceneModelStreamParams";
export * from "./SceneModelStreamLayerParams";
Loading

0 comments on commit e0bab71

Please sign in to comment.