Skip to content

Commit

Permalink
Add content post-process callback and remove computeNormals, shaderCa…
Browse files Browse the repository at this point in the history
…llback, receiveShadow (#150)
  • Loading branch information
Avnerus committed Mar 22, 2024
1 parent b29e368 commit 97ed1c6
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 53 deletions.
13 changes: 0 additions & 13 deletions docs/three-loader-3dtiles.loaderoptions.computenormals.md

This file was deleted.

13 changes: 13 additions & 0 deletions docs/three-loader-3dtiles.loaderoptions.contentpostprocess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [three-loader-3dtiles](./three-loader-3dtiles.md) &gt; [LoaderOptions](./three-loader-3dtiles.loaderoptions.md) &gt; [contentPostProcess](./three-loader-3dtiles.loaderoptions.contentpostprocess.md)

## LoaderOptions.contentPostProcess property

A callback for running post-processing on tile content (Mesh or Points) - Default: `undefined`

**Signature:**

```typescript
contentPostProcess?: (content: Mesh | Points) => void;
```
3 changes: 1 addition & 2 deletions docs/three-loader-3dtiles.loaderoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface LoaderOptions
| [basisTranscoderPath?](./three-loader-3dtiles.loaderoptions.basistranscoderpath.md) | | string | _(Optional)_ A path to that contains the basis universal library. e.g: <code>https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/basis</code> - Default: <code>undefined</code> |
| [cesiumIONToken?](./three-loader-3dtiles.loaderoptions.cesiumiontoken.md) | | string | _(Optional)_ A Cesium ION access token when loading tilesets from Cesium ION. |
| [collectAttributions?](./three-loader-3dtiles.loaderoptions.collectattributions.md) | | boolean | _(Optional)_ Collect tile attribution data (copyright) - Default: <code>true</code> if <code>googleApiKey</code> is set, otherwise <code>false</code>. |
| [computeNormals?](./three-loader-3dtiles.loaderoptions.computenormals.md) | | boolean | _(Optional)_ When viewing b3dm (mesh) tiles, compute the vertex normals - Default: <code>false</code>. |
| [contentPostProcess?](./three-loader-3dtiles.loaderoptions.contentpostprocess.md) | | (content: Mesh \| Points) =&gt; void | _(Optional)_ A callback for running post-processing on tile content (Mesh or Points) - Default: <code>undefined</code> |
| [debug?](./three-loader-3dtiles.loaderoptions.debug.md) | | boolean | _(Optional)_ Debug mode: Show tile bounding boxes. Make sure to add the boxes to the scene from [Runtime.getTileBoxes()](./three-loader-3dtiles.runtime.gettileboxes.md) - Default: <code>false</code> |
| [dracoDecoderPath?](./three-loader-3dtiles.loaderoptions.dracodecoderpath.md) | | string | _(Optional)_ A path to that contains the draco library. e.g: <code>https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/draco</code> - Default: <code>undefined</code> |
| [gltfLoader?](./three-loader-3dtiles.loaderoptions.gltfloader.md) | | GLTFLoader | _(Optional)_ Provide an existing three js GLTFLoader so that KTX2 and DRACO workers are reused across the application |
Expand All @@ -35,7 +35,6 @@ interface LoaderOptions
| [pointSize?](./three-loader-3dtiles.loaderoptions.pointsize.md) | | number | _(Optional)_ Point size for Point Cloud tiles - Default: <code>1.0</code> |
| [preloadTilesCount?](./three-loader-3dtiles.loaderoptions.preloadtilescount.md) | | number | _(Optional)_ When using a three.js loading manager, do not call <code>onLoad</code> until this number of tiles were loaded - Default: <code>undefined</code> |
| [resetTransform?](./three-loader-3dtiles.loaderoptions.resettransform.md) | | boolean | _(Optional)_ Whether to reset the tileset to the origin (0, 0, 0) - Default: <code>false</code>. |
| [shaderCallback?](./three-loader-3dtiles.loaderoptions.shadercallback.md) | | (renderer: WebGLRenderer, material: Material) =&gt; void | _(Optional)_ When viewing b3dm (mesh) tiles, a callback to update shader uniforms - Default: <code>undefined</code> |
| [shading?](./three-loader-3dtiles.loaderoptions.shading.md) | | [Shading](./three-loader-3dtiles.shading.md) | _(Optional)_ When viewing b3dm (mesh) tiles, which type of [Shading](./three-loader-3dtiles.shading.md) is used - Default: <code>Shading.FlatTexture</code> |
| [skipLevelOfDetail?](./three-loader-3dtiles.loaderoptions.skiplevelofdetail.md) | | boolean | _(Optional)_ \_EXPERIMENTAL\_: Skip traversal mechanism, not yet supported. Default: <code>false</code> |
| [throttleRequests?](./three-loader-3dtiles.loaderoptions.throttlerequests.md) | | boolean | _(Optional)_ Whether to throttle network requests so that tiles got out of the frame before the request launched, would not be requested - Default: <code>true</code> |
Expand Down
13 changes: 0 additions & 13 deletions docs/three-loader-3dtiles.loaderoptions.shadercallback.md

This file was deleted.

5 changes: 3 additions & 2 deletions etc/three-loader-3dtiles.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { Camera } from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { LoadingManager } from 'three';
import { Material } from 'three';
import { Mesh } from 'three';
import { Object3D } from 'three';
import { Points } from 'three';
import { Stats as Stats_2 } from '@probe.gl/stats';
import { Tileset3D } from '@loaders.gl/tiles';
import { Vector3 } from 'three';
Expand Down Expand Up @@ -37,7 +39,7 @@ export interface LoaderOptions {
basisTranscoderPath?: string;
cesiumIONToken?: string;
collectAttributions?: boolean;
computeNormals?: boolean;
contentPostProcess?: (content: Mesh | Points) => void;
debug?: boolean;
dracoDecoderPath?: string;
gltfLoader?: GLTFLoader;
Expand All @@ -53,7 +55,6 @@ export interface LoaderOptions {
pointSize?: number;
preloadTilesCount?: number;
resetTransform?: boolean;
shaderCallback?: (renderer: WebGLRenderer, material: Material) => void;
shading?: Shading;
skipLevelOfDetail?: boolean;
throttleRequests?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion examples/demos/google-3dtiles/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
dracoDecoderPath: 'https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/draco',
basisTranscoderPath: 'https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/basis',
pointCloudColoring: PointCloudColoring.RGB,
maximumScreenSpaceError: queryParams.get('sse') ?? 16
maximumScreenSpaceError: queryParams.get('sse') ?? 24
}
}
);
Expand Down
30 changes: 13 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ const defaultOptions: LoaderOptions = {
basisTranscoderPath: null,
dracoDecoderPath: null,
material: null,
computeNormals: false,
shaderCallback: null,
contentPostProcess: undefined,
preloadTilesCount: null,
collectAttributions: false
};
Expand Down Expand Up @@ -671,10 +670,10 @@ async function createGLTFNodes(gltfLoader, tile, unlitMaterial, options, rootTra

const tileContent = gltf.scenes[0] as Group;
tileContent.applyMatrix4(contentTransform);

// Memory usage
tile.content.texturesByteLength = 0;
tile.content.geometriesByteLength = 0;
// Memory usage
tile.content.texturesByteLength = 0;
tile.content.geometriesByteLength = 0;

tileContent.traverse((object) => {
if (object.type == "Mesh") {
Expand All @@ -693,7 +692,7 @@ async function createGLTFNodes(gltfLoader, tile, unlitMaterial, options, rootTra
if (options.material) {
mesh.material = options.material.clone();
originalMaterial.dispose();
} else if (options.shading == Shading.FlatTexture) {
} else if (options.shading == Shading.FlatTexture && (mesh.material as Material).type !== "MeshBasicMaterial") {
mesh.material = unlitMaterial.clone();
originalMaterial.dispose();
}
Expand All @@ -711,19 +710,11 @@ async function createGLTFNodes(gltfLoader, tile, unlitMaterial, options, rootTra
(mesh.material as MeshStandardMaterial).map = null;
}

if (options.shaderCallback) {
mesh.onBeforeRender = (renderer, scene, camera, geometry, material, group) => {
options.shaderCallback(renderer,material);
}
}
(mesh.material as MeshStandardMaterial | MeshBasicMaterial).wireframe = options.wireframe;

if (options.computeNormals) {
mesh.geometry.computeVertexNormals();
if (options.contentPostProcess) {
options.contentPostProcess(mesh);
}

mesh.receiveShadow = options.receiveShadow;

}
});
tile.content.gpuMemoryUsageInBytes = tile.content.texturesByteLength + tile.content.geometriesByteLength;
Expand Down Expand Up @@ -783,6 +774,11 @@ function createPointNodes(tile, pointcloudMaterial, options, rootTransformInvers
contentTransform.multiply(new Matrix4().makeTranslation(c[0], c[1], c[2]));
}
tileContent.applyMatrix4(contentTransform);

if (options.contentPostProcess) {
options.contentPostProcess(tileContent);
}

return tileContent;
}

Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
Material,
Camera,
WebGLRenderer,
LoadingManager
LoadingManager,
Mesh,
Points
} from 'three';

import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
Expand Down Expand Up @@ -83,12 +85,10 @@ interface LoaderOptions {
transparent?: boolean;
/** Apply a custom material, supports both b3dm (mesh) tiles and Point Cloud tiles - Default: `undefined` **/
material?: Material;
/** When viewing b3dm (mesh) tiles, a callback to update shader uniforms - Default: `undefined` */
shaderCallback?: (renderer: WebGLRenderer, material: Material) => void;
/** A callback for running post-processing on tile content (Mesh or Points) - Default: `undefined` */
contentPostProcess?: (content: Mesh | Points) => void;
/** When viewing b3dm (mesh) tiles, show meshes as wireframe - Default: `false`. */
wireframe?: boolean;
/** When viewing b3dm (mesh) tiles, compute the vertex normals - Default: `false`. */
computeNormals?: boolean;
/** When viewing Point Cloud tiles, how should the points be colored ({@link PointCloudColoring}) - Default: `PointCloudColoring.White` */
pointCloudColoring?: PointCloudColoring;
/** Point size for Point Cloud tiles - Default: `1.0` */
Expand Down

0 comments on commit 97ed1c6

Please sign in to comment.