Init Main project
This commit is contained in:
commit
9e581ae67f
220 changed files with 253987 additions and 0 deletions
1751
public/vendor/addons/controls/OrbitControls.js
vendored
Normal file
1751
public/vendor/addons/controls/OrbitControls.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
170
public/vendor/addons/environments/RoomEnvironment.js
vendored
Normal file
170
public/vendor/addons/environments/RoomEnvironment.js
vendored
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
import {
|
||||
BackSide,
|
||||
BoxGeometry,
|
||||
InstancedMesh,
|
||||
Mesh,
|
||||
MeshLambertMaterial,
|
||||
MeshStandardMaterial,
|
||||
PointLight,
|
||||
Scene,
|
||||
Object3D,
|
||||
} from "three";
|
||||
|
||||
/**
|
||||
* This class represents a scene with a basic room setup that can be used as
|
||||
* input for {@link PMREMGenerator#fromScene}. The resulting PMREM represents the room's
|
||||
* lighting and can be used for Image Based Lighting by assigning it to {@link Scene#environment}
|
||||
* or directly as an environment map to PBR materials.
|
||||
*
|
||||
* The implementation is based on the [EnvironmentScene](https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/three-components/EnvironmentScene.ts)
|
||||
* component from the `model-viewer` project.
|
||||
*
|
||||
* ```js
|
||||
* const environment = new RoomEnvironment();
|
||||
* const pmremGenerator = new THREE.PMREMGenerator( renderer );
|
||||
*
|
||||
* const envMap = pmremGenerator.fromScene( environment ).texture;
|
||||
* scene.environment = envMap;
|
||||
* ```
|
||||
*
|
||||
* @augments Scene
|
||||
* @three_import import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
|
||||
*/
|
||||
class RoomEnvironment extends Scene {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "RoomEnvironment";
|
||||
this.position.y = -3.5;
|
||||
|
||||
const geometry = new BoxGeometry();
|
||||
geometry.deleteAttribute("uv");
|
||||
|
||||
const roomMaterial = new MeshStandardMaterial({ side: BackSide });
|
||||
const boxMaterial = new MeshStandardMaterial();
|
||||
|
||||
const mainLight = new PointLight(0xffffff, 900, 28, 2);
|
||||
mainLight.position.set(0.418, 16.199, 0.3);
|
||||
this.add(mainLight);
|
||||
|
||||
const room = new Mesh(geometry, roomMaterial);
|
||||
room.position.set(-0.757, 13.219, 0.717);
|
||||
room.scale.set(31.713, 28.305, 28.591);
|
||||
this.add(room);
|
||||
|
||||
const boxes = new InstancedMesh(geometry, boxMaterial, 6);
|
||||
const transform = new Object3D();
|
||||
|
||||
// box1
|
||||
transform.position.set(-10.906, 2.009, 1.846);
|
||||
transform.rotation.set(0, -0.195, 0);
|
||||
transform.scale.set(2.328, 7.905, 4.651);
|
||||
transform.updateMatrix();
|
||||
boxes.setMatrixAt(0, transform.matrix);
|
||||
|
||||
// box2
|
||||
transform.position.set(-5.607, -0.754, -0.758);
|
||||
transform.rotation.set(0, 0.994, 0);
|
||||
transform.scale.set(1.97, 1.534, 3.955);
|
||||
transform.updateMatrix();
|
||||
boxes.setMatrixAt(1, transform.matrix);
|
||||
|
||||
// box3
|
||||
transform.position.set(6.167, 0.857, 7.803);
|
||||
transform.rotation.set(0, 0.561, 0);
|
||||
transform.scale.set(3.927, 6.285, 3.687);
|
||||
transform.updateMatrix();
|
||||
boxes.setMatrixAt(2, transform.matrix);
|
||||
|
||||
// box4
|
||||
transform.position.set(-2.017, 0.018, 6.124);
|
||||
transform.rotation.set(0, 0.333, 0);
|
||||
transform.scale.set(2.002, 4.566, 2.064);
|
||||
transform.updateMatrix();
|
||||
boxes.setMatrixAt(3, transform.matrix);
|
||||
|
||||
// box5
|
||||
transform.position.set(2.291, -0.756, -2.621);
|
||||
transform.rotation.set(0, -0.286, 0);
|
||||
transform.scale.set(1.546, 1.552, 1.496);
|
||||
transform.updateMatrix();
|
||||
boxes.setMatrixAt(4, transform.matrix);
|
||||
|
||||
// box6
|
||||
transform.position.set(-2.193, -0.369, -5.547);
|
||||
transform.rotation.set(0, 0.516, 0);
|
||||
transform.scale.set(3.875, 3.487, 2.986);
|
||||
transform.updateMatrix();
|
||||
boxes.setMatrixAt(5, transform.matrix);
|
||||
|
||||
this.add(boxes);
|
||||
|
||||
// -x right
|
||||
const light1 = new Mesh(geometry, createAreaLightMaterial(50));
|
||||
light1.position.set(-16.116, 14.37, 8.208);
|
||||
light1.scale.set(0.1, 2.428, 2.739);
|
||||
this.add(light1);
|
||||
|
||||
// -x left
|
||||
const light2 = new Mesh(geometry, createAreaLightMaterial(50));
|
||||
light2.position.set(-16.109, 18.021, -8.207);
|
||||
light2.scale.set(0.1, 2.425, 2.751);
|
||||
this.add(light2);
|
||||
|
||||
// +x
|
||||
const light3 = new Mesh(geometry, createAreaLightMaterial(17));
|
||||
light3.position.set(14.904, 12.198, -1.832);
|
||||
light3.scale.set(0.15, 4.265, 6.331);
|
||||
this.add(light3);
|
||||
|
||||
// +z
|
||||
const light4 = new Mesh(geometry, createAreaLightMaterial(43));
|
||||
light4.position.set(-0.462, 8.89, 14.52);
|
||||
light4.scale.set(4.38, 5.441, 0.088);
|
||||
this.add(light4);
|
||||
|
||||
// -z
|
||||
const light5 = new Mesh(geometry, createAreaLightMaterial(20));
|
||||
light5.position.set(3.235, 11.486, -12.541);
|
||||
light5.scale.set(2.5, 2.0, 0.1);
|
||||
this.add(light5);
|
||||
|
||||
// +y
|
||||
const light6 = new Mesh(geometry, createAreaLightMaterial(100));
|
||||
light6.position.set(0.0, 20.0, 0.0);
|
||||
light6.scale.set(1.0, 0.1, 1.0);
|
||||
this.add(light6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees internal resources. This method should be called
|
||||
* when the environment is no longer required.
|
||||
*/
|
||||
dispose() {
|
||||
const resources = new Set();
|
||||
|
||||
this.traverse((object) => {
|
||||
if (object.isMesh) {
|
||||
resources.add(object.geometry);
|
||||
resources.add(object.material);
|
||||
}
|
||||
});
|
||||
|
||||
for (const resource of resources) {
|
||||
resource.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createAreaLightMaterial(intensity) {
|
||||
// create an emissive-only material. see #31348
|
||||
const material = new MeshLambertMaterial({
|
||||
color: 0x000000,
|
||||
emissive: 0xffffff,
|
||||
emissiveIntensity: intensity,
|
||||
});
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
export { RoomEnvironment };
|
||||
31
public/vendor/addons/libs/draco/README.md
vendored
Normal file
31
public/vendor/addons/libs/draco/README.md
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Draco 3D Data Compression
|
||||
|
||||
Draco is an open-source library for compressing and decompressing 3D geometric meshes and point clouds. It is intended to improve the storage and transmission of 3D graphics.
|
||||
|
||||
[Website](https://google.github.io/draco/) | [GitHub](https://github.com/google/draco)
|
||||
|
||||
## Contents
|
||||
|
||||
This folder contains three utilities:
|
||||
|
||||
* `draco_decoder.js` — Emscripten-compiled decoder, compatible with any modern browser.
|
||||
* `draco_decoder.wasm` — WebAssembly decoder, compatible with newer browsers and devices.
|
||||
* `draco_wasm_wrapper.js` — JavaScript wrapper for the WASM decoder.
|
||||
|
||||
Each file is provided in two variations:
|
||||
|
||||
* **Default:** Latest stable builds, tracking the project's [master branch](https://github.com/google/draco).
|
||||
* **glTF:** Builds targeted by the [glTF mesh compression extension](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression), tracking the [corresponding Draco branch](https://github.com/google/draco/tree/gltf_2.0_draco_extension).
|
||||
|
||||
Either variation may be used with `DRACOLoader`:
|
||||
|
||||
```js
|
||||
var dracoLoader = new DRACOLoader();
|
||||
dracoLoader.setDecoderPath('path/to/decoders/');
|
||||
```
|
||||
|
||||
Further [documentation on GitHub](https://github.com/google/draco/tree/master/javascript/example#static-loading-javascript-decoder).
|
||||
|
||||
## License
|
||||
|
||||
[Apache License 2.0](https://github.com/google/draco/blob/master/LICENSE)
|
||||
74285
public/vendor/addons/libs/draco/draco_decoder.js
vendored
Normal file
74285
public/vendor/addons/libs/draco/draco_decoder.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
public/vendor/addons/libs/draco/draco_decoder.wasm
vendored
Normal file
BIN
public/vendor/addons/libs/draco/draco_decoder.wasm
vendored
Normal file
Binary file not shown.
2537
public/vendor/addons/libs/draco/draco_wasm_wrapper.js
vendored
Normal file
2537
public/vendor/addons/libs/draco/draco_wasm_wrapper.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
50651
public/vendor/addons/libs/draco/gltf/draco_decoder.js
vendored
Normal file
50651
public/vendor/addons/libs/draco/gltf/draco_decoder.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
public/vendor/addons/libs/draco/gltf/draco_decoder.wasm
vendored
Normal file
BIN
public/vendor/addons/libs/draco/gltf/draco_decoder.wasm
vendored
Normal file
Binary file not shown.
2517
public/vendor/addons/libs/draco/gltf/draco_wasm_wrapper.js
vendored
Normal file
2517
public/vendor/addons/libs/draco/gltf/draco_wasm_wrapper.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
735
public/vendor/addons/loaders/DRACOLoader.js
vendored
Normal file
735
public/vendor/addons/loaders/DRACOLoader.js
vendored
Normal file
|
|
@ -0,0 +1,735 @@
|
|||
import {
|
||||
BufferAttribute,
|
||||
BufferGeometry,
|
||||
Color,
|
||||
ColorManagement,
|
||||
FileLoader,
|
||||
Loader,
|
||||
LinearSRGBColorSpace,
|
||||
SRGBColorSpace,
|
||||
InterleavedBuffer,
|
||||
InterleavedBufferAttribute,
|
||||
LoaderUtils,
|
||||
} from "three";
|
||||
|
||||
const _taskCache = new WeakMap();
|
||||
|
||||
const WASM_BIN_URL = new URL(
|
||||
"../libs/draco/draco_decoder.wasm",
|
||||
import.meta.url,
|
||||
).toString();
|
||||
const WASM_JS_URL = new URL(
|
||||
"../libs/draco/draco_wasm_wrapper.js",
|
||||
import.meta.url,
|
||||
).toString();
|
||||
const JS_URL = new URL(
|
||||
"../libs/draco/draco_decoder.js",
|
||||
import.meta.url,
|
||||
).toString();
|
||||
|
||||
const DRACO_GLTF_CONFIG = {
|
||||
js: new URL(
|
||||
"../libs/draco/gltf/draco_wasm_wrapper.js",
|
||||
import.meta.url,
|
||||
).toString(),
|
||||
wasm: new URL(
|
||||
"../libs/draco/gltf/draco_decoder.wasm",
|
||||
import.meta.url,
|
||||
).toString(),
|
||||
};
|
||||
|
||||
/**
|
||||
* A loader for the Draco format.
|
||||
*
|
||||
* [Draco](https://google.github.io/draco/) is an open source library for compressing
|
||||
* and decompressing 3D meshes and point clouds. Compressed geometry can be significantly smaller,
|
||||
* at the cost of additional decoding time on the client device.
|
||||
*
|
||||
* Standalone Draco files have a `.drc` extension, and contain vertex positions, normals, colors,
|
||||
* and other attributes. Draco files do not contain materials, textures, animation, or node hierarchies –
|
||||
* to use these features, embed Draco geometry inside of a glTF file. A normal glTF file can be converted
|
||||
* to a Draco-compressed glTF file using [glTF-Pipeline](https://github.com/CesiumGS/gltf-pipeline).
|
||||
* When using Draco with glTF, an instance of `DRACOLoader` will be used internally by {@link GLTFLoader}.
|
||||
*
|
||||
* It is recommended to create one DRACOLoader instance and reuse it to avoid loading and creating
|
||||
* multiple decoder instances.
|
||||
*
|
||||
* `DRACOLoader` will automatically use either the JS or the WASM decoding library, based on
|
||||
* browser capabilities.
|
||||
*
|
||||
* ```js
|
||||
* const loader = new DRACOLoader();
|
||||
* const geometry = await loader.loadAsync( 'models/draco/bunny.drc' );
|
||||
* geometry.computeVertexNormals(); // optional
|
||||
*
|
||||
* loader.dispose();
|
||||
* ```
|
||||
*
|
||||
* @augments Loader
|
||||
* @three_import import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
|
||||
*/
|
||||
class DRACOLoader extends Loader {
|
||||
/**
|
||||
* Constructs a new Draco loader.
|
||||
*
|
||||
* @param {LoadingManager} [manager] - The loading manager.
|
||||
*/
|
||||
constructor(manager) {
|
||||
super(manager);
|
||||
|
||||
this.decoderPaths = {
|
||||
js: WASM_JS_URL,
|
||||
wasm: WASM_BIN_URL,
|
||||
dep_js: JS_URL,
|
||||
};
|
||||
this.decoderConfig = {};
|
||||
this.decoderBinary = null;
|
||||
this.decoderPending = null;
|
||||
|
||||
this.workerLimit = 4;
|
||||
this.workerPool = [];
|
||||
this.workerNextTaskID = 1;
|
||||
this.workerSourceURL = "";
|
||||
|
||||
this.defaultAttributeIDs = {
|
||||
position: "POSITION",
|
||||
normal: "NORMAL",
|
||||
color: "COLOR",
|
||||
uv: "TEX_COORD",
|
||||
};
|
||||
this.defaultAttributeTypes = {
|
||||
position: "Float32Array",
|
||||
normal: "Float32Array",
|
||||
color: "Float32Array",
|
||||
uv: "Float32Array",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
|
||||
*
|
||||
* @param {string|{js:string, wasm:string}} path - The decoder path, or a config object with explicit URLs for each decoder file.
|
||||
* @return {DRACOLoader} A reference to this loader.
|
||||
*/
|
||||
setDecoderPath(path) {
|
||||
const { decoderPaths } = this;
|
||||
if (typeof path === "object") {
|
||||
decoderPaths.js = path.js;
|
||||
decoderPaths.wasm = path.wasm;
|
||||
decoderPaths.dep_js = null;
|
||||
} else {
|
||||
decoderPaths.js = LoaderUtils.resolveURL("draco_wasm_wrapper.js", path);
|
||||
decoderPaths.wasm = LoaderUtils.resolveURL("draco_decoder.wasm", path);
|
||||
decoderPaths.dep_js = LoaderUtils.resolveURL("draco_decoder.js", path);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {{type:('js'|'wasm')}} config - The decoder config.
|
||||
* @return {DRACOLoader} A reference to this loader.
|
||||
*/
|
||||
setDecoderConfig(config) {
|
||||
console.warn(
|
||||
"THREE.DRACOLoader: setDecoderConfig to has been deprecated and will be removed in r194.",
|
||||
);
|
||||
this.decoderConfig = config;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of Web Workers to be used during decoding.
|
||||
* A lower limit may be preferable if workers are also for other tasks in the application.
|
||||
*
|
||||
* @param {number} workerLimit - The worker limit.
|
||||
* @return {DRACOLoader} A reference to this loader.
|
||||
*/
|
||||
setWorkerLimit(workerLimit) {
|
||||
this.workerLimit = workerLimit;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts loading from the given URL and passes the loaded Draco asset
|
||||
* to the `onLoad()` callback.
|
||||
*
|
||||
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
|
||||
* @param {function(BufferGeometry)} onLoad - Executed when the loading process has been finished.
|
||||
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
|
||||
* @param {onErrorCallback} onError - Executed when errors occur.
|
||||
*/
|
||||
load(url, onLoad, onProgress, onError) {
|
||||
const loader = new FileLoader(this.manager);
|
||||
loader.setPriority(this.priority);
|
||||
loader.setCache(this.cache);
|
||||
|
||||
loader.setPath(this.path);
|
||||
loader.setResponseType("arraybuffer");
|
||||
loader.setRequestHeader(this.requestHeader);
|
||||
loader.setWithCredentials(this.withCredentials);
|
||||
|
||||
loader.load(
|
||||
url,
|
||||
(buffer) => {
|
||||
this.parse(buffer, onLoad, onError);
|
||||
},
|
||||
onProgress,
|
||||
onError,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given Draco data.
|
||||
*
|
||||
* @param {ArrayBuffer} buffer - The raw Draco data as an array buffer.
|
||||
* @param {function(BufferGeometry)} onLoad - Executed when the loading/parsing process has been finished.
|
||||
* @param {onErrorCallback} onError - Executed when errors occur.
|
||||
*/
|
||||
parse(buffer, onLoad, onError = () => {}) {
|
||||
this.decodeDracoFile(
|
||||
buffer,
|
||||
onLoad,
|
||||
null,
|
||||
null,
|
||||
SRGBColorSpace,
|
||||
onError,
|
||||
).catch(onError);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
decodeDracoFile(
|
||||
buffer,
|
||||
callback,
|
||||
attributeIDs,
|
||||
attributeTypes,
|
||||
vertexColorSpace = LinearSRGBColorSpace,
|
||||
onError = () => {},
|
||||
) {
|
||||
const taskConfig = {
|
||||
attributeIDs: attributeIDs || this.defaultAttributeIDs,
|
||||
attributeTypes: attributeTypes || this.defaultAttributeTypes,
|
||||
useUniqueIDs: !!attributeIDs,
|
||||
vertexColorSpace: vertexColorSpace,
|
||||
};
|
||||
|
||||
return this.decodeGeometry(buffer, taskConfig)
|
||||
.then(callback)
|
||||
.catch(onError);
|
||||
}
|
||||
|
||||
decodeGeometry(buffer, taskConfig) {
|
||||
const taskKey = JSON.stringify(taskConfig);
|
||||
|
||||
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
|
||||
// again from this thread.
|
||||
if (_taskCache.has(buffer)) {
|
||||
const cachedTask = _taskCache.get(buffer);
|
||||
|
||||
if (cachedTask.key === taskKey) {
|
||||
return cachedTask.promise;
|
||||
} else if (buffer.byteLength === 0) {
|
||||
// Technically, it would be possible to wait for the previous task to complete,
|
||||
// transfer the buffer back, and decode again with the second configuration. That
|
||||
// is complex, and I don't know of any reason to decode a Draco buffer twice in
|
||||
// different ways, so this is left unimplemented.
|
||||
throw new Error(
|
||||
"THREE.DRACOLoader: Unable to re-decode a buffer with different " +
|
||||
"settings. Buffer has already been transferred.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
let worker;
|
||||
const taskID = this.workerNextTaskID++;
|
||||
const taskCost = buffer.byteLength;
|
||||
|
||||
// Obtain a worker and assign a task, and construct a geometry instance
|
||||
// when the task completes.
|
||||
const geometryPending = this._getWorker(taskID, taskCost)
|
||||
.then((_worker) => {
|
||||
worker = _worker;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
worker._callbacks[taskID] = { resolve, reject };
|
||||
|
||||
worker.postMessage(
|
||||
{ type: "decode", id: taskID, taskConfig, buffer },
|
||||
[buffer],
|
||||
);
|
||||
|
||||
// this.debug();
|
||||
});
|
||||
})
|
||||
.then((message) => this._createGeometry(message.geometry));
|
||||
|
||||
// Remove task from the task list.
|
||||
// Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
|
||||
geometryPending
|
||||
.catch(() => true)
|
||||
.then(() => {
|
||||
if (worker && taskID) {
|
||||
this._releaseTask(worker, taskID);
|
||||
|
||||
// this.debug();
|
||||
}
|
||||
});
|
||||
|
||||
// Cache the task result.
|
||||
_taskCache.set(buffer, {
|
||||
key: taskKey,
|
||||
promise: geometryPending,
|
||||
});
|
||||
|
||||
return geometryPending;
|
||||
}
|
||||
|
||||
_createGeometry(geometryData) {
|
||||
const geometry = new BufferGeometry();
|
||||
|
||||
if (geometryData.index) {
|
||||
geometry.setIndex(new BufferAttribute(geometryData.index.array, 1));
|
||||
}
|
||||
|
||||
for (let i = 0; i < geometryData.attributes.length; i++) {
|
||||
const { name, array, itemSize, stride, vertexColorSpace } =
|
||||
geometryData.attributes[i];
|
||||
|
||||
let attribute;
|
||||
|
||||
if (itemSize === stride) {
|
||||
attribute = new BufferAttribute(array, itemSize);
|
||||
} else {
|
||||
const buffer = new InterleavedBuffer(array, stride);
|
||||
|
||||
attribute = new InterleavedBufferAttribute(buffer, itemSize, 0);
|
||||
}
|
||||
|
||||
if (name === "color") {
|
||||
this._assignVertexColorSpace(attribute, vertexColorSpace);
|
||||
|
||||
attribute.normalized = array instanceof Float32Array === false;
|
||||
}
|
||||
|
||||
geometry.setAttribute(name, attribute);
|
||||
}
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
_assignVertexColorSpace(attribute, inputColorSpace) {
|
||||
// While .drc files do not specify colorspace, the only 'official' tooling
|
||||
// is PLY and OBJ converters, which use sRGB. We'll assume sRGB when a .drc
|
||||
// file is passed into .load() or .parse(). GLTFLoader uses internal APIs
|
||||
// to decode geometry, and vertex colors are already Linear-sRGB in there.
|
||||
|
||||
if (inputColorSpace !== SRGBColorSpace) return;
|
||||
|
||||
const _color = new Color();
|
||||
|
||||
for (let i = 0, il = attribute.count; i < il; i++) {
|
||||
_color.fromBufferAttribute(attribute, i);
|
||||
ColorManagement.colorSpaceToWorking(_color, SRGBColorSpace);
|
||||
attribute.setXYZ(i, _color.r, _color.g, _color.b);
|
||||
}
|
||||
}
|
||||
|
||||
_loadLibrary(url, responseType) {
|
||||
const loader = new FileLoader(this.manager);
|
||||
loader.setPriority(this.priority);
|
||||
loader.setCache(this.cache);
|
||||
loader.setResponseType(responseType);
|
||||
loader.setWithCredentials(this.withCredentials);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
loader.load(url, resolve, undefined, reject);
|
||||
});
|
||||
}
|
||||
|
||||
preload() {
|
||||
this._initDecoder();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
_initDecoder() {
|
||||
if (this.decoderPending) return this.decoderPending;
|
||||
|
||||
const useJS =
|
||||
typeof WebAssembly !== "object" || this.decoderConfig.type === "js";
|
||||
const librariesPending = [];
|
||||
|
||||
const { decoderPaths } = this;
|
||||
if (useJS) {
|
||||
if (decoderPaths.dep_js === null) {
|
||||
throw new Error(
|
||||
"THREE.DRACOLoader: WebAssembly is required when using a custom decoder paths.",
|
||||
);
|
||||
}
|
||||
|
||||
librariesPending.push(this._loadLibrary(decoderPaths.dep_js, "text"));
|
||||
} else {
|
||||
librariesPending.push(this._loadLibrary(decoderPaths.js, "text"));
|
||||
librariesPending.push(
|
||||
this._loadLibrary(decoderPaths.wasm, "arraybuffer"),
|
||||
);
|
||||
}
|
||||
|
||||
this.decoderPending = Promise.all(librariesPending).then((libraries) => {
|
||||
const jsContent = libraries[0];
|
||||
|
||||
if (!useJS) {
|
||||
this.decoderConfig.wasmBinary = libraries[1];
|
||||
}
|
||||
|
||||
const fn = DRACOWorker.toString();
|
||||
|
||||
const body = [
|
||||
"/* draco decoder */",
|
||||
jsContent,
|
||||
"",
|
||||
"/* worker */",
|
||||
fn.substring(fn.indexOf("{") + 1, fn.lastIndexOf("}")),
|
||||
].join("\n");
|
||||
|
||||
this.workerSourceURL = URL.createObjectURL(new Blob([body]));
|
||||
});
|
||||
|
||||
return this.decoderPending;
|
||||
}
|
||||
|
||||
_getWorker(taskID, taskCost) {
|
||||
return this._initDecoder().then(() => {
|
||||
if (this.workerPool.length < this.workerLimit) {
|
||||
const worker = new Worker(this.workerSourceURL);
|
||||
|
||||
worker._callbacks = {};
|
||||
worker._taskCosts = {};
|
||||
worker._taskLoad = 0;
|
||||
|
||||
worker.postMessage({ type: "init", decoderConfig: this.decoderConfig });
|
||||
|
||||
worker.onmessage = function (e) {
|
||||
const message = e.data;
|
||||
|
||||
switch (message.type) {
|
||||
case "decode":
|
||||
worker._callbacks[message.id].resolve(message);
|
||||
break;
|
||||
|
||||
case "error":
|
||||
worker._callbacks[message.id].reject(message);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.error(
|
||||
'THREE.DRACOLoader: Unexpected message, "' + message.type + '"',
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
this.workerPool.push(worker);
|
||||
} else {
|
||||
this.workerPool.sort(function (a, b) {
|
||||
return a._taskLoad > b._taskLoad ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
||||
const worker = this.workerPool[this.workerPool.length - 1];
|
||||
worker._taskCosts[taskID] = taskCost;
|
||||
worker._taskLoad += taskCost;
|
||||
return worker;
|
||||
});
|
||||
}
|
||||
|
||||
_releaseTask(worker, taskID) {
|
||||
worker._taskLoad -= worker._taskCosts[taskID];
|
||||
delete worker._callbacks[taskID];
|
||||
delete worker._taskCosts[taskID];
|
||||
}
|
||||
|
||||
debug() {
|
||||
console.log(
|
||||
"Task load: ",
|
||||
this.workerPool.map((worker) => worker._taskLoad),
|
||||
);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
for (let i = 0; i < this.workerPool.length; ++i) {
|
||||
this.workerPool[i].terminate();
|
||||
}
|
||||
|
||||
this.workerPool.length = 0;
|
||||
|
||||
if (this.workerSourceURL !== "") {
|
||||
URL.revokeObjectURL(this.workerSourceURL);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/* WEB WORKER */
|
||||
|
||||
function DRACOWorker() {
|
||||
let decoderConfig;
|
||||
let decoderPending;
|
||||
|
||||
onmessage = function (e) {
|
||||
const message = e.data;
|
||||
|
||||
switch (message.type) {
|
||||
case "init":
|
||||
decoderConfig = message.decoderConfig;
|
||||
decoderPending = new Promise(function (resolve /*, reject*/) {
|
||||
decoderConfig.onModuleLoaded = function (draco) {
|
||||
// Module is Promise-like. Wrap before resolving to avoid loop.
|
||||
resolve({ draco: draco });
|
||||
};
|
||||
|
||||
DracoDecoderModule(decoderConfig); // eslint-disable-line no-undef
|
||||
});
|
||||
break;
|
||||
|
||||
case "decode":
|
||||
const buffer = message.buffer;
|
||||
const taskConfig = message.taskConfig;
|
||||
decoderPending.then((module) => {
|
||||
const draco = module.draco;
|
||||
const decoder = new draco.Decoder();
|
||||
|
||||
try {
|
||||
const geometry = decodeGeometry(
|
||||
draco,
|
||||
decoder,
|
||||
new Int8Array(buffer),
|
||||
taskConfig,
|
||||
);
|
||||
|
||||
const buffers = geometry.attributes.map(
|
||||
(attr) => attr.array.buffer,
|
||||
);
|
||||
|
||||
if (geometry.index) buffers.push(geometry.index.array.buffer);
|
||||
|
||||
self.postMessage(
|
||||
{ type: "decode", id: message.id, geometry },
|
||||
buffers,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
self.postMessage({
|
||||
type: "error",
|
||||
id: message.id,
|
||||
error: error.message,
|
||||
});
|
||||
} finally {
|
||||
draco.destroy(decoder);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
function decodeGeometry(draco, decoder, array, taskConfig) {
|
||||
const attributeIDs = taskConfig.attributeIDs;
|
||||
const attributeTypes = taskConfig.attributeTypes;
|
||||
|
||||
let dracoGeometry;
|
||||
let decodingStatus;
|
||||
|
||||
const geometryType = decoder.GetEncodedGeometryType(array);
|
||||
|
||||
if (geometryType === draco.TRIANGULAR_MESH) {
|
||||
dracoGeometry = new draco.Mesh();
|
||||
decodingStatus = decoder.DecodeArrayToMesh(
|
||||
array,
|
||||
array.byteLength,
|
||||
dracoGeometry,
|
||||
);
|
||||
} else if (geometryType === draco.POINT_CLOUD) {
|
||||
dracoGeometry = new draco.PointCloud();
|
||||
decodingStatus = decoder.DecodeArrayToPointCloud(
|
||||
array,
|
||||
array.byteLength,
|
||||
dracoGeometry,
|
||||
);
|
||||
} else {
|
||||
throw new Error("THREE.DRACOLoader: Unexpected geometry type.");
|
||||
}
|
||||
|
||||
if (!decodingStatus.ok() || dracoGeometry.ptr === 0) {
|
||||
throw new Error(
|
||||
"THREE.DRACOLoader: Decoding failed: " + decodingStatus.error_msg(),
|
||||
);
|
||||
}
|
||||
|
||||
const geometry = { index: null, attributes: [] };
|
||||
|
||||
// Gather all vertex attributes.
|
||||
for (const attributeName in attributeIDs) {
|
||||
const attributeType = self[attributeTypes[attributeName]];
|
||||
|
||||
let attribute;
|
||||
let attributeID;
|
||||
|
||||
// A Draco file may be created with default vertex attributes, whose attribute IDs
|
||||
// are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
|
||||
// a Draco file may contain a custom set of attributes, identified by known unique
|
||||
// IDs. glTF files always do the latter, and `.drc` files typically do the former.
|
||||
if (taskConfig.useUniqueIDs) {
|
||||
attributeID = attributeIDs[attributeName];
|
||||
attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeID);
|
||||
} else {
|
||||
attributeID = decoder.GetAttributeId(
|
||||
dracoGeometry,
|
||||
draco[attributeIDs[attributeName]],
|
||||
);
|
||||
|
||||
if (attributeID === -1) continue;
|
||||
|
||||
attribute = decoder.GetAttribute(dracoGeometry, attributeID);
|
||||
}
|
||||
|
||||
const attributeResult = decodeAttribute(
|
||||
draco,
|
||||
decoder,
|
||||
dracoGeometry,
|
||||
attributeName,
|
||||
attributeType,
|
||||
attribute,
|
||||
);
|
||||
|
||||
if (attributeName === "color") {
|
||||
attributeResult.vertexColorSpace = taskConfig.vertexColorSpace;
|
||||
}
|
||||
|
||||
geometry.attributes.push(attributeResult);
|
||||
}
|
||||
|
||||
// Add index.
|
||||
if (geometryType === draco.TRIANGULAR_MESH) {
|
||||
geometry.index = decodeIndex(draco, decoder, dracoGeometry);
|
||||
}
|
||||
|
||||
draco.destroy(dracoGeometry);
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
function decodeIndex(draco, decoder, dracoGeometry) {
|
||||
const numFaces = dracoGeometry.num_faces();
|
||||
const numIndices = numFaces * 3;
|
||||
const byteLength = numIndices * 4;
|
||||
|
||||
const ptr = draco._malloc(byteLength);
|
||||
decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
|
||||
const index = new Uint32Array(
|
||||
draco.HEAPF32.buffer,
|
||||
ptr,
|
||||
numIndices,
|
||||
).slice();
|
||||
draco._free(ptr);
|
||||
|
||||
return { array: index, itemSize: 1 };
|
||||
}
|
||||
|
||||
function decodeAttribute(
|
||||
draco,
|
||||
decoder,
|
||||
dracoGeometry,
|
||||
attributeName,
|
||||
TypedArray,
|
||||
attribute,
|
||||
) {
|
||||
const count = dracoGeometry.num_points();
|
||||
const itemSize = attribute.num_components();
|
||||
const dracoDataType = getDracoDataType(draco, TypedArray);
|
||||
|
||||
// Reference: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#data-alignment
|
||||
const srcByteStride = itemSize * TypedArray.BYTES_PER_ELEMENT;
|
||||
const dstByteStride = Math.ceil(srcByteStride / 4) * 4;
|
||||
|
||||
const dstStride = dstByteStride / TypedArray.BYTES_PER_ELEMENT;
|
||||
|
||||
const srcByteLength = count * srcByteStride;
|
||||
const dstByteLength = count * dstByteStride;
|
||||
|
||||
const ptr = draco._malloc(srcByteLength);
|
||||
decoder.GetAttributeDataArrayForAllPoints(
|
||||
dracoGeometry,
|
||||
attribute,
|
||||
dracoDataType,
|
||||
srcByteLength,
|
||||
ptr,
|
||||
);
|
||||
|
||||
const srcArray = new TypedArray(
|
||||
draco.HEAPF32.buffer,
|
||||
ptr,
|
||||
srcByteLength / TypedArray.BYTES_PER_ELEMENT,
|
||||
);
|
||||
let dstArray;
|
||||
|
||||
if (srcByteStride === dstByteStride) {
|
||||
// THREE.BufferAttribute
|
||||
|
||||
dstArray = srcArray.slice();
|
||||
} else {
|
||||
// THREE.InterleavedBufferAttribute
|
||||
|
||||
dstArray = new TypedArray(dstByteLength / TypedArray.BYTES_PER_ELEMENT);
|
||||
|
||||
let dstOffset = 0;
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
for (let j = 0; j < itemSize; j++) {
|
||||
dstArray[dstOffset + j] = srcArray[i * itemSize + j];
|
||||
}
|
||||
|
||||
dstOffset += dstStride;
|
||||
}
|
||||
}
|
||||
|
||||
draco._free(ptr);
|
||||
|
||||
return {
|
||||
name: attributeName,
|
||||
count: count,
|
||||
itemSize: itemSize,
|
||||
array: dstArray,
|
||||
stride: dstStride,
|
||||
};
|
||||
}
|
||||
|
||||
function getDracoDataType(draco, TypedArray) {
|
||||
switch (TypedArray) {
|
||||
case Float32Array:
|
||||
return draco.DT_FLOAT32;
|
||||
case Int8Array:
|
||||
return draco.DT_INT8;
|
||||
case Int16Array:
|
||||
return draco.DT_INT16;
|
||||
case Int32Array:
|
||||
return draco.DT_INT32;
|
||||
case Uint8Array:
|
||||
return draco.DT_UINT8;
|
||||
case Uint16Array:
|
||||
return draco.DT_UINT16;
|
||||
case Uint32Array:
|
||||
return draco.DT_UINT32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { DRACOLoader, DRACO_GLTF_CONFIG };
|
||||
4629
public/vendor/addons/loaders/GLTFLoader.js
vendored
Normal file
4629
public/vendor/addons/loaders/GLTFLoader.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
337
public/vendor/addons/postprocessing/EffectComposer.js
vendored
Normal file
337
public/vendor/addons/postprocessing/EffectComposer.js
vendored
Normal file
|
|
@ -0,0 +1,337 @@
|
|||
import {
|
||||
HalfFloatType,
|
||||
NoBlending,
|
||||
Timer,
|
||||
Vector2,
|
||||
WebGLRenderTarget,
|
||||
} from "three";
|
||||
import { CopyShader } from "../shaders/CopyShader.js";
|
||||
import { ShaderPass } from "./ShaderPass.js";
|
||||
import { ClearMaskPass, MaskPass } from "./MaskPass.js";
|
||||
|
||||
/**
|
||||
* Used to implement post-processing effects in three.js.
|
||||
* The class manages a chain of post-processing passes to produce the final visual result.
|
||||
* Post-processing passes are executed in order of their addition/insertion.
|
||||
* The last pass is automatically rendered to screen.
|
||||
*
|
||||
* This module can only be used with {@link WebGLRenderer}.
|
||||
*
|
||||
* ```js
|
||||
* const composer = new EffectComposer( renderer );
|
||||
*
|
||||
* // adding some passes
|
||||
* const renderPass = new RenderPass( scene, camera );
|
||||
* composer.addPass( renderPass );
|
||||
*
|
||||
* const glitchPass = new GlitchPass();
|
||||
* composer.addPass( glitchPass );
|
||||
*
|
||||
* const outputPass = new OutputPass()
|
||||
* composer.addPass( outputPass );
|
||||
*
|
||||
* function animate() {
|
||||
*
|
||||
* composer.render(); // instead of renderer.render()
|
||||
*
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @three_import import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
||||
*/
|
||||
class EffectComposer {
|
||||
/**
|
||||
* Constructs a new effect composer.
|
||||
*
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
* @param {WebGLRenderTarget} [renderTarget] - This render target and a clone will
|
||||
* be used as the internal read and write buffers. If not given, the composer creates
|
||||
* the buffers automatically.
|
||||
*/
|
||||
constructor(renderer, renderTarget) {
|
||||
/**
|
||||
* The renderer.
|
||||
*
|
||||
* @type {WebGLRenderer}
|
||||
*/
|
||||
this.renderer = renderer;
|
||||
|
||||
this._pixelRatio = renderer.getPixelRatio();
|
||||
|
||||
if (renderTarget === undefined) {
|
||||
const size = renderer.getSize(new Vector2());
|
||||
this._width = size.width;
|
||||
this._height = size.height;
|
||||
|
||||
renderTarget = new WebGLRenderTarget(
|
||||
this._width * this._pixelRatio,
|
||||
this._height * this._pixelRatio,
|
||||
{ type: HalfFloatType },
|
||||
);
|
||||
renderTarget.texture.name = "EffectComposer.rt1";
|
||||
} else {
|
||||
this._width = renderTarget.width;
|
||||
this._height = renderTarget.height;
|
||||
}
|
||||
|
||||
this.renderTarget1 = renderTarget;
|
||||
this.renderTarget2 = renderTarget.clone();
|
||||
this.renderTarget2.texture.name = "EffectComposer.rt2";
|
||||
|
||||
/**
|
||||
* A reference to the internal write buffer. Passes usually write
|
||||
* their result into this buffer.
|
||||
*
|
||||
* @type {WebGLRenderTarget}
|
||||
*/
|
||||
this.writeBuffer = this.renderTarget1;
|
||||
|
||||
/**
|
||||
* A reference to the internal read buffer. Passes usually read
|
||||
* the previous render result from this buffer.
|
||||
*
|
||||
* @type {WebGLRenderTarget}
|
||||
*/
|
||||
this.readBuffer = this.renderTarget2;
|
||||
|
||||
/**
|
||||
* Whether the final pass is rendered to the screen (default framebuffer) or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.renderToScreen = true;
|
||||
|
||||
/**
|
||||
* An array representing the (ordered) chain of post-processing passes.
|
||||
*
|
||||
* @type {Array<Pass>}
|
||||
*/
|
||||
this.passes = [];
|
||||
|
||||
/**
|
||||
* A copy pass used for internal swap operations.
|
||||
*
|
||||
* @private
|
||||
* @type {ShaderPass}
|
||||
*/
|
||||
this.copyPass = new ShaderPass(CopyShader);
|
||||
this.copyPass.material.blending = NoBlending;
|
||||
|
||||
/**
|
||||
* The internal timer for managing time data.
|
||||
*
|
||||
* @private
|
||||
* @type {Timer}
|
||||
*/
|
||||
this.timer = new Timer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Swaps the internal read/write buffers.
|
||||
*/
|
||||
swapBuffers() {
|
||||
const tmp = this.readBuffer;
|
||||
this.readBuffer = this.writeBuffer;
|
||||
this.writeBuffer = tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given pass to the pass chain.
|
||||
*
|
||||
* @param {Pass} pass - The pass to add.
|
||||
*/
|
||||
addPass(pass) {
|
||||
this.passes.push(pass);
|
||||
pass.setSize(
|
||||
this._width * this._pixelRatio,
|
||||
this._height * this._pixelRatio,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the given pass at a given index.
|
||||
*
|
||||
* @param {Pass} pass - The pass to insert.
|
||||
* @param {number} index - The index into the pass chain.
|
||||
*/
|
||||
insertPass(pass, index) {
|
||||
this.passes.splice(index, 0, pass);
|
||||
pass.setSize(
|
||||
this._width * this._pixelRatio,
|
||||
this._height * this._pixelRatio,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given pass from the pass chain.
|
||||
*
|
||||
* @param {Pass} pass - The pass to remove.
|
||||
*/
|
||||
removePass(pass) {
|
||||
const index = this.passes.indexOf(pass);
|
||||
|
||||
if (index !== -1) {
|
||||
this.passes.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the pass for the given index is the last enabled pass in the pass chain.
|
||||
*
|
||||
* @param {number} passIndex - The pass index.
|
||||
* @return {boolean} Whether the pass for the given index is the last pass in the pass chain.
|
||||
*/
|
||||
isLastEnabledPass(passIndex) {
|
||||
for (let i = passIndex + 1; i < this.passes.length; i++) {
|
||||
if (this.passes[i].enabled) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all enabled post-processing passes in order to produce the final frame.
|
||||
*
|
||||
* @param {number} deltaTime - The delta time in seconds. If not given, the composer computes
|
||||
* its own time delta value.
|
||||
*/
|
||||
render(deltaTime) {
|
||||
// deltaTime value is in seconds
|
||||
|
||||
this.timer.update();
|
||||
|
||||
if (deltaTime === undefined) {
|
||||
deltaTime = this.timer.getDelta();
|
||||
}
|
||||
|
||||
const currentRenderTarget = this.renderer.getRenderTarget();
|
||||
|
||||
let maskActive = false;
|
||||
|
||||
for (let i = 0, il = this.passes.length; i < il; i++) {
|
||||
const pass = this.passes[i];
|
||||
|
||||
if (pass.enabled === false) continue;
|
||||
|
||||
pass.renderToScreen = this.renderToScreen && this.isLastEnabledPass(i);
|
||||
pass.render(
|
||||
this.renderer,
|
||||
this.writeBuffer,
|
||||
this.readBuffer,
|
||||
deltaTime,
|
||||
maskActive,
|
||||
);
|
||||
|
||||
if (pass.needsSwap) {
|
||||
if (maskActive) {
|
||||
const context = this.renderer.getContext();
|
||||
const stencil = this.renderer.state.buffers.stencil;
|
||||
|
||||
//context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );
|
||||
stencil.setFunc(context.NOTEQUAL, 1, 0xffffffff);
|
||||
|
||||
this.copyPass.render(
|
||||
this.renderer,
|
||||
this.writeBuffer,
|
||||
this.readBuffer,
|
||||
deltaTime,
|
||||
);
|
||||
|
||||
//context.stencilFunc( context.EQUAL, 1, 0xffffffff );
|
||||
stencil.setFunc(context.EQUAL, 1, 0xffffffff);
|
||||
}
|
||||
|
||||
this.swapBuffers();
|
||||
}
|
||||
|
||||
if (MaskPass !== undefined) {
|
||||
if (pass instanceof MaskPass) {
|
||||
maskActive = true;
|
||||
} else if (pass instanceof ClearMaskPass) {
|
||||
maskActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.renderer.setRenderTarget(currentRenderTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the internal state of the EffectComposer.
|
||||
*
|
||||
* @param {WebGLRenderTarget} [renderTarget] - This render target has the same purpose like
|
||||
* the one from the constructor. If set, it is used to setup the read and write buffers.
|
||||
*/
|
||||
reset(renderTarget) {
|
||||
if (renderTarget === undefined) {
|
||||
const size = this.renderer.getSize(new Vector2());
|
||||
this._pixelRatio = this.renderer.getPixelRatio();
|
||||
this._width = size.width;
|
||||
this._height = size.height;
|
||||
|
||||
renderTarget = this.renderTarget1.clone();
|
||||
renderTarget.setSize(
|
||||
this._width * this._pixelRatio,
|
||||
this._height * this._pixelRatio,
|
||||
);
|
||||
}
|
||||
|
||||
this.renderTarget1.dispose();
|
||||
this.renderTarget2.dispose();
|
||||
this.renderTarget1 = renderTarget;
|
||||
this.renderTarget2 = renderTarget.clone();
|
||||
|
||||
this.writeBuffer = this.renderTarget1;
|
||||
this.readBuffer = this.renderTarget2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizes the internal read and write buffers as well as all passes. Similar to {@link WebGLRenderer#setSize},
|
||||
* this method honors the current pixel ration.
|
||||
*
|
||||
* @param {number} width - The width in logical pixels.
|
||||
* @param {number} height - The height in logical pixels.
|
||||
*/
|
||||
setSize(width, height) {
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
|
||||
const effectiveWidth = this._width * this._pixelRatio;
|
||||
const effectiveHeight = this._height * this._pixelRatio;
|
||||
|
||||
this.renderTarget1.setSize(effectiveWidth, effectiveHeight);
|
||||
this.renderTarget2.setSize(effectiveWidth, effectiveHeight);
|
||||
|
||||
for (let i = 0; i < this.passes.length; i++) {
|
||||
this.passes[i].setSize(effectiveWidth, effectiveHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets device pixel ratio. This is usually used for HiDPI device to prevent blurring output.
|
||||
* Setting the pixel ratio will automatically resize the composer.
|
||||
*
|
||||
* @param {number} pixelRatio - The pixel ratio to set.
|
||||
*/
|
||||
setPixelRatio(pixelRatio) {
|
||||
this._pixelRatio = pixelRatio;
|
||||
|
||||
this.setSize(this._width, this._height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever the composer is no longer used in your app.
|
||||
*/
|
||||
dispose() {
|
||||
this.renderTarget1.dispose();
|
||||
this.renderTarget2.dispose();
|
||||
|
||||
this.copyPass.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
export { EffectComposer };
|
||||
183
public/vendor/addons/postprocessing/MaskPass.js
vendored
Normal file
183
public/vendor/addons/postprocessing/MaskPass.js
vendored
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
import { Pass } from "./Pass.js";
|
||||
|
||||
/**
|
||||
* This pass can be used to define a mask during post processing.
|
||||
* Meaning only areas of subsequent post processing are affected
|
||||
* which lie in the masking area of this pass. Internally, the masking
|
||||
* is implemented with the stencil buffer.
|
||||
*
|
||||
* ```js
|
||||
* const maskPass = new MaskPass( scene, camera );
|
||||
* composer.addPass( maskPass );
|
||||
* ```
|
||||
*
|
||||
* @augments Pass
|
||||
* @three_import import { MaskPass } from 'three/addons/postprocessing/MaskPass.js';
|
||||
*/
|
||||
class MaskPass extends Pass {
|
||||
/**
|
||||
* Constructs a new mask pass.
|
||||
*
|
||||
* @param {Scene} scene - The 3D objects in this scene will define the mask.
|
||||
* @param {Camera} camera - The camera.
|
||||
*/
|
||||
constructor(scene, camera) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The scene that defines the mask.
|
||||
*
|
||||
* @type {Scene}
|
||||
*/
|
||||
this.scene = scene;
|
||||
|
||||
/**
|
||||
* The camera.
|
||||
*
|
||||
* @type {Camera}
|
||||
*/
|
||||
this.camera = camera;
|
||||
|
||||
/**
|
||||
* Overwritten to perform a clear operation by default.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.clear = true;
|
||||
|
||||
/**
|
||||
* Overwritten to disable the swap.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.needsSwap = false;
|
||||
|
||||
/**
|
||||
* Whether to inverse the mask or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.inverse = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a mask pass with the configured scene and camera.
|
||||
*
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||
* destination for the pass.
|
||||
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||
* previous pass from this buffer.
|
||||
* @param {number} deltaTime - The delta time in seconds.
|
||||
* @param {boolean} maskActive - Whether masking is active or not.
|
||||
*/
|
||||
render(renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
|
||||
const context = renderer.getContext();
|
||||
const state = renderer.state;
|
||||
|
||||
// don't update color or depth
|
||||
|
||||
state.buffers.color.setMask(false);
|
||||
state.buffers.depth.setMask(false);
|
||||
|
||||
// lock buffers
|
||||
|
||||
state.buffers.color.setLocked(true);
|
||||
state.buffers.depth.setLocked(true);
|
||||
|
||||
// set up stencil
|
||||
|
||||
let writeValue, clearValue;
|
||||
|
||||
if (this.inverse) {
|
||||
writeValue = 0;
|
||||
clearValue = 1;
|
||||
} else {
|
||||
writeValue = 1;
|
||||
clearValue = 0;
|
||||
}
|
||||
|
||||
state.buffers.stencil.setTest(true);
|
||||
state.buffers.stencil.setOp(
|
||||
context.REPLACE,
|
||||
context.REPLACE,
|
||||
context.REPLACE,
|
||||
);
|
||||
state.buffers.stencil.setFunc(context.ALWAYS, writeValue, 0xffffffff);
|
||||
state.buffers.stencil.setClear(clearValue);
|
||||
state.buffers.stencil.setLocked(true);
|
||||
|
||||
// draw into the stencil buffer
|
||||
|
||||
renderer.setRenderTarget(readBuffer);
|
||||
if (this.clear) renderer.clear();
|
||||
renderer.render(this.scene, this.camera);
|
||||
|
||||
renderer.setRenderTarget(writeBuffer);
|
||||
if (this.clear) renderer.clear();
|
||||
renderer.render(this.scene, this.camera);
|
||||
|
||||
// unlock color and depth buffer and make them writable for subsequent rendering/clearing
|
||||
|
||||
state.buffers.color.setLocked(false);
|
||||
state.buffers.depth.setLocked(false);
|
||||
|
||||
state.buffers.color.setMask(true);
|
||||
state.buffers.depth.setMask(true);
|
||||
|
||||
// only render where stencil is set to 1
|
||||
|
||||
state.buffers.stencil.setLocked(false);
|
||||
state.buffers.stencil.setFunc(context.EQUAL, 1, 0xffffffff); // draw if == 1
|
||||
state.buffers.stencil.setOp(context.KEEP, context.KEEP, context.KEEP);
|
||||
state.buffers.stencil.setLocked(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This pass can be used to clear a mask previously defined with {@link MaskPass}.
|
||||
*
|
||||
* ```js
|
||||
* const clearPass = new ClearMaskPass();
|
||||
* composer.addPass( clearPass );
|
||||
* ```
|
||||
*
|
||||
* @augments Pass
|
||||
*/
|
||||
class ClearMaskPass extends Pass {
|
||||
/**
|
||||
* Constructs a new clear mask pass.
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
/**
|
||||
* Overwritten to disable the swap.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.needsSwap = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the clear of the currently defined mask.
|
||||
*
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||
* destination for the pass.
|
||||
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||
* previous pass from this buffer.
|
||||
* @param {number} deltaTime - The delta time in seconds.
|
||||
* @param {boolean} maskActive - Whether masking is active or not.
|
||||
*/
|
||||
render(renderer /*, writeBuffer, readBuffer, deltaTime, maskActive */) {
|
||||
renderer.state.buffers.stencil.setLocked(false);
|
||||
renderer.state.buffers.stencil.setTest(false);
|
||||
}
|
||||
}
|
||||
|
||||
export { MaskPass, ClearMaskPass };
|
||||
150
public/vendor/addons/postprocessing/OutputPass.js
vendored
Normal file
150
public/vendor/addons/postprocessing/OutputPass.js
vendored
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
import {
|
||||
ColorManagement,
|
||||
RawShaderMaterial,
|
||||
UniformsUtils,
|
||||
LinearToneMapping,
|
||||
ReinhardToneMapping,
|
||||
CineonToneMapping,
|
||||
AgXToneMapping,
|
||||
ACESFilmicToneMapping,
|
||||
NeutralToneMapping,
|
||||
CustomToneMapping,
|
||||
SRGBTransfer,
|
||||
} from "three";
|
||||
import { Pass, FullScreenQuad } from "./Pass.js";
|
||||
import { OutputShader } from "../shaders/OutputShader.js";
|
||||
|
||||
/**
|
||||
* This pass is responsible for including tone mapping and color space conversion
|
||||
* into your pass chain. In most cases, this pass should be included at the end
|
||||
* of each pass chain. If a pass requires sRGB input (e.g. like FXAA), the pass
|
||||
* must follow `OutputPass` in the pass chain.
|
||||
*
|
||||
* The tone mapping and color space settings are extracted from the renderer.
|
||||
*
|
||||
* ```js
|
||||
* const outputPass = new OutputPass();
|
||||
* composer.addPass( outputPass );
|
||||
* ```
|
||||
*
|
||||
* @augments Pass
|
||||
* @three_import import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
|
||||
*/
|
||||
class OutputPass extends Pass {
|
||||
/**
|
||||
* Constructs a new output pass.
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag indicates that this is an output pass.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isOutputPass = true;
|
||||
|
||||
/**
|
||||
* The pass uniforms.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.uniforms = UniformsUtils.clone(OutputShader.uniforms);
|
||||
|
||||
/**
|
||||
* The pass material.
|
||||
*
|
||||
* @type {RawShaderMaterial}
|
||||
*/
|
||||
this.material = new RawShaderMaterial({
|
||||
name: OutputShader.name,
|
||||
uniforms: this.uniforms,
|
||||
vertexShader: OutputShader.vertexShader,
|
||||
fragmentShader: OutputShader.fragmentShader,
|
||||
});
|
||||
|
||||
// internals
|
||||
|
||||
this._fsQuad = new FullScreenQuad(this.material);
|
||||
|
||||
this._outputColorSpace = null;
|
||||
this._toneMapping = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the output pass.
|
||||
*
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||
* destination for the pass.
|
||||
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||
* previous pass from this buffer.
|
||||
* @param {number} deltaTime - The delta time in seconds.
|
||||
* @param {boolean} maskActive - Whether masking is active or not.
|
||||
*/
|
||||
render(renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
|
||||
this.uniforms["tDiffuse"].value = readBuffer.texture;
|
||||
this.uniforms["toneMappingExposure"].value = renderer.toneMappingExposure;
|
||||
|
||||
// rebuild defines if required
|
||||
|
||||
if (
|
||||
this._outputColorSpace !== renderer.outputColorSpace ||
|
||||
this._toneMapping !== renderer.toneMapping
|
||||
) {
|
||||
this._outputColorSpace = renderer.outputColorSpace;
|
||||
this._toneMapping = renderer.toneMapping;
|
||||
|
||||
this.material.defines = {};
|
||||
|
||||
if (ColorManagement.getTransfer(this._outputColorSpace) === SRGBTransfer)
|
||||
this.material.defines.SRGB_TRANSFER = "";
|
||||
|
||||
if (this._toneMapping === LinearToneMapping)
|
||||
this.material.defines.LINEAR_TONE_MAPPING = "";
|
||||
else if (this._toneMapping === ReinhardToneMapping)
|
||||
this.material.defines.REINHARD_TONE_MAPPING = "";
|
||||
else if (this._toneMapping === CineonToneMapping)
|
||||
this.material.defines.CINEON_TONE_MAPPING = "";
|
||||
else if (this._toneMapping === ACESFilmicToneMapping)
|
||||
this.material.defines.ACES_FILMIC_TONE_MAPPING = "";
|
||||
else if (this._toneMapping === AgXToneMapping)
|
||||
this.material.defines.AGX_TONE_MAPPING = "";
|
||||
else if (this._toneMapping === NeutralToneMapping)
|
||||
this.material.defines.NEUTRAL_TONE_MAPPING = "";
|
||||
else if (this._toneMapping === CustomToneMapping)
|
||||
this.material.defines.CUSTOM_TONE_MAPPING = "";
|
||||
|
||||
this.material.needsUpdate = true;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
if (this.renderToScreen === true) {
|
||||
renderer.setRenderTarget(null);
|
||||
this._fsQuad.render(renderer);
|
||||
} else {
|
||||
renderer.setRenderTarget(writeBuffer);
|
||||
if (this.clear)
|
||||
renderer.clear(
|
||||
renderer.autoClearColor,
|
||||
renderer.autoClearDepth,
|
||||
renderer.autoClearStencil,
|
||||
);
|
||||
this._fsQuad.render(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever the pass is no longer used in your app.
|
||||
*/
|
||||
dispose() {
|
||||
this.material.dispose();
|
||||
this._fsQuad.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
export { OutputPass };
|
||||
171
public/vendor/addons/postprocessing/Pass.js
vendored
Normal file
171
public/vendor/addons/postprocessing/Pass.js
vendored
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
import {
|
||||
BufferGeometry,
|
||||
Float32BufferAttribute,
|
||||
OrthographicCamera,
|
||||
Mesh,
|
||||
} from "three";
|
||||
|
||||
/**
|
||||
* Abstract base class for all post processing passes.
|
||||
*
|
||||
* This module is only relevant for post processing with {@link WebGLRenderer}.
|
||||
*
|
||||
* @abstract
|
||||
* @three_import import { Pass } from 'three/addons/postprocessing/Pass.js';
|
||||
*/
|
||||
class Pass {
|
||||
/**
|
||||
* Constructs a new pass.
|
||||
*/
|
||||
constructor() {
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isPass = true;
|
||||
|
||||
/**
|
||||
* If set to `true`, the pass is processed by the composer.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.enabled = true;
|
||||
|
||||
/**
|
||||
* If set to `true`, the pass indicates to swap read and write buffer after rendering.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.needsSwap = true;
|
||||
|
||||
/**
|
||||
* If set to `true`, the pass clears its buffer before rendering
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.clear = false;
|
||||
|
||||
/**
|
||||
* If set to `true`, the result of the pass is rendered to screen. The last pass in the composers
|
||||
* pass chain gets automatically rendered to screen, no matter how this property is configured.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.renderToScreen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the pass.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} width - The width to set.
|
||||
* @param {number} height - The height to set.
|
||||
*/
|
||||
setSize(/* width, height */) {}
|
||||
|
||||
/**
|
||||
* This method holds the render logic of a pass. It must be implemented in all derived classes.
|
||||
*
|
||||
* @abstract
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||
* destination for the pass.
|
||||
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||
* previous pass from this buffer.
|
||||
* @param {number} deltaTime - The delta time in seconds.
|
||||
* @param {boolean} maskActive - Whether masking is active or not.
|
||||
*/
|
||||
render(/* renderer, writeBuffer, readBuffer, deltaTime, maskActive */) {
|
||||
console.error("THREE.Pass: .render() must be implemented in derived pass.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever the pass is no longer used in your app.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
dispose() {}
|
||||
}
|
||||
|
||||
// Helper for passes that need to fill the viewport with a single quad.
|
||||
|
||||
const _camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
||||
|
||||
// https://github.com/mrdoob/three.js/pull/21358
|
||||
|
||||
class FullscreenTriangleGeometry extends BufferGeometry {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.setAttribute(
|
||||
"position",
|
||||
new Float32BufferAttribute([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3),
|
||||
);
|
||||
this.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2));
|
||||
}
|
||||
}
|
||||
|
||||
const _geometry = new FullscreenTriangleGeometry();
|
||||
|
||||
/**
|
||||
* This module is a helper for passes which need to render a full
|
||||
* screen effect which is quite common in context of post processing.
|
||||
*
|
||||
* The intended usage is to reuse a single full screen quad for rendering
|
||||
* subsequent passes by just reassigning the `material` reference.
|
||||
*
|
||||
* This module can only be used with {@link WebGLRenderer}.
|
||||
*
|
||||
* @augments Mesh
|
||||
* @three_import import { FullScreenQuad } from 'three/addons/postprocessing/Pass.js';
|
||||
*/
|
||||
class FullScreenQuad {
|
||||
/**
|
||||
* Constructs a new full screen quad.
|
||||
*
|
||||
* @param {?Material} material - The material to render te full screen quad with.
|
||||
*/
|
||||
constructor(material) {
|
||||
this._mesh = new Mesh(_geometry, material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever the instance is no longer used in your app.
|
||||
*/
|
||||
dispose() {
|
||||
this._mesh.geometry.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the full screen quad.
|
||||
*
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
*/
|
||||
render(renderer) {
|
||||
renderer.render(this._mesh, _camera);
|
||||
}
|
||||
|
||||
/**
|
||||
* The quad's material.
|
||||
*
|
||||
* @type {?Material}
|
||||
*/
|
||||
get material() {
|
||||
return this._mesh.material;
|
||||
}
|
||||
|
||||
set material(value) {
|
||||
this._mesh.material = value;
|
||||
}
|
||||
}
|
||||
|
||||
export { Pass, FullScreenQuad };
|
||||
179
public/vendor/addons/postprocessing/RenderPass.js
vendored
Normal file
179
public/vendor/addons/postprocessing/RenderPass.js
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
import { Color } from "three";
|
||||
import { Pass } from "./Pass.js";
|
||||
|
||||
/**
|
||||
* This class represents a render pass. It takes a camera and a scene and produces
|
||||
* a beauty pass for subsequent post processing effects.
|
||||
*
|
||||
* ```js
|
||||
* const renderPass = new RenderPass( scene, camera );
|
||||
* composer.addPass( renderPass );
|
||||
* ```
|
||||
*
|
||||
* @augments Pass
|
||||
* @three_import import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
|
||||
*/
|
||||
class RenderPass extends Pass {
|
||||
/**
|
||||
* Constructs a new render pass.
|
||||
*
|
||||
* @param {Scene} scene - The scene to render.
|
||||
* @param {Camera} camera - The camera.
|
||||
* @param {?Material} [overrideMaterial=null] - The override material. If set, this material is used
|
||||
* for all objects in the scene.
|
||||
* @param {?(number|Color|string)} [clearColor=null] - The clear color of the render pass.
|
||||
* @param {?number} [clearAlpha=null] - The clear alpha of the render pass.
|
||||
*/
|
||||
constructor(
|
||||
scene,
|
||||
camera,
|
||||
overrideMaterial = null,
|
||||
clearColor = null,
|
||||
clearAlpha = null,
|
||||
) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The scene to render.
|
||||
*
|
||||
* @type {Scene}
|
||||
*/
|
||||
this.scene = scene;
|
||||
|
||||
/**
|
||||
* The camera.
|
||||
*
|
||||
* @type {Camera}
|
||||
*/
|
||||
this.camera = camera;
|
||||
|
||||
/**
|
||||
* The override material. If set, this material is used
|
||||
* for all objects in the scene.
|
||||
*
|
||||
* @type {?Material}
|
||||
* @default null
|
||||
*/
|
||||
this.overrideMaterial = overrideMaterial;
|
||||
|
||||
/**
|
||||
* The clear color of the render pass.
|
||||
*
|
||||
* @type {?(number|Color|string)}
|
||||
* @default null
|
||||
*/
|
||||
this.clearColor = clearColor;
|
||||
|
||||
/**
|
||||
* The clear alpha of the render pass.
|
||||
*
|
||||
* @type {?number}
|
||||
* @default null
|
||||
*/
|
||||
this.clearAlpha = clearAlpha;
|
||||
|
||||
/**
|
||||
* Overwritten to perform a clear operation by default.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.clear = true;
|
||||
|
||||
/**
|
||||
* If set to `true`, only the depth can be cleared when `clear` is to `false`.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.clearDepth = false;
|
||||
|
||||
/**
|
||||
* Overwritten to disable the swap.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.needsSwap = false;
|
||||
|
||||
/**
|
||||
* This flag indicates that this pass renders the scene itself.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isRenderPass = true;
|
||||
|
||||
this._oldClearColor = new Color();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a beauty pass with the configured scene and camera.
|
||||
*
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||
* destination for the pass.
|
||||
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||
* previous pass from this buffer.
|
||||
* @param {number} deltaTime - The delta time in seconds.
|
||||
* @param {boolean} maskActive - Whether masking is active or not.
|
||||
*/
|
||||
render(renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
|
||||
const oldAutoClear = renderer.autoClear;
|
||||
renderer.autoClear = false;
|
||||
|
||||
let oldClearAlpha, oldOverrideMaterial;
|
||||
|
||||
if (this.overrideMaterial !== null) {
|
||||
oldOverrideMaterial = this.scene.overrideMaterial;
|
||||
|
||||
this.scene.overrideMaterial = this.overrideMaterial;
|
||||
}
|
||||
|
||||
if (this.clearColor !== null) {
|
||||
renderer.getClearColor(this._oldClearColor);
|
||||
renderer.setClearColor(this.clearColor, renderer.getClearAlpha());
|
||||
}
|
||||
|
||||
if (this.clearAlpha !== null) {
|
||||
oldClearAlpha = renderer.getClearAlpha();
|
||||
renderer.setClearAlpha(this.clearAlpha);
|
||||
}
|
||||
|
||||
if (this.clearDepth == true) {
|
||||
renderer.clearDepth();
|
||||
}
|
||||
|
||||
renderer.setRenderTarget(this.renderToScreen ? null : readBuffer);
|
||||
|
||||
if (this.clear === true) {
|
||||
// TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
|
||||
renderer.clear(
|
||||
renderer.autoClearColor,
|
||||
renderer.autoClearDepth,
|
||||
renderer.autoClearStencil,
|
||||
);
|
||||
}
|
||||
|
||||
renderer.render(this.scene, this.camera);
|
||||
|
||||
// restore
|
||||
|
||||
if (this.clearColor !== null) {
|
||||
renderer.setClearColor(this._oldClearColor);
|
||||
}
|
||||
|
||||
if (this.clearAlpha !== null) {
|
||||
renderer.setClearAlpha(oldClearAlpha);
|
||||
}
|
||||
|
||||
if (this.overrideMaterial !== null) {
|
||||
this.scene.overrideMaterial = oldOverrideMaterial;
|
||||
}
|
||||
|
||||
renderer.autoClear = oldAutoClear;
|
||||
}
|
||||
}
|
||||
|
||||
export { RenderPass };
|
||||
117
public/vendor/addons/postprocessing/ShaderPass.js
vendored
Normal file
117
public/vendor/addons/postprocessing/ShaderPass.js
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
import { ShaderMaterial, UniformsUtils } from "three";
|
||||
import { Pass, FullScreenQuad } from "./Pass.js";
|
||||
|
||||
/**
|
||||
* This pass can be used to create a post processing effect
|
||||
* with a raw GLSL shader object. Useful for implementing custom
|
||||
* effects.
|
||||
*
|
||||
* ```js
|
||||
* const fxaaPass = new ShaderPass( FXAAShader );
|
||||
* composer.addPass( fxaaPass );
|
||||
* ```
|
||||
*
|
||||
* @augments Pass
|
||||
* @three_import import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
||||
*/
|
||||
class ShaderPass extends Pass {
|
||||
/**
|
||||
* Constructs a new shader pass.
|
||||
*
|
||||
* @param {Object|ShaderMaterial} [shader] - A shader object holding vertex and fragment shader as well as
|
||||
* defines and uniforms. It's also valid to pass a custom shader material.
|
||||
* @param {string} [textureID='tDiffuse'] - The name of the texture uniform that should sample
|
||||
* the read buffer.
|
||||
*/
|
||||
constructor(shader, textureID = "tDiffuse") {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The name of the texture uniform that should sample the read buffer.
|
||||
*
|
||||
* @type {string}
|
||||
* @default 'tDiffuse'
|
||||
*/
|
||||
this.textureID = textureID;
|
||||
|
||||
/**
|
||||
* The pass uniforms.
|
||||
*
|
||||
* @type {?Object}
|
||||
*/
|
||||
this.uniforms = null;
|
||||
|
||||
/**
|
||||
* The pass material.
|
||||
*
|
||||
* @type {?ShaderMaterial}
|
||||
*/
|
||||
this.material = null;
|
||||
|
||||
if (shader instanceof ShaderMaterial) {
|
||||
this.uniforms = shader.uniforms;
|
||||
|
||||
this.material = shader;
|
||||
} else if (shader) {
|
||||
this.uniforms = UniformsUtils.clone(shader.uniforms);
|
||||
|
||||
this.material = new ShaderMaterial({
|
||||
name: shader.name !== undefined ? shader.name : "unspecified",
|
||||
defines: Object.assign({}, shader.defines),
|
||||
uniforms: this.uniforms,
|
||||
vertexShader: shader.vertexShader,
|
||||
fragmentShader: shader.fragmentShader,
|
||||
});
|
||||
}
|
||||
|
||||
// internals
|
||||
|
||||
this._fsQuad = new FullScreenQuad(this.material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the shader pass.
|
||||
*
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||
* destination for the pass.
|
||||
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||
* previous pass from this buffer.
|
||||
* @param {number} deltaTime - The delta time in seconds.
|
||||
* @param {boolean} maskActive - Whether masking is active or not.
|
||||
*/
|
||||
render(renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
|
||||
if (this.uniforms[this.textureID]) {
|
||||
this.uniforms[this.textureID].value = readBuffer.texture;
|
||||
}
|
||||
|
||||
this._fsQuad.material = this.material;
|
||||
|
||||
if (this.renderToScreen) {
|
||||
renderer.setRenderTarget(null);
|
||||
this._fsQuad.render(renderer);
|
||||
} else {
|
||||
renderer.setRenderTarget(writeBuffer);
|
||||
// TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
|
||||
if (this.clear)
|
||||
renderer.clear(
|
||||
renderer.autoClearColor,
|
||||
renderer.autoClearDepth,
|
||||
renderer.autoClearStencil,
|
||||
);
|
||||
this._fsQuad.render(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever the pass is no longer used in your app.
|
||||
*/
|
||||
dispose() {
|
||||
this.material.dispose();
|
||||
|
||||
this._fsQuad.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
export { ShaderPass };
|
||||
541
public/vendor/addons/postprocessing/UnrealBloomPass.js
vendored
Normal file
541
public/vendor/addons/postprocessing/UnrealBloomPass.js
vendored
Normal file
|
|
@ -0,0 +1,541 @@
|
|||
import {
|
||||
AdditiveBlending,
|
||||
Color,
|
||||
HalfFloatType,
|
||||
MeshBasicMaterial,
|
||||
ShaderMaterial,
|
||||
UniformsUtils,
|
||||
Vector2,
|
||||
Vector3,
|
||||
WebGLRenderTarget,
|
||||
} from "three";
|
||||
import { Pass, FullScreenQuad } from "./Pass.js";
|
||||
import { CopyShader } from "../shaders/CopyShader.js";
|
||||
import { LuminosityHighPassShader } from "../shaders/LuminosityHighPassShader.js";
|
||||
|
||||
/**
|
||||
* This pass is inspired by the bloom pass of Unreal Engine. It creates a
|
||||
* mip map chain of bloom textures and blurs them with different radii. Because
|
||||
* of the weighted combination of mips, and because larger blurs are done on
|
||||
* higher mips, this effect provides good quality and performance.
|
||||
*
|
||||
* When using this pass, tone mapping must be enabled in the renderer settings.
|
||||
*
|
||||
* Reference:
|
||||
* - [Bloom in Unreal Engine](https://docs.unrealengine.com/latest/INT/Engine/Rendering/PostProcessEffects/Bloom/)
|
||||
*
|
||||
* ```js
|
||||
* const resolution = new THREE.Vector2( window.innerWidth, window.innerHeight );
|
||||
* const bloomPass = new UnrealBloomPass( resolution, 1.5, 0.4, 0.85 );
|
||||
* composer.addPass( bloomPass );
|
||||
* ```
|
||||
*
|
||||
* @augments Pass
|
||||
* @three_import import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
|
||||
*/
|
||||
class UnrealBloomPass extends Pass {
|
||||
/**
|
||||
* Constructs a new Unreal Bloom pass.
|
||||
*
|
||||
* @param {Vector2} [resolution] - The effect's resolution.
|
||||
* @param {number} [strength=1] - The Bloom strength.
|
||||
* @param {number} radius - The Bloom radius.
|
||||
* @param {number} threshold - The luminance threshold limits which bright areas contribute to the Bloom effect.
|
||||
*/
|
||||
constructor(resolution, strength = 1, radius, threshold) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The Bloom strength.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.strength = strength;
|
||||
|
||||
/**
|
||||
* The Bloom radius. Must be in the range `[0,1]`.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.radius = radius;
|
||||
|
||||
/**
|
||||
* The luminance threshold limits which bright areas contribute to the Bloom effect.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.threshold = threshold;
|
||||
|
||||
/**
|
||||
* The effect's resolution.
|
||||
*
|
||||
* @type {Vector2}
|
||||
* @default (256,256)
|
||||
*/
|
||||
this.resolution =
|
||||
resolution !== undefined
|
||||
? new Vector2(resolution.x, resolution.y)
|
||||
: new Vector2(256, 256);
|
||||
|
||||
/**
|
||||
* The effect's clear color
|
||||
*
|
||||
* @type {Color}
|
||||
* @default (0,0,0)
|
||||
*/
|
||||
this.clearColor = new Color(0, 0, 0);
|
||||
|
||||
/**
|
||||
* Overwritten to disable the swap.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.needsSwap = false;
|
||||
|
||||
// internals
|
||||
|
||||
// render targets
|
||||
this.renderTargetsHorizontal = [];
|
||||
this.renderTargetsVertical = [];
|
||||
this.nMips = 5;
|
||||
let resx = Math.round(this.resolution.x / 2);
|
||||
let resy = Math.round(this.resolution.y / 2);
|
||||
|
||||
this.renderTargetBright = new WebGLRenderTarget(resx, resy, {
|
||||
type: HalfFloatType,
|
||||
depthBuffer: false,
|
||||
});
|
||||
this.renderTargetBright.texture.name = "UnrealBloomPass.bright";
|
||||
this.renderTargetBright.texture.generateMipmaps = false;
|
||||
|
||||
for (let i = 0; i < this.nMips; i++) {
|
||||
const renderTargetHorizontal = new WebGLRenderTarget(resx, resy, {
|
||||
type: HalfFloatType,
|
||||
depthBuffer: false,
|
||||
});
|
||||
|
||||
renderTargetHorizontal.texture.name = "UnrealBloomPass.h" + i;
|
||||
renderTargetHorizontal.texture.generateMipmaps = false;
|
||||
|
||||
this.renderTargetsHorizontal.push(renderTargetHorizontal);
|
||||
|
||||
const renderTargetVertical = new WebGLRenderTarget(resx, resy, {
|
||||
type: HalfFloatType,
|
||||
depthBuffer: false,
|
||||
});
|
||||
|
||||
renderTargetVertical.texture.name = "UnrealBloomPass.v" + i;
|
||||
renderTargetVertical.texture.generateMipmaps = false;
|
||||
|
||||
this.renderTargetsVertical.push(renderTargetVertical);
|
||||
|
||||
resx = Math.round(resx / 2);
|
||||
|
||||
resy = Math.round(resy / 2);
|
||||
}
|
||||
|
||||
// luminosity high pass material
|
||||
|
||||
const highPassShader = LuminosityHighPassShader;
|
||||
this.highPassUniforms = UniformsUtils.clone(highPassShader.uniforms);
|
||||
|
||||
this.highPassUniforms["luminosityThreshold"].value = threshold;
|
||||
this.highPassUniforms["smoothWidth"].value = 0.01;
|
||||
|
||||
this.materialHighPassFilter = new ShaderMaterial({
|
||||
uniforms: this.highPassUniforms,
|
||||
vertexShader: highPassShader.vertexShader,
|
||||
fragmentShader: highPassShader.fragmentShader,
|
||||
});
|
||||
|
||||
// gaussian blur materials
|
||||
|
||||
this.separableBlurMaterials = [];
|
||||
// These sizes have been changed to account for the altered coefficients-calculation to avoid blockiness,
|
||||
// while retaining the same blur-strength. For details see https://github.com/mrdoob/three.js/pull/31528
|
||||
const kernelSizeArray = [6, 10, 14, 18, 22];
|
||||
resx = Math.round(this.resolution.x / 2);
|
||||
resy = Math.round(this.resolution.y / 2);
|
||||
|
||||
for (let i = 0; i < this.nMips; i++) {
|
||||
this.separableBlurMaterials.push(
|
||||
this._getSeparableBlurMaterial(kernelSizeArray[i]),
|
||||
);
|
||||
|
||||
this.separableBlurMaterials[i].uniforms["invSize"].value = new Vector2(
|
||||
1 / resx,
|
||||
1 / resy,
|
||||
);
|
||||
|
||||
resx = Math.round(resx / 2);
|
||||
|
||||
resy = Math.round(resy / 2);
|
||||
}
|
||||
|
||||
// composite material
|
||||
|
||||
this.compositeMaterial = this._getCompositeMaterial(this.nMips);
|
||||
this.compositeMaterial.uniforms["blurTexture1"].value =
|
||||
this.renderTargetsVertical[0].texture;
|
||||
this.compositeMaterial.uniforms["blurTexture2"].value =
|
||||
this.renderTargetsVertical[1].texture;
|
||||
this.compositeMaterial.uniforms["blurTexture3"].value =
|
||||
this.renderTargetsVertical[2].texture;
|
||||
this.compositeMaterial.uniforms["blurTexture4"].value =
|
||||
this.renderTargetsVertical[3].texture;
|
||||
this.compositeMaterial.uniforms["blurTexture5"].value =
|
||||
this.renderTargetsVertical[4].texture;
|
||||
this.compositeMaterial.uniforms["bloomStrength"].value = strength;
|
||||
this.compositeMaterial.uniforms["bloomRadius"].value = 0.1;
|
||||
|
||||
const bloomFactors = [1.0, 0.8, 0.6, 0.4, 0.2];
|
||||
this.compositeMaterial.uniforms["bloomFactors"].value = bloomFactors;
|
||||
this.bloomTintColors = [
|
||||
new Vector3(1, 1, 1),
|
||||
new Vector3(1, 1, 1),
|
||||
new Vector3(1, 1, 1),
|
||||
new Vector3(1, 1, 1),
|
||||
new Vector3(1, 1, 1),
|
||||
];
|
||||
this.compositeMaterial.uniforms["bloomTintColors"].value =
|
||||
this.bloomTintColors;
|
||||
|
||||
// blend material
|
||||
|
||||
this.copyUniforms = UniformsUtils.clone(CopyShader.uniforms);
|
||||
|
||||
this.blendMaterial = new ShaderMaterial({
|
||||
uniforms: this.copyUniforms,
|
||||
vertexShader: CopyShader.vertexShader,
|
||||
fragmentShader: CopyShader.fragmentShader,
|
||||
premultipliedAlpha: true,
|
||||
blending: AdditiveBlending,
|
||||
depthTest: false,
|
||||
depthWrite: false,
|
||||
transparent: true,
|
||||
});
|
||||
|
||||
this._oldClearColor = new Color();
|
||||
this._oldClearAlpha = 1;
|
||||
|
||||
this._basic = new MeshBasicMaterial();
|
||||
|
||||
this._fsQuad = new FullScreenQuad(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever the pass is no longer used in your app.
|
||||
*/
|
||||
dispose() {
|
||||
for (let i = 0; i < this.renderTargetsHorizontal.length; i++) {
|
||||
this.renderTargetsHorizontal[i].dispose();
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.renderTargetsVertical.length; i++) {
|
||||
this.renderTargetsVertical[i].dispose();
|
||||
}
|
||||
|
||||
this.renderTargetBright.dispose();
|
||||
|
||||
//
|
||||
|
||||
for (let i = 0; i < this.separableBlurMaterials.length; i++) {
|
||||
this.separableBlurMaterials[i].dispose();
|
||||
}
|
||||
|
||||
this.compositeMaterial.dispose();
|
||||
this.blendMaterial.dispose();
|
||||
this._basic.dispose();
|
||||
|
||||
//
|
||||
|
||||
this._fsQuad.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the pass.
|
||||
*
|
||||
* @param {number} width - The width to set.
|
||||
* @param {number} height - The height to set.
|
||||
*/
|
||||
setSize(width, height) {
|
||||
let resx = Math.round(width / 2);
|
||||
let resy = Math.round(height / 2);
|
||||
|
||||
this.renderTargetBright.setSize(resx, resy);
|
||||
|
||||
for (let i = 0; i < this.nMips; i++) {
|
||||
this.renderTargetsHorizontal[i].setSize(resx, resy);
|
||||
this.renderTargetsVertical[i].setSize(resx, resy);
|
||||
|
||||
this.separableBlurMaterials[i].uniforms["invSize"].value = new Vector2(
|
||||
1 / resx,
|
||||
1 / resy,
|
||||
);
|
||||
|
||||
resx = Math.round(resx / 2);
|
||||
resy = Math.round(resy / 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the Bloom pass.
|
||||
*
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||
* destination for the pass.
|
||||
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||
* previous pass from this buffer.
|
||||
* @param {number} deltaTime - The delta time in seconds.
|
||||
* @param {boolean} maskActive - Whether masking is active or not.
|
||||
*/
|
||||
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
||||
renderer.getClearColor(this._oldClearColor);
|
||||
this._oldClearAlpha = renderer.getClearAlpha();
|
||||
const oldAutoClear = renderer.autoClear;
|
||||
renderer.autoClear = false;
|
||||
|
||||
renderer.setClearColor(this.clearColor, 0);
|
||||
|
||||
if (maskActive) renderer.state.buffers.stencil.setTest(false);
|
||||
|
||||
// Render input to screen
|
||||
|
||||
if (this.renderToScreen) {
|
||||
this._fsQuad.material = this._basic;
|
||||
this._basic.map = readBuffer.texture;
|
||||
|
||||
renderer.setRenderTarget(null);
|
||||
renderer.clear();
|
||||
this._fsQuad.render(renderer);
|
||||
}
|
||||
|
||||
// 1. Extract Bright Areas
|
||||
|
||||
this.highPassUniforms["tDiffuse"].value = readBuffer.texture;
|
||||
this.highPassUniforms["luminosityThreshold"].value = this.threshold;
|
||||
this._fsQuad.material = this.materialHighPassFilter;
|
||||
|
||||
renderer.setRenderTarget(this.renderTargetBright);
|
||||
renderer.clear();
|
||||
this._fsQuad.render(renderer);
|
||||
|
||||
// 2. Blur All the mips progressively
|
||||
|
||||
let inputRenderTarget = this.renderTargetBright;
|
||||
|
||||
for (let i = 0; i < this.nMips; i++) {
|
||||
this._fsQuad.material = this.separableBlurMaterials[i];
|
||||
|
||||
this.separableBlurMaterials[i].uniforms["colorTexture"].value =
|
||||
inputRenderTarget.texture;
|
||||
this.separableBlurMaterials[i].uniforms["direction"].value =
|
||||
UnrealBloomPass.BlurDirectionX;
|
||||
renderer.setRenderTarget(this.renderTargetsHorizontal[i]);
|
||||
renderer.clear();
|
||||
this._fsQuad.render(renderer);
|
||||
|
||||
this.separableBlurMaterials[i].uniforms["colorTexture"].value =
|
||||
this.renderTargetsHorizontal[i].texture;
|
||||
this.separableBlurMaterials[i].uniforms["direction"].value =
|
||||
UnrealBloomPass.BlurDirectionY;
|
||||
renderer.setRenderTarget(this.renderTargetsVertical[i]);
|
||||
renderer.clear();
|
||||
this._fsQuad.render(renderer);
|
||||
|
||||
inputRenderTarget = this.renderTargetsVertical[i];
|
||||
}
|
||||
|
||||
// Composite All the mips
|
||||
|
||||
this._fsQuad.material = this.compositeMaterial;
|
||||
this.compositeMaterial.uniforms["bloomStrength"].value = this.strength;
|
||||
this.compositeMaterial.uniforms["bloomRadius"].value = this.radius;
|
||||
this.compositeMaterial.uniforms["bloomTintColors"].value =
|
||||
this.bloomTintColors;
|
||||
|
||||
renderer.setRenderTarget(this.renderTargetsHorizontal[0]);
|
||||
renderer.clear();
|
||||
this._fsQuad.render(renderer);
|
||||
|
||||
// Blend it additively over the input texture
|
||||
|
||||
this._fsQuad.material = this.blendMaterial;
|
||||
this.copyUniforms["tDiffuse"].value =
|
||||
this.renderTargetsHorizontal[0].texture;
|
||||
|
||||
if (maskActive) renderer.state.buffers.stencil.setTest(true);
|
||||
|
||||
if (this.renderToScreen) {
|
||||
renderer.setRenderTarget(null);
|
||||
this._fsQuad.render(renderer);
|
||||
} else {
|
||||
renderer.setRenderTarget(readBuffer);
|
||||
this._fsQuad.render(renderer);
|
||||
}
|
||||
|
||||
// Restore renderer settings
|
||||
|
||||
renderer.setClearColor(this._oldClearColor, this._oldClearAlpha);
|
||||
renderer.autoClear = oldAutoClear;
|
||||
}
|
||||
|
||||
// internals
|
||||
|
||||
_getSeparableBlurMaterial(kernelRadius) {
|
||||
const coefficients = [];
|
||||
const sigma = kernelRadius / 3;
|
||||
|
||||
for (let i = 0; i < kernelRadius; i++) {
|
||||
coefficients.push(
|
||||
(0.39894 * Math.exp((-0.5 * i * i) / (sigma * sigma))) / sigma,
|
||||
);
|
||||
}
|
||||
|
||||
// merge adjacent taps into single bilinear fetches (linear sampling)
|
||||
|
||||
const offsets = [];
|
||||
const weights = [];
|
||||
|
||||
for (let i = 1; i < kernelRadius; i += 2) {
|
||||
const wa = coefficients[i];
|
||||
const wb = i + 1 < kernelRadius ? coefficients[i + 1] : 0;
|
||||
const w = wa + wb;
|
||||
|
||||
offsets.push((i * wa + (i + 1) * wb) / w);
|
||||
weights.push(w);
|
||||
}
|
||||
|
||||
return new ShaderMaterial({
|
||||
defines: {
|
||||
KERNEL_PAIRS: offsets.length,
|
||||
},
|
||||
|
||||
uniforms: {
|
||||
colorTexture: { value: null },
|
||||
invSize: { value: new Vector2(0.5, 0.5) }, // inverse texture size
|
||||
direction: { value: new Vector2(0.5, 0.5) },
|
||||
centerWeight: { value: coefficients[0] },
|
||||
gaussianOffsets: { value: offsets },
|
||||
gaussianWeights: { value: weights },
|
||||
},
|
||||
|
||||
vertexShader: /* glsl */ `
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
|
||||
vUv = uv;
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||
|
||||
}`,
|
||||
|
||||
fragmentShader: /* glsl */ `
|
||||
|
||||
#include <common>
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
uniform sampler2D colorTexture;
|
||||
uniform vec2 invSize;
|
||||
uniform vec2 direction;
|
||||
uniform float centerWeight;
|
||||
uniform float gaussianOffsets[KERNEL_PAIRS];
|
||||
uniform float gaussianWeights[KERNEL_PAIRS];
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 diffuseSum = texture2D( colorTexture, vUv ).rgb * centerWeight;
|
||||
|
||||
for ( int i = 0; i < KERNEL_PAIRS; i ++ ) {
|
||||
|
||||
vec2 uvOffset = direction * invSize * gaussianOffsets[ i ];
|
||||
vec3 sample1 = texture2D( colorTexture, vUv + uvOffset ).rgb;
|
||||
vec3 sample2 = texture2D( colorTexture, vUv - uvOffset ).rgb;
|
||||
diffuseSum += ( sample1 + sample2 ) * gaussianWeights[ i ];
|
||||
|
||||
}
|
||||
|
||||
gl_FragColor = vec4( diffuseSum, 1.0 );
|
||||
|
||||
}`,
|
||||
});
|
||||
}
|
||||
|
||||
_getCompositeMaterial(nMips) {
|
||||
return new ShaderMaterial({
|
||||
defines: {
|
||||
NUM_MIPS: nMips,
|
||||
},
|
||||
|
||||
uniforms: {
|
||||
blurTexture1: { value: null },
|
||||
blurTexture2: { value: null },
|
||||
blurTexture3: { value: null },
|
||||
blurTexture4: { value: null },
|
||||
blurTexture5: { value: null },
|
||||
bloomStrength: { value: 1.0 },
|
||||
bloomFactors: { value: null },
|
||||
bloomTintColors: { value: null },
|
||||
bloomRadius: { value: 0.0 },
|
||||
},
|
||||
|
||||
vertexShader: /* glsl */ `
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
|
||||
vUv = uv;
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||
|
||||
}`,
|
||||
|
||||
fragmentShader: /* glsl */ `
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
uniform sampler2D blurTexture1;
|
||||
uniform sampler2D blurTexture2;
|
||||
uniform sampler2D blurTexture3;
|
||||
uniform sampler2D blurTexture4;
|
||||
uniform sampler2D blurTexture5;
|
||||
uniform float bloomStrength;
|
||||
uniform float bloomRadius;
|
||||
uniform float bloomFactors[NUM_MIPS];
|
||||
uniform vec3 bloomTintColors[NUM_MIPS];
|
||||
|
||||
float lerpBloomFactor( const in float factor ) {
|
||||
|
||||
float mirrorFactor = 1.2 - factor;
|
||||
return mix( factor, mirrorFactor, bloomRadius );
|
||||
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
// 3.0 for backwards compatibility with previous alpha-based intensity
|
||||
vec3 bloom = 3.0 * bloomStrength * (
|
||||
lerpBloomFactor( bloomFactors[ 0 ] ) * bloomTintColors[ 0 ] * texture2D( blurTexture1, vUv ).rgb +
|
||||
lerpBloomFactor( bloomFactors[ 1 ] ) * bloomTintColors[ 1 ] * texture2D( blurTexture2, vUv ).rgb +
|
||||
lerpBloomFactor( bloomFactors[ 2 ] ) * bloomTintColors[ 2 ] * texture2D( blurTexture3, vUv ).rgb +
|
||||
lerpBloomFactor( bloomFactors[ 3 ] ) * bloomTintColors[ 3 ] * texture2D( blurTexture4, vUv ).rgb +
|
||||
lerpBloomFactor( bloomFactors[ 4 ] ) * bloomTintColors[ 4 ] * texture2D( blurTexture5, vUv ).rgb
|
||||
);
|
||||
|
||||
float bloomAlpha = max( bloom.r, max( bloom.g, bloom.b ) );
|
||||
gl_FragColor = vec4( bloom, bloomAlpha );
|
||||
|
||||
}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
UnrealBloomPass.BlurDirectionX = new Vector2(1.0, 0.0);
|
||||
UnrealBloomPass.BlurDirectionY = new Vector2(0.0, 1.0);
|
||||
|
||||
export { UnrealBloomPass };
|
||||
48
public/vendor/addons/shaders/CopyShader.js
vendored
Normal file
48
public/vendor/addons/shaders/CopyShader.js
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* @module CopyShader
|
||||
* @three_import import { CopyShader } from 'three/addons/shaders/CopyShader.js';
|
||||
*/
|
||||
|
||||
/**
|
||||
* Full-screen copy shader pass.
|
||||
*
|
||||
* @constant
|
||||
* @type {ShaderMaterial~Shader}
|
||||
*/
|
||||
const CopyShader = {
|
||||
name: "CopyShader",
|
||||
|
||||
uniforms: {
|
||||
tDiffuse: { value: null },
|
||||
opacity: { value: 1.0 },
|
||||
},
|
||||
|
||||
vertexShader: /* glsl */ `
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
|
||||
vUv = uv;
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||
|
||||
}`,
|
||||
|
||||
fragmentShader: /* glsl */ `
|
||||
|
||||
uniform float opacity;
|
||||
|
||||
uniform sampler2D tDiffuse;
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
|
||||
vec4 texel = texture2D( tDiffuse, vUv );
|
||||
gl_FragColor = opacity * texel;
|
||||
|
||||
|
||||
}`,
|
||||
};
|
||||
|
||||
export { CopyShader };
|
||||
62
public/vendor/addons/shaders/LuminosityHighPassShader.js
vendored
Normal file
62
public/vendor/addons/shaders/LuminosityHighPassShader.js
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { Color } from "three";
|
||||
|
||||
/**
|
||||
* @module LuminosityHighPassShader
|
||||
* @three_import import { LuminosityHighPassShader } from 'three/addons/shaders/LuminosityHighPassShader.js';
|
||||
*/
|
||||
|
||||
/**
|
||||
* Luminosity high pass shader.
|
||||
*
|
||||
* @constant
|
||||
* @type {ShaderMaterial~Shader}
|
||||
*/
|
||||
const LuminosityHighPassShader = {
|
||||
name: "LuminosityHighPassShader",
|
||||
|
||||
uniforms: {
|
||||
tDiffuse: { value: null },
|
||||
luminosityThreshold: { value: 1.0 },
|
||||
smoothWidth: { value: 1.0 },
|
||||
defaultColor: { value: new Color(0x000000) },
|
||||
defaultOpacity: { value: 0.0 },
|
||||
},
|
||||
|
||||
vertexShader: /* glsl */ `
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
|
||||
vUv = uv;
|
||||
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||
|
||||
}`,
|
||||
|
||||
fragmentShader: /* glsl */ `
|
||||
|
||||
uniform sampler2D tDiffuse;
|
||||
uniform vec3 defaultColor;
|
||||
uniform float defaultOpacity;
|
||||
uniform float luminosityThreshold;
|
||||
uniform float smoothWidth;
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
|
||||
vec4 texel = texture2D( tDiffuse, vUv );
|
||||
|
||||
float v = luminance( texel.xyz );
|
||||
|
||||
vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );
|
||||
|
||||
float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );
|
||||
|
||||
gl_FragColor = mix( outputColor, texel, alpha );
|
||||
|
||||
}`,
|
||||
};
|
||||
|
||||
export { LuminosityHighPassShader };
|
||||
99
public/vendor/addons/shaders/OutputShader.js
vendored
Normal file
99
public/vendor/addons/shaders/OutputShader.js
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/**
|
||||
* @module OutputShader
|
||||
* @three_import import { OutputShader } from 'three/addons/shaders/OutputShader.js';
|
||||
*/
|
||||
|
||||
/**
|
||||
* Performs tone mapping and color space conversion for
|
||||
* FX workflows.
|
||||
*
|
||||
* Used by {@link OutputPass}.
|
||||
*
|
||||
* @constant
|
||||
* @type {ShaderMaterial~Shader}
|
||||
*/
|
||||
const OutputShader = {
|
||||
name: "OutputShader",
|
||||
|
||||
uniforms: {
|
||||
tDiffuse: { value: null },
|
||||
toneMappingExposure: { value: 1 },
|
||||
},
|
||||
|
||||
vertexShader: /* glsl */ `
|
||||
precision highp float;
|
||||
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
attribute vec3 position;
|
||||
attribute vec2 uv;
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
|
||||
vUv = uv;
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||
|
||||
}`,
|
||||
|
||||
fragmentShader: /* glsl */ `
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform sampler2D tDiffuse;
|
||||
|
||||
#include <tonemapping_pars_fragment>
|
||||
#include <colorspace_pars_fragment>
|
||||
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_FragColor = texture2D( tDiffuse, vUv );
|
||||
|
||||
// tone mapping
|
||||
|
||||
#ifdef LINEAR_TONE_MAPPING
|
||||
|
||||
gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
|
||||
|
||||
#elif defined( REINHARD_TONE_MAPPING )
|
||||
|
||||
gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
|
||||
|
||||
#elif defined( CINEON_TONE_MAPPING )
|
||||
|
||||
gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );
|
||||
|
||||
#elif defined( ACES_FILMIC_TONE_MAPPING )
|
||||
|
||||
gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
|
||||
|
||||
#elif defined( AGX_TONE_MAPPING )
|
||||
|
||||
gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
|
||||
|
||||
#elif defined( NEUTRAL_TONE_MAPPING )
|
||||
|
||||
gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
|
||||
|
||||
#elif defined( CUSTOM_TONE_MAPPING )
|
||||
|
||||
gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
|
||||
|
||||
#endif
|
||||
|
||||
// color space
|
||||
|
||||
#ifdef SRGB_TRANSFER
|
||||
|
||||
gl_FragColor = sRGBTransferOETF( gl_FragColor );
|
||||
|
||||
#endif
|
||||
|
||||
}`,
|
||||
};
|
||||
|
||||
export { OutputShader };
|
||||
1413
public/vendor/addons/utils/BufferGeometryUtils.js
vendored
Normal file
1413
public/vendor/addons/utils/BufferGeometryUtils.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
411
public/vendor/addons/utils/SkeletonUtils.js
vendored
Normal file
411
public/vendor/addons/utils/SkeletonUtils.js
vendored
Normal file
|
|
@ -0,0 +1,411 @@
|
|||
import {
|
||||
AnimationClip,
|
||||
AnimationMixer,
|
||||
Matrix4,
|
||||
Quaternion,
|
||||
QuaternionKeyframeTrack,
|
||||
SkeletonHelper,
|
||||
Vector3,
|
||||
VectorKeyframeTrack,
|
||||
} from "three";
|
||||
|
||||
/**
|
||||
* @module SkeletonUtils
|
||||
* @three_import import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js';
|
||||
*/
|
||||
|
||||
function getBoneName(bone, options) {
|
||||
if (options.getBoneName !== undefined) {
|
||||
return options.getBoneName(bone);
|
||||
}
|
||||
|
||||
return options.names[bone.name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retargets the skeleton from the given source to the target.
|
||||
*
|
||||
* Both `target` and `source` can be a 3D object with a skeleton property (e.g. a skinned mesh)
|
||||
* or a {@link Skeleton} directly.
|
||||
*
|
||||
* @param {Object3D|Skeleton} target - The target object.
|
||||
* @param {Object3D|Skeleton} source - The source object.
|
||||
* @param {module:SkeletonUtils~RetargetOptions} options - The options.
|
||||
*/
|
||||
function retarget(target, source, options = {}) {
|
||||
const quat = new Quaternion(),
|
||||
scale = new Vector3(),
|
||||
relativeMatrix = new Matrix4(),
|
||||
globalMatrix = new Matrix4();
|
||||
|
||||
options.preserveBoneMatrix =
|
||||
options.preserveBoneMatrix !== undefined
|
||||
? options.preserveBoneMatrix
|
||||
: true;
|
||||
options.preserveBonePositions =
|
||||
options.preserveBonePositions !== undefined
|
||||
? options.preserveBonePositions
|
||||
: true;
|
||||
options.useTargetMatrix =
|
||||
options.useTargetMatrix !== undefined ? options.useTargetMatrix : false;
|
||||
options.hip = options.hip !== undefined ? options.hip : "hip";
|
||||
options.hipInfluence =
|
||||
options.hipInfluence !== undefined
|
||||
? options.hipInfluence
|
||||
: new Vector3(1, 1, 1);
|
||||
options.scale = options.scale !== undefined ? options.scale : 1;
|
||||
options.names = options.names || {};
|
||||
|
||||
const sourceBones = source.isObject3D
|
||||
? source.skeleton.bones
|
||||
: getBones(source),
|
||||
bones = target.isObject3D ? target.skeleton.bones : getBones(target);
|
||||
|
||||
let bone, name, boneTo, bonesPosition;
|
||||
|
||||
// reset bones
|
||||
|
||||
if (target.isObject3D) {
|
||||
target.skeleton.pose();
|
||||
} else {
|
||||
options.useTargetMatrix = true;
|
||||
options.preserveBoneMatrix = false;
|
||||
}
|
||||
|
||||
if (options.preserveBonePositions) {
|
||||
bonesPosition = [];
|
||||
|
||||
for (let i = 0; i < bones.length; i++) {
|
||||
bonesPosition.push(bones[i].position.clone());
|
||||
}
|
||||
}
|
||||
|
||||
if (options.preserveBoneMatrix) {
|
||||
// reset matrix
|
||||
|
||||
target.updateMatrixWorld();
|
||||
|
||||
target.matrixWorld.identity();
|
||||
|
||||
// reset children matrix
|
||||
|
||||
for (let i = 0; i < target.children.length; ++i) {
|
||||
target.children[i].updateMatrixWorld(true);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < bones.length; ++i) {
|
||||
bone = bones[i];
|
||||
name = getBoneName(bone, options);
|
||||
|
||||
boneTo = getBoneByName(name, sourceBones);
|
||||
|
||||
globalMatrix.copy(bone.matrixWorld);
|
||||
|
||||
if (boneTo) {
|
||||
boneTo.updateMatrixWorld();
|
||||
|
||||
if (options.useTargetMatrix) {
|
||||
relativeMatrix.copy(boneTo.matrixWorld);
|
||||
} else {
|
||||
relativeMatrix.copy(target.matrixWorld).invert();
|
||||
relativeMatrix.multiply(boneTo.matrixWorld);
|
||||
}
|
||||
|
||||
// ignore scale to extract rotation
|
||||
|
||||
scale.setFromMatrixScale(relativeMatrix);
|
||||
relativeMatrix.scale(scale.set(1 / scale.x, 1 / scale.y, 1 / scale.z));
|
||||
|
||||
// apply to global matrix
|
||||
|
||||
globalMatrix.makeRotationFromQuaternion(
|
||||
quat.setFromRotationMatrix(relativeMatrix),
|
||||
);
|
||||
|
||||
if (target.isObject3D) {
|
||||
if (options.localOffsets) {
|
||||
if (options.localOffsets[bone.name]) {
|
||||
globalMatrix.multiply(options.localOffsets[bone.name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
globalMatrix.copyPosition(relativeMatrix);
|
||||
}
|
||||
|
||||
if (name === options.hip) {
|
||||
globalMatrix.elements[12] *= options.scale * options.hipInfluence.x;
|
||||
globalMatrix.elements[13] *= options.scale * options.hipInfluence.y;
|
||||
globalMatrix.elements[14] *= options.scale * options.hipInfluence.z;
|
||||
|
||||
if (options.hipPosition !== undefined) {
|
||||
globalMatrix.elements[12] += options.hipPosition.x * options.scale;
|
||||
globalMatrix.elements[13] += options.hipPosition.y * options.scale;
|
||||
globalMatrix.elements[14] += options.hipPosition.z * options.scale;
|
||||
}
|
||||
}
|
||||
|
||||
if (bone.parent) {
|
||||
bone.matrix.copy(bone.parent.matrixWorld).invert();
|
||||
bone.matrix.multiply(globalMatrix);
|
||||
} else {
|
||||
bone.matrix.copy(globalMatrix);
|
||||
}
|
||||
|
||||
bone.matrix.decompose(bone.position, bone.quaternion, bone.scale);
|
||||
|
||||
bone.updateMatrixWorld();
|
||||
}
|
||||
|
||||
if (options.preserveBonePositions) {
|
||||
for (let i = 0; i < bones.length; ++i) {
|
||||
bone = bones[i];
|
||||
name = getBoneName(bone, options) || bone.name;
|
||||
|
||||
if (name !== options.hip) {
|
||||
bone.position.copy(bonesPosition[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.preserveBoneMatrix) {
|
||||
// restore matrix
|
||||
|
||||
target.updateMatrixWorld(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retargets the animation clip of the source to the target 3D object.
|
||||
*
|
||||
* The `source` can be a 3D object with a skeleton property (e.g. a skinned mesh)
|
||||
* or a {@link Skeleton} directly.
|
||||
*
|
||||
* @param {Object3D} target - The target 3D object. Must have a `skeleton` property.
|
||||
* @param {Object3D|Skeleton} source - The source object.
|
||||
* @param {AnimationClip} clip - The animation clip.
|
||||
* @param {module:SkeletonUtils~RetargetOptions} options - The options.
|
||||
* @return {AnimationClip} The retargeted animation clip.
|
||||
*/
|
||||
function retargetClip(target, source, clip, options = {}) {
|
||||
options.useFirstFramePosition =
|
||||
options.useFirstFramePosition !== undefined
|
||||
? options.useFirstFramePosition
|
||||
: false;
|
||||
|
||||
// Calculate the fps from the source clip based on the track with the most frames, unless fps is already provided.
|
||||
options.fps =
|
||||
options.fps !== undefined
|
||||
? options.fps
|
||||
: Math.max(...clip.tracks.map((track) => track.times.length)) /
|
||||
clip.duration;
|
||||
options.names = options.names || [];
|
||||
|
||||
if (!source.isObject3D) {
|
||||
source = getHelperFromSkeleton(source);
|
||||
}
|
||||
|
||||
const numFrames = Math.round(clip.duration * (options.fps / 1000) * 1000),
|
||||
delta = clip.duration / (numFrames - 1),
|
||||
convertedTracks = [],
|
||||
mixer = new AnimationMixer(source),
|
||||
bones = getBones(target.skeleton),
|
||||
boneDatas = [];
|
||||
|
||||
let positionOffset, bone, boneTo, boneData, name;
|
||||
|
||||
mixer.clipAction(clip).play();
|
||||
|
||||
// trim
|
||||
|
||||
let start = 0,
|
||||
end = numFrames;
|
||||
|
||||
if (options.trim !== undefined) {
|
||||
start = Math.round(options.trim[0] * options.fps);
|
||||
end =
|
||||
Math.min(Math.round(options.trim[1] * options.fps), numFrames) - start;
|
||||
|
||||
mixer.update(options.trim[0]);
|
||||
} else {
|
||||
mixer.update(0);
|
||||
}
|
||||
|
||||
source.updateMatrixWorld();
|
||||
|
||||
//
|
||||
|
||||
for (let frame = 0; frame < end; ++frame) {
|
||||
const time = frame * delta;
|
||||
|
||||
retarget(target, source, options);
|
||||
|
||||
for (let j = 0; j < bones.length; ++j) {
|
||||
bone = bones[j];
|
||||
name = getBoneName(bone, options) || bone.name;
|
||||
boneTo = getBoneByName(name, source.skeleton);
|
||||
|
||||
if (boneTo) {
|
||||
boneData = boneDatas[j] = boneDatas[j] || { bone: bone };
|
||||
|
||||
if (options.hip === name) {
|
||||
if (!boneData.pos) {
|
||||
boneData.pos = {
|
||||
times: new Float32Array(end),
|
||||
values: new Float32Array(end * 3),
|
||||
};
|
||||
}
|
||||
|
||||
if (options.useFirstFramePosition) {
|
||||
if (frame === 0) {
|
||||
positionOffset = bone.position.clone();
|
||||
}
|
||||
|
||||
bone.position.sub(positionOffset);
|
||||
}
|
||||
|
||||
boneData.pos.times[frame] = time;
|
||||
|
||||
bone.position.toArray(boneData.pos.values, frame * 3);
|
||||
}
|
||||
|
||||
if (!boneData.quat) {
|
||||
boneData.quat = {
|
||||
times: new Float32Array(end),
|
||||
values: new Float32Array(end * 4),
|
||||
};
|
||||
}
|
||||
|
||||
boneData.quat.times[frame] = time;
|
||||
|
||||
bone.quaternion.toArray(boneData.quat.values, frame * 4);
|
||||
}
|
||||
}
|
||||
|
||||
if (frame === end - 2) {
|
||||
// last mixer update before final loop iteration
|
||||
// make sure we do not go over or equal to clip duration
|
||||
mixer.update(delta - 0.0000001);
|
||||
} else {
|
||||
mixer.update(delta);
|
||||
}
|
||||
|
||||
source.updateMatrixWorld();
|
||||
}
|
||||
|
||||
for (let i = 0; i < boneDatas.length; ++i) {
|
||||
boneData = boneDatas[i];
|
||||
|
||||
if (boneData) {
|
||||
if (boneData.pos) {
|
||||
convertedTracks.push(
|
||||
new VectorKeyframeTrack(
|
||||
".bones[" + boneData.bone.name + "].position",
|
||||
boneData.pos.times,
|
||||
boneData.pos.values,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
convertedTracks.push(
|
||||
new QuaternionKeyframeTrack(
|
||||
".bones[" + boneData.bone.name + "].quaternion",
|
||||
boneData.quat.times,
|
||||
boneData.quat.values,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mixer.uncacheAction(clip);
|
||||
|
||||
return new AnimationClip(clip.name, -1, convertedTracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the given 3D object and its descendants, ensuring that any `SkinnedMesh` instances are
|
||||
* correctly associated with their bones. Bones are also cloned, and must be descendants of the
|
||||
* object passed to this method. Other data, like geometries and materials, are reused by reference.
|
||||
*
|
||||
* @param {Object3D} source - The 3D object to clone.
|
||||
* @return {Object3D} The cloned 3D object.
|
||||
*/
|
||||
function clone(source) {
|
||||
const sourceLookup = new Map();
|
||||
const cloneLookup = new Map();
|
||||
|
||||
const clone = source.clone();
|
||||
|
||||
parallelTraverse(source, clone, function (sourceNode, clonedNode) {
|
||||
sourceLookup.set(clonedNode, sourceNode);
|
||||
cloneLookup.set(sourceNode, clonedNode);
|
||||
});
|
||||
|
||||
clone.traverse(function (node) {
|
||||
if (!node.isSkinnedMesh) return;
|
||||
|
||||
const clonedMesh = node;
|
||||
const sourceMesh = sourceLookup.get(node);
|
||||
const sourceBones = sourceMesh.skeleton.bones;
|
||||
|
||||
clonedMesh.skeleton = sourceMesh.skeleton.clone();
|
||||
clonedMesh.bindMatrix.copy(sourceMesh.bindMatrix);
|
||||
|
||||
clonedMesh.skeleton.bones = sourceBones.map(function (bone) {
|
||||
return cloneLookup.get(bone);
|
||||
});
|
||||
|
||||
clonedMesh.bind(clonedMesh.skeleton, clonedMesh.bindMatrix);
|
||||
});
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
// internal helper
|
||||
|
||||
function getBoneByName(name, skeleton) {
|
||||
for (let i = 0, bones = getBones(skeleton); i < bones.length; i++) {
|
||||
if (name === bones[i].name) return bones[i];
|
||||
}
|
||||
}
|
||||
|
||||
function getBones(skeleton) {
|
||||
return Array.isArray(skeleton) ? skeleton : skeleton.bones;
|
||||
}
|
||||
|
||||
function getHelperFromSkeleton(skeleton) {
|
||||
const source = new SkeletonHelper(skeleton.bones[0]);
|
||||
source.skeleton = skeleton;
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
function parallelTraverse(a, b, callback) {
|
||||
callback(a, b);
|
||||
|
||||
for (let i = 0; i < a.children.length; i++) {
|
||||
parallelTraverse(a.children[i], b.children[i], callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retarget options of `SkeletonUtils`.
|
||||
*
|
||||
* @typedef {Object} module:SkeletonUtils~RetargetOptions
|
||||
* @property {boolean} [useFirstFramePosition=false] - Whether to use the position of the first frame or not.
|
||||
* @property {number} [fps] - The FPS of the clip.
|
||||
* @property {Object<string,string>} [names] - A dictionary for mapping target to source bone names.
|
||||
* @property {function(string):string} [getBoneName] - A function for mapping bone names. Alternative to `names`.
|
||||
* @property {Array<number>} [trim] - Whether to trim the clip or not. If set the array should hold two values for the start and end.
|
||||
* @property {boolean} [preserveBoneMatrix=true] - Whether to preserve bone matrices or not.
|
||||
* @property {boolean} [preserveBonePositions=true] - Whether to preserve bone positions or not.
|
||||
* @property {boolean} [useTargetMatrix=false] - Whether to use the target matrix or not.
|
||||
* @property {string} [hip='hip'] - The name of the source's hip bone.
|
||||
* @property {Vector3} [hipInfluence=(1,1,1)] - The hip influence.
|
||||
* @property {number} [scale=1] - The scale.
|
||||
* @property {Object<string,Matrix4>} [localOffsets] - Per-bone local offset matrices, keyed by bone name.
|
||||
* @property {Vector3} [hipPosition] - An additional position offset applied to the hip bone.
|
||||
**/
|
||||
|
||||
export { retarget, retargetClip, clone };
|
||||
57243
public/vendor/three.core.js
vendored
Normal file
57243
public/vendor/three.core.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
19637
public/vendor/three.module.js
vendored
Normal file
19637
public/vendor/three.module.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue