first app vibe
This commit is contained in:
1044
app/node_modules/three/src/core/BufferAttribute.js
generated
vendored
Normal file
1044
app/node_modules/three/src/core/BufferAttribute.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1446
app/node_modules/three/src/core/BufferGeometry.js
generated
vendored
Normal file
1446
app/node_modules/three/src/core/BufferGeometry.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
128
app/node_modules/three/src/core/Clock.js
generated
vendored
Normal file
128
app/node_modules/three/src/core/Clock.js
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* Class for keeping track of time.
|
||||
*/
|
||||
class Clock {
|
||||
|
||||
/**
|
||||
* Constructs a new clock.
|
||||
*
|
||||
* @param {boolean} [autoStart=true] - Whether to automatically start the clock when
|
||||
* `getDelta()` is called for the first time.
|
||||
*/
|
||||
constructor( autoStart = true ) {
|
||||
|
||||
/**
|
||||
* If set to `true`, the clock starts automatically when `getDelta()` is called
|
||||
* for the first time.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.autoStart = autoStart;
|
||||
|
||||
/**
|
||||
* Holds the time at which the clock's `start()` method was last called.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.startTime = 0;
|
||||
|
||||
/**
|
||||
* Holds the time at which the clock's `start()`, `getElapsedTime()` or
|
||||
* `getDelta()` methods were last called.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.oldTime = 0;
|
||||
|
||||
/**
|
||||
* Keeps track of the total time that the clock has been running.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.elapsedTime = 0;
|
||||
|
||||
/**
|
||||
* Whether the clock is running or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.running = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the clock. When `autoStart` is set to `true`, the method is automatically
|
||||
* called by the class.
|
||||
*/
|
||||
start() {
|
||||
|
||||
this.startTime = performance.now();
|
||||
|
||||
this.oldTime = this.startTime;
|
||||
this.elapsedTime = 0;
|
||||
this.running = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the clock.
|
||||
*/
|
||||
stop() {
|
||||
|
||||
this.getElapsedTime();
|
||||
this.running = false;
|
||||
this.autoStart = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the elapsed time in seconds.
|
||||
*
|
||||
* @return {number} The elapsed time.
|
||||
*/
|
||||
getElapsedTime() {
|
||||
|
||||
this.getDelta();
|
||||
return this.elapsedTime;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the delta time in seconds.
|
||||
*
|
||||
* @return {number} The delta time.
|
||||
*/
|
||||
getDelta() {
|
||||
|
||||
let diff = 0;
|
||||
|
||||
if ( this.autoStart && ! this.running ) {
|
||||
|
||||
this.start();
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
if ( this.running ) {
|
||||
|
||||
const newTime = performance.now();
|
||||
|
||||
diff = ( newTime - this.oldTime ) / 1000;
|
||||
this.oldTime = newTime;
|
||||
|
||||
this.elapsedTime += diff;
|
||||
|
||||
}
|
||||
|
||||
return diff;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Clock };
|
||||
131
app/node_modules/three/src/core/EventDispatcher.js
generated
vendored
Normal file
131
app/node_modules/three/src/core/EventDispatcher.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* This modules allows to dispatch event objects on custom JavaScript objects.
|
||||
*
|
||||
* Main repository: [eventdispatcher.js]{@link https://github.com/mrdoob/eventdispatcher.js/}
|
||||
*
|
||||
* Code Example:
|
||||
* ```js
|
||||
* class Car extends EventDispatcher {
|
||||
* start() {
|
||||
* this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
|
||||
* }
|
||||
*};
|
||||
*
|
||||
* // Using events with the custom object
|
||||
* const car = new Car();
|
||||
* car.addEventListener( 'start', function ( event ) {
|
||||
* alert( event.message );
|
||||
* } );
|
||||
*
|
||||
* car.start();
|
||||
* ```
|
||||
*/
|
||||
class EventDispatcher {
|
||||
|
||||
/**
|
||||
* Adds the given event listener to the given event type.
|
||||
*
|
||||
* @param {string} type - The type of event to listen to.
|
||||
* @param {Function} listener - The function that gets called when the event is fired.
|
||||
*/
|
||||
addEventListener( type, listener ) {
|
||||
|
||||
if ( this._listeners === undefined ) this._listeners = {};
|
||||
|
||||
const listeners = this._listeners;
|
||||
|
||||
if ( listeners[ type ] === undefined ) {
|
||||
|
||||
listeners[ type ] = [];
|
||||
|
||||
}
|
||||
|
||||
if ( listeners[ type ].indexOf( listener ) === - 1 ) {
|
||||
|
||||
listeners[ type ].push( listener );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the given event listener has been added to the given event type.
|
||||
*
|
||||
* @param {string} type - The type of event.
|
||||
* @param {Function} listener - The listener to check.
|
||||
* @return {boolean} Whether the given event listener has been added to the given event type.
|
||||
*/
|
||||
hasEventListener( type, listener ) {
|
||||
|
||||
const listeners = this._listeners;
|
||||
|
||||
if ( listeners === undefined ) return false;
|
||||
|
||||
return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given event listener from the given event type.
|
||||
*
|
||||
* @param {string} type - The type of event.
|
||||
* @param {Function} listener - The listener to remove.
|
||||
*/
|
||||
removeEventListener( type, listener ) {
|
||||
|
||||
const listeners = this._listeners;
|
||||
|
||||
if ( listeners === undefined ) return;
|
||||
|
||||
const listenerArray = listeners[ type ];
|
||||
|
||||
if ( listenerArray !== undefined ) {
|
||||
|
||||
const index = listenerArray.indexOf( listener );
|
||||
|
||||
if ( index !== - 1 ) {
|
||||
|
||||
listenerArray.splice( index, 1 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches an event object.
|
||||
*
|
||||
* @param {Object} event - The event that gets fired.
|
||||
*/
|
||||
dispatchEvent( event ) {
|
||||
|
||||
const listeners = this._listeners;
|
||||
|
||||
if ( listeners === undefined ) return;
|
||||
|
||||
const listenerArray = listeners[ event.type ];
|
||||
|
||||
if ( listenerArray !== undefined ) {
|
||||
|
||||
event.target = this;
|
||||
|
||||
// Make a copy, in case listeners are removed while iterating.
|
||||
const array = listenerArray.slice( 0 );
|
||||
|
||||
for ( let i = 0, l = array.length; i < l; i ++ ) {
|
||||
|
||||
array[ i ].call( this, event );
|
||||
|
||||
}
|
||||
|
||||
event.target = null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { EventDispatcher };
|
||||
171
app/node_modules/three/src/core/GLBufferAttribute.js
generated
vendored
Normal file
171
app/node_modules/three/src/core/GLBufferAttribute.js
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* An alternative version of a buffer attribute with more control over the VBO.
|
||||
*
|
||||
* The renderer does not construct a VBO for this kind of attribute. Instead, it uses
|
||||
* whatever VBO is passed in constructor and can later be altered via the `buffer` property.
|
||||
*
|
||||
* The most common use case for this class is when some kind of GPGPU calculation interferes
|
||||
* or even produces the VBOs in question.
|
||||
*
|
||||
* Notice that this class can only be used with {@link WebGLRenderer}.
|
||||
*/
|
||||
class GLBufferAttribute {
|
||||
|
||||
/**
|
||||
* Constructs a new GL buffer attribute.
|
||||
*
|
||||
* @param {WebGLBuffer} buffer - The native WebGL buffer.
|
||||
* @param {number} type - The native data type (e.g. `gl.FLOAT`).
|
||||
* @param {number} itemSize - The item size.
|
||||
* @param {number} elementSize - The corresponding size (in bytes) for the given `type` parameter.
|
||||
* @param {number} count - The expected number of vertices in VBO.
|
||||
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
|
||||
*/
|
||||
constructor( buffer, type, itemSize, elementSize, count, normalized = false ) {
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isGLBufferAttribute = true;
|
||||
|
||||
/**
|
||||
* The name of the buffer attribute.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* The native WebGL buffer.
|
||||
*
|
||||
* @type {WebGLBuffer}
|
||||
*/
|
||||
this.buffer = buffer;
|
||||
|
||||
/**
|
||||
* The native data type.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.type = type;
|
||||
|
||||
/**
|
||||
* The item size, see {@link BufferAttribute#itemSize}.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.itemSize = itemSize;
|
||||
|
||||
/**
|
||||
* The corresponding size (in bytes) for the given `type` parameter.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.elementSize = elementSize;
|
||||
|
||||
/**
|
||||
* The expected number of vertices in VBO.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.count = count;
|
||||
|
||||
/**
|
||||
* Applies to integer data only. Indicates how the underlying data in the buffer maps to
|
||||
* the values in the GLSL code. For instance, if `buffer` contains data of `gl.UNSIGNED_SHORT`,
|
||||
* and `normalized` is `true`, the values `0 - +65535` in the buffer data will be mapped to
|
||||
* `0.0f - +1.0f` in the GLSL attribute. If `normalized` is `false`, the values will be converted
|
||||
* to floats unmodified, i.e. `65535` becomes `65535.0f`.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.normalized = normalized;
|
||||
|
||||
/**
|
||||
* A version number, incremented every time the `needsUpdate` is set to `true`.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.version = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to indicate that this attribute has changed and should be re-sent to
|
||||
* the GPU. Set this to `true` when you modify the value of the array.
|
||||
*
|
||||
* @type {number}
|
||||
* @default false
|
||||
* @param {boolean} value
|
||||
*/
|
||||
set needsUpdate( value ) {
|
||||
|
||||
if ( value === true ) this.version ++;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given native WebGL buffer.
|
||||
*
|
||||
* @param {WebGLBuffer} buffer - The buffer to set.
|
||||
* @return {BufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setBuffer( buffer ) {
|
||||
|
||||
this.buffer = buffer;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given native data type and element size.
|
||||
*
|
||||
* @param {number} type - The native data type (e.g. `gl.FLOAT`).
|
||||
* @param {number} elementSize - The corresponding size (in bytes) for the given `type` parameter.
|
||||
* @return {BufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setType( type, elementSize ) {
|
||||
|
||||
this.type = type;
|
||||
this.elementSize = elementSize;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the item size.
|
||||
*
|
||||
* @param {number} itemSize - The item size.
|
||||
* @return {BufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setItemSize( itemSize ) {
|
||||
|
||||
this.itemSize = itemSize;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the count (the expected number of vertices in VBO).
|
||||
*
|
||||
* @param {number} count - The count.
|
||||
* @return {BufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setCount( count ) {
|
||||
|
||||
this.count = count;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { GLBufferAttribute };
|
||||
68
app/node_modules/three/src/core/InstancedBufferAttribute.js
generated
vendored
Normal file
68
app/node_modules/three/src/core/InstancedBufferAttribute.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import { BufferAttribute } from './BufferAttribute.js';
|
||||
|
||||
/**
|
||||
* An instanced version of a buffer attribute.
|
||||
*
|
||||
* @augments BufferAttribute
|
||||
*/
|
||||
class InstancedBufferAttribute extends BufferAttribute {
|
||||
|
||||
/**
|
||||
* Constructs a new instanced buffer attribute.
|
||||
*
|
||||
* @param {TypedArray} array - The array holding the attribute data.
|
||||
* @param {number} itemSize - The item size.
|
||||
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
|
||||
* @param {number} [meshPerAttribute=1] - How often a value of this buffer attribute should be repeated.
|
||||
*/
|
||||
constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {
|
||||
|
||||
super( array, itemSize, normalized );
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInstancedBufferAttribute = true;
|
||||
|
||||
/**
|
||||
* Defines how often a value of this buffer attribute should be repeated. A
|
||||
* value of one means that each value of the instanced attribute is used for
|
||||
* a single instance. A value of two means that each value is used for two
|
||||
* consecutive instances (and so on).
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.meshPerAttribute = meshPerAttribute;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.meshPerAttribute = source.meshPerAttribute;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.meshPerAttribute = this.meshPerAttribute;
|
||||
|
||||
data.isInstancedBufferAttribute = true;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { InstancedBufferAttribute };
|
||||
60
app/node_modules/three/src/core/InstancedBufferGeometry.js
generated
vendored
Normal file
60
app/node_modules/three/src/core/InstancedBufferGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
import { BufferGeometry } from './BufferGeometry.js';
|
||||
|
||||
/**
|
||||
* An instanced version of a geometry.
|
||||
*/
|
||||
class InstancedBufferGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new instanced buffer geometry.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInstancedBufferGeometry = true;
|
||||
|
||||
this.type = 'InstancedBufferGeometry';
|
||||
|
||||
/**
|
||||
* The instance count.
|
||||
*
|
||||
* @type {number}
|
||||
* @default Infinity
|
||||
*/
|
||||
this.instanceCount = Infinity;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.instanceCount = source.instanceCount;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.instanceCount = this.instanceCount;
|
||||
|
||||
data.isInstancedBufferGeometry = true;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { InstancedBufferGeometry };
|
||||
74
app/node_modules/three/src/core/InstancedInterleavedBuffer.js
generated
vendored
Normal file
74
app/node_modules/three/src/core/InstancedInterleavedBuffer.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
import { InterleavedBuffer } from './InterleavedBuffer.js';
|
||||
|
||||
/**
|
||||
* An instanced version of an interleaved buffer.
|
||||
*
|
||||
* @augments InterleavedBuffer
|
||||
*/
|
||||
class InstancedInterleavedBuffer extends InterleavedBuffer {
|
||||
|
||||
/**
|
||||
* Constructs a new instanced interleaved buffer.
|
||||
*
|
||||
* @param {TypedArray} array - A typed array with a shared buffer storing attribute data.
|
||||
* @param {number} stride - The number of typed-array elements per vertex.
|
||||
* @param {number} [meshPerAttribute=1] - Defines how often a value of this interleaved buffer should be repeated.
|
||||
*/
|
||||
constructor( array, stride, meshPerAttribute = 1 ) {
|
||||
|
||||
super( array, stride );
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInstancedInterleavedBuffer = true;
|
||||
|
||||
/**
|
||||
* Defines how often a value of this buffer attribute should be repeated,
|
||||
* see {@link InstancedBufferAttribute#meshPerAttribute}.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.meshPerAttribute = meshPerAttribute;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.meshPerAttribute = source.meshPerAttribute;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
clone( data ) {
|
||||
|
||||
const ib = super.clone( data );
|
||||
|
||||
ib.meshPerAttribute = this.meshPerAttribute;
|
||||
|
||||
return ib;
|
||||
|
||||
}
|
||||
|
||||
toJSON( data ) {
|
||||
|
||||
const json = super.toJSON( data );
|
||||
|
||||
json.isInstancedInterleavedBuffer = true;
|
||||
json.meshPerAttribute = this.meshPerAttribute;
|
||||
|
||||
return json;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { InstancedInterleavedBuffer };
|
||||
291
app/node_modules/three/src/core/InterleavedBuffer.js
generated
vendored
Normal file
291
app/node_modules/three/src/core/InterleavedBuffer.js
generated
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
import { generateUUID } from '../math/MathUtils.js';
|
||||
import { StaticDrawUsage } from '../constants.js';
|
||||
|
||||
/**
|
||||
* "Interleaved" means that multiple attributes, possibly of different types,
|
||||
* (e.g., position, normal, uv, color) are packed into a single array buffer.
|
||||
*
|
||||
* An introduction into interleaved arrays can be found here: [Interleaved array basics]{@link https://blog.tojicode.com/2011/05/interleaved-array-basics.html}
|
||||
*/
|
||||
class InterleavedBuffer {
|
||||
|
||||
/**
|
||||
* Constructs a new interleaved buffer.
|
||||
*
|
||||
* @param {TypedArray} array - A typed array with a shared buffer storing attribute data.
|
||||
* @param {number} stride - The number of typed-array elements per vertex.
|
||||
*/
|
||||
constructor( array, stride ) {
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInterleavedBuffer = true;
|
||||
|
||||
/**
|
||||
* A typed array with a shared buffer storing attribute data.
|
||||
*
|
||||
* @type {TypedArray}
|
||||
*/
|
||||
this.array = array;
|
||||
|
||||
/**
|
||||
* The number of typed-array elements per vertex.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.stride = stride;
|
||||
|
||||
/**
|
||||
* The total number of elements in the array
|
||||
*
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
this.count = array !== undefined ? array.length / stride : 0;
|
||||
|
||||
/**
|
||||
* Defines the intended usage pattern of the data store for optimization purposes.
|
||||
*
|
||||
* Note: After the initial use of a buffer, its usage cannot be changed. Instead,
|
||||
* instantiate a new one and set the desired usage before the next render.
|
||||
*
|
||||
* @type {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)}
|
||||
* @default StaticDrawUsage
|
||||
*/
|
||||
this.usage = StaticDrawUsage;
|
||||
|
||||
/**
|
||||
* This can be used to only update some components of stored vectors (for example, just the
|
||||
* component related to color). Use the `addUpdateRange()` function to add ranges to this array.
|
||||
*
|
||||
* @type {Array<Object>}
|
||||
*/
|
||||
this.updateRanges = [];
|
||||
|
||||
/**
|
||||
* A version number, incremented every time the `needsUpdate` is set to `true`.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.version = 0;
|
||||
|
||||
/**
|
||||
* The UUID of the interleaved buffer.
|
||||
*
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.uuid = generateUUID();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback function that is executed after the renderer has transferred the attribute array
|
||||
* data to the GPU.
|
||||
*/
|
||||
onUploadCallback() {}
|
||||
|
||||
/**
|
||||
* Flag to indicate that this attribute has changed and should be re-sent to
|
||||
* the GPU. Set this to `true` when you modify the value of the array.
|
||||
*
|
||||
* @type {number}
|
||||
* @default false
|
||||
* @param {boolean} value
|
||||
*/
|
||||
set needsUpdate( value ) {
|
||||
|
||||
if ( value === true ) this.version ++;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the usage of this interleaved buffer.
|
||||
*
|
||||
* @param {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)} value - The usage to set.
|
||||
* @return {InterleavedBuffer} A reference to this interleaved buffer.
|
||||
*/
|
||||
setUsage( value ) {
|
||||
|
||||
this.usage = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a range of data in the data array to be updated on the GPU.
|
||||
*
|
||||
* @param {number} start - Position at which to start update.
|
||||
* @param {number} count - The number of components to update.
|
||||
*/
|
||||
addUpdateRange( start, count ) {
|
||||
|
||||
this.updateRanges.push( { start, count } );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the update ranges.
|
||||
*/
|
||||
clearUpdateRanges() {
|
||||
|
||||
this.updateRanges.length = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the values of the given interleaved buffer to this instance.
|
||||
*
|
||||
* @param {InterleavedBuffer} source - The interleaved buffer to copy.
|
||||
* @return {InterleavedBuffer} A reference to this instance.
|
||||
*/
|
||||
copy( source ) {
|
||||
|
||||
this.array = new source.array.constructor( source.array );
|
||||
this.count = source.count;
|
||||
this.stride = source.stride;
|
||||
this.usage = source.usage;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a vector from the given interleaved buffer to this one. The start
|
||||
* and destination position in the attribute buffers are represented by the
|
||||
* given indices.
|
||||
*
|
||||
* @param {number} index1 - The destination index into this interleaved buffer.
|
||||
* @param {InterleavedBuffer} interleavedBuffer - The interleaved buffer to copy from.
|
||||
* @param {number} index2 - The source index into the given interleaved buffer.
|
||||
* @return {InterleavedBuffer} A reference to this instance.
|
||||
*/
|
||||
copyAt( index1, interleavedBuffer, index2 ) {
|
||||
|
||||
index1 *= this.stride;
|
||||
index2 *= interleavedBuffer.stride;
|
||||
|
||||
for ( let i = 0, l = this.stride; i < l; i ++ ) {
|
||||
|
||||
this.array[ index1 + i ] = interleavedBuffer.array[ index2 + i ];
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given array data in the interleaved buffer.
|
||||
*
|
||||
* @param {(TypedArray|Array)} value - The array data to set.
|
||||
* @param {number} [offset=0] - The offset in this interleaved buffer's array.
|
||||
* @return {InterleavedBuffer} A reference to this instance.
|
||||
*/
|
||||
set( value, offset = 0 ) {
|
||||
|
||||
this.array.set( value, offset );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new interleaved buffer with copied values from this instance.
|
||||
*
|
||||
* @param {Object} [data] - An object with shared array buffers that allows to retain shared structures.
|
||||
* @return {InterleavedBuffer} A clone of this instance.
|
||||
*/
|
||||
clone( data ) {
|
||||
|
||||
if ( data.arrayBuffers === undefined ) {
|
||||
|
||||
data.arrayBuffers = {};
|
||||
|
||||
}
|
||||
|
||||
if ( this.array.buffer._uuid === undefined ) {
|
||||
|
||||
this.array.buffer._uuid = generateUUID();
|
||||
|
||||
}
|
||||
|
||||
if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
|
||||
|
||||
data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
|
||||
|
||||
}
|
||||
|
||||
const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
|
||||
|
||||
const ib = new this.constructor( array, this.stride );
|
||||
ib.setUsage( this.usage );
|
||||
|
||||
return ib;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given callback function that is executed after the Renderer has transferred
|
||||
* the array data to the GPU. Can be used to perform clean-up operations after
|
||||
* the upload when data are not needed anymore on the CPU side.
|
||||
*
|
||||
* @param {Function} callback - The `onUpload()` callback.
|
||||
* @return {InterleavedBuffer} A reference to this instance.
|
||||
*/
|
||||
onUpload( callback ) {
|
||||
|
||||
this.onUploadCallback = callback;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the interleaved buffer into JSON.
|
||||
*
|
||||
* @param {Object} [data] - An optional value holding meta information about the serialization.
|
||||
* @return {Object} A JSON object representing the serialized interleaved buffer.
|
||||
*/
|
||||
toJSON( data ) {
|
||||
|
||||
if ( data.arrayBuffers === undefined ) {
|
||||
|
||||
data.arrayBuffers = {};
|
||||
|
||||
}
|
||||
|
||||
// generate UUID for array buffer if necessary
|
||||
|
||||
if ( this.array.buffer._uuid === undefined ) {
|
||||
|
||||
this.array.buffer._uuid = generateUUID();
|
||||
|
||||
}
|
||||
|
||||
if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
|
||||
|
||||
data.arrayBuffers[ this.array.buffer._uuid ] = Array.from( new Uint32Array( this.array.buffer ) );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
return {
|
||||
uuid: this.uuid,
|
||||
buffer: this.array.buffer._uuid,
|
||||
type: this.array.constructor.name,
|
||||
stride: this.stride
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { InterleavedBuffer };
|
||||
548
app/node_modules/three/src/core/InterleavedBufferAttribute.js
generated
vendored
Normal file
548
app/node_modules/three/src/core/InterleavedBufferAttribute.js
generated
vendored
Normal file
@@ -0,0 +1,548 @@
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { BufferAttribute } from './BufferAttribute.js';
|
||||
import { denormalize, normalize } from '../math/MathUtils.js';
|
||||
|
||||
const _vector = /*@__PURE__*/ new Vector3();
|
||||
|
||||
/**
|
||||
* An alternative version of a buffer attribute with interleaved data. Interleaved
|
||||
* attributes share a common interleaved data storage ({@link InterleavedBuffer}) and refer with
|
||||
* different offsets into the buffer.
|
||||
*/
|
||||
class InterleavedBufferAttribute {
|
||||
|
||||
/**
|
||||
* Constructs a new interleaved buffer attribute.
|
||||
*
|
||||
* @param {InterleavedBuffer} interleavedBuffer - The buffer holding the interleaved data.
|
||||
* @param {number} itemSize - The item size.
|
||||
* @param {number} offset - The attribute offset into the buffer.
|
||||
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
|
||||
*/
|
||||
constructor( interleavedBuffer, itemSize, offset, normalized = false ) {
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInterleavedBufferAttribute = true;
|
||||
|
||||
/**
|
||||
* The name of the buffer attribute.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* The buffer holding the interleaved data.
|
||||
*
|
||||
* @type {InterleavedBuffer}
|
||||
*/
|
||||
this.data = interleavedBuffer;
|
||||
|
||||
/**
|
||||
* The item size, see {@link BufferAttribute#itemSize}.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.itemSize = itemSize;
|
||||
|
||||
/**
|
||||
* The attribute offset into the buffer.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.offset = offset;
|
||||
|
||||
/**
|
||||
* Whether the data are normalized or not, see {@link BufferAttribute#normalized}
|
||||
*
|
||||
* @type {InterleavedBuffer}
|
||||
*/
|
||||
this.normalized = normalized;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The item count of this buffer attribute.
|
||||
*
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get count() {
|
||||
|
||||
return this.data.count;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The array holding the interleaved buffer attribute data.
|
||||
*
|
||||
* @type {TypedArray}
|
||||
*/
|
||||
get array() {
|
||||
|
||||
return this.data.array;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to indicate that this attribute has changed and should be re-sent to
|
||||
* the GPU. Set this to `true` when you modify the value of the array.
|
||||
*
|
||||
* @type {number}
|
||||
* @default false
|
||||
* @param {boolean} value
|
||||
*/
|
||||
set needsUpdate( value ) {
|
||||
|
||||
this.data.needsUpdate = value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the given 4x4 matrix to the given attribute. Only works with
|
||||
* item size `3`.
|
||||
*
|
||||
* @param {Matrix4} m - The matrix to apply.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
applyMatrix4( m ) {
|
||||
|
||||
for ( let i = 0, l = this.data.count; i < l; i ++ ) {
|
||||
|
||||
_vector.fromBufferAttribute( this, i );
|
||||
|
||||
_vector.applyMatrix4( m );
|
||||
|
||||
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the given 3x3 normal matrix to the given attribute. Only works with
|
||||
* item size `3`.
|
||||
*
|
||||
* @param {Matrix3} m - The normal matrix to apply.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
applyNormalMatrix( m ) {
|
||||
|
||||
for ( let i = 0, l = this.count; i < l; i ++ ) {
|
||||
|
||||
_vector.fromBufferAttribute( this, i );
|
||||
|
||||
_vector.applyNormalMatrix( m );
|
||||
|
||||
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the given 4x4 matrix to the given attribute. Only works with
|
||||
* item size `3` and with direction vectors.
|
||||
*
|
||||
* @param {Matrix4} m - The matrix to apply.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
transformDirection( m ) {
|
||||
|
||||
for ( let i = 0, l = this.count; i < l; i ++ ) {
|
||||
|
||||
_vector.fromBufferAttribute( this, i );
|
||||
|
||||
_vector.transformDirection( m );
|
||||
|
||||
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} component - The component index.
|
||||
* @return {number} The returned value.
|
||||
*/
|
||||
getComponent( index, component ) {
|
||||
|
||||
let value = this.array[ index * this.data.stride + this.offset + component ];
|
||||
|
||||
if ( this.normalized ) value = denormalize( value, this.array );
|
||||
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given value to the given component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} component - The component index.
|
||||
* @param {number} value - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setComponent( index, component, value ) {
|
||||
|
||||
if ( this.normalized ) value = normalize( value, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + component ] = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} x - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setX( index, x ) {
|
||||
|
||||
if ( this.normalized ) x = normalize( x, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset ] = x;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the y component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} y - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setY( index, y ) {
|
||||
|
||||
if ( this.normalized ) y = normalize( y, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the z component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} z - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setZ( index, z ) {
|
||||
|
||||
if ( this.normalized ) z = normalize( z, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the w component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} w - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setW( index, w ) {
|
||||
|
||||
if ( this.normalized ) w = normalize( w, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the x component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @return {number} The x component.
|
||||
*/
|
||||
getX( index ) {
|
||||
|
||||
let x = this.data.array[ index * this.data.stride + this.offset ];
|
||||
|
||||
if ( this.normalized ) x = denormalize( x, this.array );
|
||||
|
||||
return x;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the y component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @return {number} The y component.
|
||||
*/
|
||||
getY( index ) {
|
||||
|
||||
let y = this.data.array[ index * this.data.stride + this.offset + 1 ];
|
||||
|
||||
if ( this.normalized ) y = denormalize( y, this.array );
|
||||
|
||||
return y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the z component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @return {number} The z component.
|
||||
*/
|
||||
getZ( index ) {
|
||||
|
||||
let z = this.data.array[ index * this.data.stride + this.offset + 2 ];
|
||||
|
||||
if ( this.normalized ) z = denormalize( z, this.array );
|
||||
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the w component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @return {number} The w component.
|
||||
*/
|
||||
getW( index ) {
|
||||
|
||||
let w = this.data.array[ index * this.data.stride + this.offset + 3 ];
|
||||
|
||||
if ( this.normalized ) w = denormalize( w, this.array );
|
||||
|
||||
return w;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x and y component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} x - The value for the x component to set.
|
||||
* @param {number} y - The value for the y component to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setXY( index, x, y ) {
|
||||
|
||||
index = index * this.data.stride + this.offset;
|
||||
|
||||
if ( this.normalized ) {
|
||||
|
||||
x = normalize( x, this.array );
|
||||
y = normalize( y, this.array );
|
||||
|
||||
}
|
||||
|
||||
this.data.array[ index + 0 ] = x;
|
||||
this.data.array[ index + 1 ] = y;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x, y and z component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} x - The value for the x component to set.
|
||||
* @param {number} y - The value for the y component to set.
|
||||
* @param {number} z - The value for the z component to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setXYZ( index, x, y, z ) {
|
||||
|
||||
index = index * this.data.stride + this.offset;
|
||||
|
||||
if ( this.normalized ) {
|
||||
|
||||
x = normalize( x, this.array );
|
||||
y = normalize( y, this.array );
|
||||
z = normalize( z, this.array );
|
||||
|
||||
}
|
||||
|
||||
this.data.array[ index + 0 ] = x;
|
||||
this.data.array[ index + 1 ] = y;
|
||||
this.data.array[ index + 2 ] = z;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x, y, z and w component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} x - The value for the x component to set.
|
||||
* @param {number} y - The value for the y component to set.
|
||||
* @param {number} z - The value for the z component to set.
|
||||
* @param {number} w - The value for the w component to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setXYZW( index, x, y, z, w ) {
|
||||
|
||||
index = index * this.data.stride + this.offset;
|
||||
|
||||
if ( this.normalized ) {
|
||||
|
||||
x = normalize( x, this.array );
|
||||
y = normalize( y, this.array );
|
||||
z = normalize( z, this.array );
|
||||
w = normalize( w, this.array );
|
||||
|
||||
}
|
||||
|
||||
this.data.array[ index + 0 ] = x;
|
||||
this.data.array[ index + 1 ] = y;
|
||||
this.data.array[ index + 2 ] = z;
|
||||
this.data.array[ index + 3 ] = w;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new buffer attribute with copied values from this instance.
|
||||
*
|
||||
* If no parameter is provided, cloning an interleaved buffer attribute will de-interleave buffer data.
|
||||
*
|
||||
* @param {Object} [data] - An object with interleaved buffers that allows to retain the interleaved property.
|
||||
* @return {BufferAttribute|InterleavedBufferAttribute} A clone of this instance.
|
||||
*/
|
||||
clone( data ) {
|
||||
|
||||
if ( data === undefined ) {
|
||||
|
||||
console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );
|
||||
|
||||
const array = [];
|
||||
|
||||
for ( let i = 0; i < this.count; i ++ ) {
|
||||
|
||||
const index = i * this.data.stride + this.offset;
|
||||
|
||||
for ( let j = 0; j < this.itemSize; j ++ ) {
|
||||
|
||||
array.push( this.data.array[ index + j ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
|
||||
|
||||
} else {
|
||||
|
||||
if ( data.interleavedBuffers === undefined ) {
|
||||
|
||||
data.interleavedBuffers = {};
|
||||
|
||||
}
|
||||
|
||||
if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
|
||||
|
||||
data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
|
||||
|
||||
}
|
||||
|
||||
return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the buffer attribute into JSON.
|
||||
*
|
||||
* If no parameter is provided, cloning an interleaved buffer attribute will de-interleave buffer data.
|
||||
*
|
||||
* @param {Object} [data] - An optional value holding meta information about the serialization.
|
||||
* @return {Object} A JSON object representing the serialized buffer attribute.
|
||||
*/
|
||||
toJSON( data ) {
|
||||
|
||||
if ( data === undefined ) {
|
||||
|
||||
console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );
|
||||
|
||||
const array = [];
|
||||
|
||||
for ( let i = 0; i < this.count; i ++ ) {
|
||||
|
||||
const index = i * this.data.stride + this.offset;
|
||||
|
||||
for ( let j = 0; j < this.itemSize; j ++ ) {
|
||||
|
||||
array.push( this.data.array[ index + j ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// de-interleave data and save it as an ordinary buffer attribute for now
|
||||
|
||||
return {
|
||||
itemSize: this.itemSize,
|
||||
type: this.array.constructor.name,
|
||||
array: array,
|
||||
normalized: this.normalized
|
||||
};
|
||||
|
||||
} else {
|
||||
|
||||
// save as true interleaved attribute
|
||||
|
||||
if ( data.interleavedBuffers === undefined ) {
|
||||
|
||||
data.interleavedBuffers = {};
|
||||
|
||||
}
|
||||
|
||||
if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
|
||||
|
||||
data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
isInterleavedBufferAttribute: true,
|
||||
itemSize: this.itemSize,
|
||||
data: this.data.uuid,
|
||||
offset: this.offset,
|
||||
normalized: this.normalized
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { InterleavedBufferAttribute };
|
||||
121
app/node_modules/three/src/core/Layers.js
generated
vendored
Normal file
121
app/node_modules/three/src/core/Layers.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* A layers object assigns an 3D object to 1 or more of 32
|
||||
* layers numbered `0` to `31` - internally the layers are stored as a
|
||||
* bit mask], and by default all 3D objects are a member of layer `0`.
|
||||
*
|
||||
* This can be used to control visibility - an object must share a layer with
|
||||
* a camera to be visible when that camera's view is
|
||||
* rendered.
|
||||
*
|
||||
* All classes that inherit from {@link Object3D} have an `layers` property which
|
||||
* is an instance of this class.
|
||||
*/
|
||||
class Layers {
|
||||
|
||||
/**
|
||||
* Constructs a new layers instance, with membership
|
||||
* initially set to layer `0`.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
/**
|
||||
* A bit mask storing which of the 32 layers this layers object is currently
|
||||
* a member of.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.mask = 1 | 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets membership to the given layer, and remove membership all other layers.
|
||||
*
|
||||
* @param {number} layer - The layer to set.
|
||||
*/
|
||||
set( layer ) {
|
||||
|
||||
this.mask = ( 1 << layer | 0 ) >>> 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds membership of the given layer.
|
||||
*
|
||||
* @param {number} layer - The layer to enable.
|
||||
*/
|
||||
enable( layer ) {
|
||||
|
||||
this.mask |= 1 << layer | 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds membership to all layers.
|
||||
*/
|
||||
enableAll() {
|
||||
|
||||
this.mask = 0xffffffff | 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the membership of the given layer.
|
||||
*
|
||||
* @param {number} layer - The layer to toggle.
|
||||
*/
|
||||
toggle( layer ) {
|
||||
|
||||
this.mask ^= 1 << layer | 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes membership of the given layer.
|
||||
*
|
||||
* @param {number} layer - The layer to enable.
|
||||
*/
|
||||
disable( layer ) {
|
||||
|
||||
this.mask &= ~ ( 1 << layer | 0 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the membership from all layers.
|
||||
*/
|
||||
disableAll() {
|
||||
|
||||
this.mask = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if this and the given layers object have at least one
|
||||
* layer in common.
|
||||
*
|
||||
* @param {Layers} layers - The layers to test.
|
||||
* @return {boolean } Whether this and the given layers object have at least one layer in common or not.
|
||||
*/
|
||||
test( layers ) {
|
||||
|
||||
return ( this.mask & layers.mask ) !== 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the given layer is enabled.
|
||||
*
|
||||
* @param {number} layer - The layer to test.
|
||||
* @return {boolean } Whether the given layer is enabled or not.
|
||||
*/
|
||||
isEnabled( layer ) {
|
||||
|
||||
return ( this.mask & ( 1 << layer | 0 ) ) !== 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { Layers };
|
||||
1618
app/node_modules/three/src/core/Object3D.js
generated
vendored
Normal file
1618
app/node_modules/three/src/core/Object3D.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
261
app/node_modules/three/src/core/Raycaster.js
generated
vendored
Normal file
261
app/node_modules/three/src/core/Raycaster.js
generated
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
import { Matrix4 } from '../math/Matrix4.js';
|
||||
import { Ray } from '../math/Ray.js';
|
||||
import { Layers } from './Layers.js';
|
||||
|
||||
const _matrix = /*@__PURE__*/ new Matrix4();
|
||||
|
||||
/**
|
||||
* This class is designed to assist with raycasting. Raycasting is used for
|
||||
* mouse picking (working out what objects in the 3d space the mouse is over)
|
||||
* amongst other things.
|
||||
*/
|
||||
class Raycaster {
|
||||
|
||||
/**
|
||||
* Constructs a new raycaster.
|
||||
*
|
||||
* @param {Vector3} origin - The origin vector where the ray casts from.
|
||||
* @param {Vector3} direction - The (normalized) direction vector that gives direction to the ray.
|
||||
* @param {number} [near=0] - All results returned are further away than near. Near can't be negative.
|
||||
* @param {number} [far=Infinity] - All results returned are closer than far. Far can't be lower than near.
|
||||
*/
|
||||
constructor( origin, direction, near = 0, far = Infinity ) {
|
||||
|
||||
/**
|
||||
* The ray used for raycasting.
|
||||
*
|
||||
* @type {Ray}
|
||||
*/
|
||||
this.ray = new Ray( origin, direction );
|
||||
|
||||
/**
|
||||
* All results returned are further away than near. Near can't be negative.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.near = near;
|
||||
|
||||
/**
|
||||
* All results returned are further away than near. Near can't be negative.
|
||||
*
|
||||
* @type {number}
|
||||
* @default Infinity
|
||||
*/
|
||||
this.far = far;
|
||||
|
||||
/**
|
||||
* The camera to use when raycasting against view-dependent objects such as
|
||||
* billboarded objects like sprites. This field can be set manually or
|
||||
* is set when calling `setFromCamera()`.
|
||||
*
|
||||
* @type {?Camera}
|
||||
* @default null
|
||||
*/
|
||||
this.camera = null;
|
||||
|
||||
/**
|
||||
* Allows to selectively ignore 3D objects when performing intersection tests.
|
||||
* The following code example ensures that only 3D objects on layer `1` will be
|
||||
* honored by raycaster.
|
||||
* ```js
|
||||
* raycaster.layers.set( 1 );
|
||||
* object.layers.enable( 1 );
|
||||
* ```
|
||||
*
|
||||
* @type {Layers}
|
||||
*/
|
||||
this.layers = new Layers();
|
||||
|
||||
|
||||
/**
|
||||
* A parameter object that configures the raycasting. It has the structure:
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
* Mesh: {},
|
||||
* Line: { threshold: 1 },
|
||||
* LOD: {},
|
||||
* Points: { threshold: 1 },
|
||||
* Sprite: {}
|
||||
* }
|
||||
* ```
|
||||
* Where `threshold` is the precision of the raycaster when intersecting objects, in world units.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.params = {
|
||||
Mesh: {},
|
||||
Line: { threshold: 1 },
|
||||
LOD: {},
|
||||
Points: { threshold: 1 },
|
||||
Sprite: {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the ray with a new origin and direction by copying the values from the arguments.
|
||||
*
|
||||
* @param {Vector3} origin - The origin vector where the ray casts from.
|
||||
* @param {Vector3} direction - The (normalized) direction vector that gives direction to the ray.
|
||||
*/
|
||||
set( origin, direction ) {
|
||||
|
||||
// direction is assumed to be normalized (for accurate distance calculations)
|
||||
|
||||
this.ray.set( origin, direction );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the given coordinates and camera to compute a new origin and direction for the internal ray.
|
||||
*
|
||||
* @param {Vector2} coords - 2D coordinates of the mouse, in normalized device coordinates (NDC).
|
||||
* X and Y components should be between `-1` and `1`.
|
||||
* @param {Camera} camera - The camera from which the ray should originate.
|
||||
*/
|
||||
setFromCamera( coords, camera ) {
|
||||
|
||||
if ( camera.isPerspectiveCamera ) {
|
||||
|
||||
this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
|
||||
this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
|
||||
this.camera = camera;
|
||||
|
||||
} else if ( camera.isOrthographicCamera ) {
|
||||
|
||||
this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
|
||||
this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
|
||||
this.camera = camera;
|
||||
|
||||
} else {
|
||||
|
||||
console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the given WebXR controller to compute a new origin and direction for the internal ray.
|
||||
*
|
||||
* @param {WebXRController} controller - The controller to copy the position and direction from.
|
||||
* @return {Raycaster} A reference to this raycaster.
|
||||
*/
|
||||
setFromXRController( controller ) {
|
||||
|
||||
_matrix.identity().extractRotation( controller.matrixWorld );
|
||||
|
||||
this.ray.origin.setFromMatrixPosition( controller.matrixWorld );
|
||||
this.ray.direction.set( 0, 0, - 1 ).applyMatrix4( _matrix );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The intersection point of a raycaster intersection test.
|
||||
* @typedef {Object} Raycaster~Intersection
|
||||
* @property {number} distance - The distance from the ray's origin to the intersection point.
|
||||
* @property {number} distanceToRay - Some 3D objects e.g. {@link Points} provide the distance of the
|
||||
* intersection to the nearest point on the ray. For other objects it will be `undefined`.
|
||||
* @property {Vector3} point - The intersection point, in world coordinates.
|
||||
* @property {Object} face - The face that has been intersected.
|
||||
* @property {number} faceIndex - The face index.
|
||||
* @property {Object3D} object - The 3D object that has been intersected.
|
||||
* @property {Vector2} uv - U,V coordinates at point of intersection.
|
||||
* @property {Vector2} uv1 - Second set of U,V coordinates at point of intersection.
|
||||
* @property {Vector3} uv1 - Interpolated normal vector at point of intersection.
|
||||
* @property {number} instanceId - The index number of the instance where the ray
|
||||
* intersects the {@link InstancedMesh}.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks all intersection between the ray and the object with or without the
|
||||
* descendants. Intersections are returned sorted by distance, closest first.
|
||||
*
|
||||
* `Raycaster` delegates to the `raycast()` method of the passed 3D object, when
|
||||
* evaluating whether the ray intersects the object or not. This allows meshes to respond
|
||||
* differently to ray casting than lines or points.
|
||||
*
|
||||
* Note that for meshes, faces must be pointed towards the origin of the ray in order
|
||||
* to be detected; intersections of the ray passing through the back of a face will not
|
||||
* be detected. To raycast against both faces of an object, you'll want to set {@link Material#side}
|
||||
* to `THREE.DoubleSide`.
|
||||
*
|
||||
* @param {Object3D} object - The 3D object to check for intersection with the ray.
|
||||
* @param {boolean} [recursive=true] - If set to `true`, it also checks all descendants.
|
||||
* Otherwise it only checks intersection with the object.
|
||||
* @param {Array<Raycaster~Intersection>} [intersects=[]] The target array that holds the result of the method.
|
||||
* @return {Array<Raycaster~Intersection>} An array holding the intersection points.
|
||||
*/
|
||||
intersectObject( object, recursive = true, intersects = [] ) {
|
||||
|
||||
intersect( object, this, intersects, recursive );
|
||||
|
||||
intersects.sort( ascSort );
|
||||
|
||||
return intersects;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks all intersection between the ray and the objects with or without
|
||||
* the descendants. Intersections are returned sorted by distance, closest first.
|
||||
*
|
||||
* @param {Array<Object3D>} objects - The 3D objects to check for intersection with the ray.
|
||||
* @param {boolean} [recursive=true] - If set to `true`, it also checks all descendants.
|
||||
* Otherwise it only checks intersection with the object.
|
||||
* @param {Array<Raycaster~Intersection>} [intersects=[]] The target array that holds the result of the method.
|
||||
* @return {Array<Raycaster~Intersection>} An array holding the intersection points.
|
||||
*/
|
||||
intersectObjects( objects, recursive = true, intersects = [] ) {
|
||||
|
||||
for ( let i = 0, l = objects.length; i < l; i ++ ) {
|
||||
|
||||
intersect( objects[ i ], this, intersects, recursive );
|
||||
|
||||
}
|
||||
|
||||
intersects.sort( ascSort );
|
||||
|
||||
return intersects;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ascSort( a, b ) {
|
||||
|
||||
return a.distance - b.distance;
|
||||
|
||||
}
|
||||
|
||||
function intersect( object, raycaster, intersects, recursive ) {
|
||||
|
||||
let propagate = true;
|
||||
|
||||
if ( object.layers.test( raycaster.layers ) ) {
|
||||
|
||||
const result = object.raycast( raycaster, intersects );
|
||||
|
||||
if ( result === false ) propagate = false;
|
||||
|
||||
}
|
||||
|
||||
if ( propagate === true && recursive === true ) {
|
||||
|
||||
const children = object.children;
|
||||
|
||||
for ( let i = 0, l = children.length; i < l; i ++ ) {
|
||||
|
||||
intersect( children[ i ], raycaster, intersects, true );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Raycaster };
|
||||
383
app/node_modules/three/src/core/RenderTarget.js
generated
vendored
Normal file
383
app/node_modules/three/src/core/RenderTarget.js
generated
vendored
Normal file
@@ -0,0 +1,383 @@
|
||||
import { EventDispatcher } from './EventDispatcher.js';
|
||||
import { Texture } from '../textures/Texture.js';
|
||||
import { LinearFilter } from '../constants.js';
|
||||
import { Vector4 } from '../math/Vector4.js';
|
||||
import { Source } from '../textures/Source.js';
|
||||
|
||||
/**
|
||||
* A render target is a buffer where the video card draws pixels for a scene
|
||||
* that is being rendered in the background. It is used in different effects,
|
||||
* such as applying postprocessing to a rendered image before displaying it
|
||||
* on the screen.
|
||||
*
|
||||
* @augments EventDispatcher
|
||||
*/
|
||||
class RenderTarget extends EventDispatcher {
|
||||
|
||||
/**
|
||||
* Render target options.
|
||||
*
|
||||
* @typedef {Object} RenderTarget~Options
|
||||
* @property {boolean} [generateMipmaps=false] - Whether to generate mipmaps or not.
|
||||
* @property {number} [magFilter=LinearFilter] - The mag filter.
|
||||
* @property {number} [minFilter=LinearFilter] - The min filter.
|
||||
* @property {number} [format=RGBAFormat] - The texture format.
|
||||
* @property {number} [type=UnsignedByteType] - The texture type.
|
||||
* @property {?string} [internalFormat=null] - The texture's internal format.
|
||||
* @property {number} [wrapS=ClampToEdgeWrapping] - The texture's uv wrapping mode.
|
||||
* @property {number} [wrapT=ClampToEdgeWrapping] - The texture's uv wrapping mode.
|
||||
* @property {number} [anisotropy=1] - The texture's anisotropy value.
|
||||
* @property {string} [colorSpace=NoColorSpace] - The texture's color space.
|
||||
* @property {boolean} [depthBuffer=true] - Whether to allocate a depth buffer or not.
|
||||
* @property {boolean} [stencilBuffer=false] - Whether to allocate a stencil buffer or not.
|
||||
* @property {boolean} [resolveDepthBuffer=true] - Whether to resolve the depth buffer or not.
|
||||
* @property {boolean} [resolveStencilBuffer=true] - Whether to resolve the stencil buffer or not.
|
||||
* @property {?Texture} [depthTexture=null] - Reference to a depth texture.
|
||||
* @property {number} [samples=0] - The MSAA samples count.
|
||||
* @property {number} [count=1] - Defines the number of color attachments . Must be at least `1`.
|
||||
* @property {number} [depth=1] - The texture depth.
|
||||
* @property {boolean} [multiview=false] - Whether this target is used for multiview rendering.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructs a new render target.
|
||||
*
|
||||
* @param {number} [width=1] - The width of the render target.
|
||||
* @param {number} [height=1] - The height of the render target.
|
||||
* @param {RenderTarget~Options} [options] - The configuration object.
|
||||
*/
|
||||
constructor( width = 1, height = 1, options = {} ) {
|
||||
|
||||
super();
|
||||
|
||||
options = Object.assign( {
|
||||
generateMipmaps: false,
|
||||
internalFormat: null,
|
||||
minFilter: LinearFilter,
|
||||
depthBuffer: true,
|
||||
stencilBuffer: false,
|
||||
resolveDepthBuffer: true,
|
||||
resolveStencilBuffer: true,
|
||||
depthTexture: null,
|
||||
samples: 0,
|
||||
count: 1,
|
||||
depth: 1,
|
||||
multiview: false
|
||||
}, options );
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isRenderTarget = true;
|
||||
|
||||
/**
|
||||
* The width of the render target.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.width = width;
|
||||
|
||||
/**
|
||||
* The height of the render target.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.height = height;
|
||||
|
||||
/**
|
||||
* The depth of the render target.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.depth = options.depth;
|
||||
|
||||
/**
|
||||
* A rectangular area inside the render target's viewport. Fragments that are
|
||||
* outside the area will be discarded.
|
||||
*
|
||||
* @type {Vector4}
|
||||
* @default (0,0,width,height)
|
||||
*/
|
||||
this.scissor = new Vector4( 0, 0, width, height );
|
||||
|
||||
/**
|
||||
* Indicates whether the scissor test should be enabled when rendering into
|
||||
* this render target or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.scissorTest = false;
|
||||
|
||||
/**
|
||||
* A rectangular area representing the render target's viewport.
|
||||
*
|
||||
* @type {Vector4}
|
||||
* @default (0,0,width,height)
|
||||
*/
|
||||
this.viewport = new Vector4( 0, 0, width, height );
|
||||
|
||||
const image = { width: width, height: height, depth: options.depth };
|
||||
|
||||
const texture = new Texture( image );
|
||||
|
||||
/**
|
||||
* An array of textures. Each color attachment is represented as a separate texture.
|
||||
* Has at least a single entry for the default color attachment.
|
||||
*
|
||||
* @type {Array<Texture>}
|
||||
*/
|
||||
this.textures = [];
|
||||
|
||||
const count = options.count;
|
||||
for ( let i = 0; i < count; i ++ ) {
|
||||
|
||||
this.textures[ i ] = texture.clone();
|
||||
this.textures[ i ].isRenderTargetTexture = true;
|
||||
this.textures[ i ].renderTarget = this;
|
||||
|
||||
}
|
||||
|
||||
this._setTextureOptions( options );
|
||||
|
||||
/**
|
||||
* Whether to allocate a depth buffer or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.depthBuffer = options.depthBuffer;
|
||||
|
||||
/**
|
||||
* Whether to allocate a stencil buffer or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.stencilBuffer = options.stencilBuffer;
|
||||
|
||||
/**
|
||||
* Whether to resolve the depth buffer or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.resolveDepthBuffer = options.resolveDepthBuffer;
|
||||
|
||||
/**
|
||||
* Whether to resolve the stencil buffer or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.resolveStencilBuffer = options.resolveStencilBuffer;
|
||||
|
||||
this._depthTexture = null;
|
||||
this.depthTexture = options.depthTexture;
|
||||
|
||||
/**
|
||||
* The number of MSAA samples.
|
||||
*
|
||||
* A value of `0` disables MSAA.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.samples = options.samples;
|
||||
|
||||
/**
|
||||
* Whether to this target is used in multiview rendering.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.multiview = options.multiview;
|
||||
|
||||
}
|
||||
|
||||
_setTextureOptions( options = {} ) {
|
||||
|
||||
const values = {
|
||||
minFilter: LinearFilter,
|
||||
generateMipmaps: false,
|
||||
flipY: false,
|
||||
internalFormat: null
|
||||
};
|
||||
|
||||
if ( options.mapping !== undefined ) values.mapping = options.mapping;
|
||||
if ( options.wrapS !== undefined ) values.wrapS = options.wrapS;
|
||||
if ( options.wrapT !== undefined ) values.wrapT = options.wrapT;
|
||||
if ( options.wrapR !== undefined ) values.wrapR = options.wrapR;
|
||||
if ( options.magFilter !== undefined ) values.magFilter = options.magFilter;
|
||||
if ( options.minFilter !== undefined ) values.minFilter = options.minFilter;
|
||||
if ( options.format !== undefined ) values.format = options.format;
|
||||
if ( options.type !== undefined ) values.type = options.type;
|
||||
if ( options.anisotropy !== undefined ) values.anisotropy = options.anisotropy;
|
||||
if ( options.colorSpace !== undefined ) values.colorSpace = options.colorSpace;
|
||||
if ( options.flipY !== undefined ) values.flipY = options.flipY;
|
||||
if ( options.generateMipmaps !== undefined ) values.generateMipmaps = options.generateMipmaps;
|
||||
if ( options.internalFormat !== undefined ) values.internalFormat = options.internalFormat;
|
||||
|
||||
for ( let i = 0; i < this.textures.length; i ++ ) {
|
||||
|
||||
const texture = this.textures[ i ];
|
||||
texture.setValues( values );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The texture representing the default color attachment.
|
||||
*
|
||||
* @type {Texture}
|
||||
*/
|
||||
get texture() {
|
||||
|
||||
return this.textures[ 0 ];
|
||||
|
||||
}
|
||||
|
||||
set texture( value ) {
|
||||
|
||||
this.textures[ 0 ] = value;
|
||||
|
||||
}
|
||||
|
||||
set depthTexture( current ) {
|
||||
|
||||
if ( this._depthTexture !== null ) this._depthTexture.renderTarget = null;
|
||||
if ( current !== null ) current.renderTarget = this;
|
||||
|
||||
this._depthTexture = current;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instead of saving the depth in a renderbuffer, a texture
|
||||
* can be used instead which is useful for further processing
|
||||
* e.g. in context of post-processing.
|
||||
*
|
||||
* @type {?DepthTexture}
|
||||
* @default null
|
||||
*/
|
||||
get depthTexture() {
|
||||
|
||||
return this._depthTexture;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of this render target.
|
||||
*
|
||||
* @param {number} width - The width.
|
||||
* @param {number} height - The height.
|
||||
* @param {number} [depth=1] - The depth.
|
||||
*/
|
||||
setSize( width, height, depth = 1 ) {
|
||||
|
||||
if ( this.width !== width || this.height !== height || this.depth !== depth ) {
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = depth;
|
||||
|
||||
for ( let i = 0, il = this.textures.length; i < il; i ++ ) {
|
||||
|
||||
this.textures[ i ].image.width = width;
|
||||
this.textures[ i ].image.height = height;
|
||||
this.textures[ i ].image.depth = depth;
|
||||
this.textures[ i ].isArrayTexture = this.textures[ i ].image.depth > 1;
|
||||
|
||||
}
|
||||
|
||||
this.dispose();
|
||||
|
||||
}
|
||||
|
||||
this.viewport.set( 0, 0, width, height );
|
||||
this.scissor.set( 0, 0, width, height );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new render target with copied values from this instance.
|
||||
*
|
||||
* @return {RenderTarget} A clone of this instance.
|
||||
*/
|
||||
clone() {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the settings of the given render target. This is a structural copy so
|
||||
* no resources are shared between render targets after the copy. That includes
|
||||
* all MRT textures and the depth texture.
|
||||
*
|
||||
* @param {RenderTarget} source - The render target to copy.
|
||||
* @return {RenderTarget} A reference to this instance.
|
||||
*/
|
||||
copy( source ) {
|
||||
|
||||
this.width = source.width;
|
||||
this.height = source.height;
|
||||
this.depth = source.depth;
|
||||
|
||||
this.scissor.copy( source.scissor );
|
||||
this.scissorTest = source.scissorTest;
|
||||
|
||||
this.viewport.copy( source.viewport );
|
||||
|
||||
this.textures.length = 0;
|
||||
|
||||
for ( let i = 0, il = source.textures.length; i < il; i ++ ) {
|
||||
|
||||
this.textures[ i ] = source.textures[ i ].clone();
|
||||
this.textures[ i ].isRenderTargetTexture = true;
|
||||
this.textures[ i ].renderTarget = this;
|
||||
|
||||
// ensure image object is not shared, see #20328
|
||||
|
||||
const image = Object.assign( {}, source.textures[ i ].image );
|
||||
this.textures[ i ].source = new Source( image );
|
||||
|
||||
}
|
||||
|
||||
this.depthBuffer = source.depthBuffer;
|
||||
this.stencilBuffer = source.stencilBuffer;
|
||||
|
||||
this.resolveDepthBuffer = source.resolveDepthBuffer;
|
||||
this.resolveStencilBuffer = source.resolveStencilBuffer;
|
||||
|
||||
if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();
|
||||
|
||||
this.samples = source.samples;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever this instance is no longer used in your app.
|
||||
*
|
||||
* @fires RenderTarget#dispose
|
||||
*/
|
||||
dispose() {
|
||||
|
||||
this.dispatchEvent( { type: 'dispose' } );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { RenderTarget };
|
||||
48
app/node_modules/three/src/core/RenderTarget3D.js
generated
vendored
Normal file
48
app/node_modules/three/src/core/RenderTarget3D.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import { RenderTarget } from './RenderTarget.js';
|
||||
import { Data3DTexture } from '../textures/Data3DTexture.js';
|
||||
|
||||
/**
|
||||
* Represents a 3D render target.
|
||||
*
|
||||
* @augments RenderTarget
|
||||
*/
|
||||
class RenderTarget3D extends RenderTarget {
|
||||
|
||||
/**
|
||||
* Constructs a new 3D render target.
|
||||
*
|
||||
* @param {number} [width=1] - The width of the render target.
|
||||
* @param {number} [height=1] - The height of the render target.
|
||||
* @param {number} [depth=1] - The height of the render target.
|
||||
* @param {RenderTarget~Options} [options] - The configuration object.
|
||||
*/
|
||||
constructor( width = 1, height = 1, depth = 1, options = {} ) {
|
||||
|
||||
super( width, height, options );
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isRenderTarget3D = true;
|
||||
|
||||
this.depth = depth;
|
||||
|
||||
/**
|
||||
* Overwritten with a different texture type.
|
||||
*
|
||||
* @type {Data3DTexture}
|
||||
*/
|
||||
this.texture = new Data3DTexture( null, width, height, depth );
|
||||
this._setTextureOptions( options );
|
||||
|
||||
this.texture.isRenderTargetTexture = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { RenderTarget3D };
|
||||
46
app/node_modules/three/src/core/Uniform.js
generated
vendored
Normal file
46
app/node_modules/three/src/core/Uniform.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Represents a uniform which is a global shader variable. They are passed to shader programs.
|
||||
*
|
||||
* When declaring a uniform of a {@link ShaderMaterial}, it is declared by value or by object.
|
||||
* ```js
|
||||
* uniforms: {
|
||||
* time: { value: 1.0 },
|
||||
* resolution: new Uniform( new Vector2() )
|
||||
* };
|
||||
* ```
|
||||
* Since this class can only be used in context of {@link ShaderMaterial}, it is only supported
|
||||
* in {@link WebGLRenderer}.
|
||||
*/
|
||||
class Uniform {
|
||||
|
||||
/**
|
||||
* Constructs a new uniform.
|
||||
*
|
||||
* @param {any} value - The uniform value.
|
||||
*/
|
||||
constructor( value ) {
|
||||
|
||||
/**
|
||||
* The uniform value.
|
||||
*
|
||||
* @type {any}
|
||||
*/
|
||||
this.value = value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new uniform with copied values from this instance.
|
||||
* If the value has a `clone()` method, the value is cloned as well.
|
||||
*
|
||||
* @return {Uniform} A clone of this instance.
|
||||
*/
|
||||
clone() {
|
||||
|
||||
return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Uniform };
|
||||
180
app/node_modules/three/src/core/UniformsGroup.js
generated
vendored
Normal file
180
app/node_modules/three/src/core/UniformsGroup.js
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
import { EventDispatcher } from './EventDispatcher.js';
|
||||
import { StaticDrawUsage } from '../constants.js';
|
||||
|
||||
let _id = 0;
|
||||
|
||||
/**
|
||||
* A class for managing multiple uniforms in a single group. The renderer will process
|
||||
* such a definition as a single UBO.
|
||||
*
|
||||
* Since this class can only be used in context of {@link ShaderMaterial}, it is only supported
|
||||
* in {@link WebGLRenderer}.
|
||||
*
|
||||
* @augments EventDispatcher
|
||||
*/
|
||||
class UniformsGroup extends EventDispatcher {
|
||||
|
||||
/**
|
||||
* Constructs a new uniforms group.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isUniformsGroup = true;
|
||||
|
||||
/**
|
||||
* The ID of the 3D object.
|
||||
*
|
||||
* @name UniformsGroup#id
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty( this, 'id', { value: _id ++ } );
|
||||
|
||||
/**
|
||||
* The name of the uniforms group.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* The buffer usage.
|
||||
*
|
||||
* @type {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)}
|
||||
* @default StaticDrawUsage
|
||||
*/
|
||||
this.usage = StaticDrawUsage;
|
||||
|
||||
/**
|
||||
* An array holding the uniforms.
|
||||
*
|
||||
* @type {Array<Uniform>}
|
||||
*/
|
||||
this.uniforms = [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given uniform to this uniforms group.
|
||||
*
|
||||
* @param {Uniform} uniform - The uniform to add.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
add( uniform ) {
|
||||
|
||||
this.uniforms.push( uniform );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given uniform from this uniforms group.
|
||||
*
|
||||
* @param {Uniform} uniform - The uniform to remove.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
remove( uniform ) {
|
||||
|
||||
const index = this.uniforms.indexOf( uniform );
|
||||
|
||||
if ( index !== - 1 ) this.uniforms.splice( index, 1 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of this uniforms group.
|
||||
*
|
||||
* @param {string} name - The name to set.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
setName( name ) {
|
||||
|
||||
this.name = name;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the usage of this uniforms group.
|
||||
*
|
||||
* @param {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)} value - The usage to set.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
setUsage( value ) {
|
||||
|
||||
this.usage = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever this instance is no longer used in your app.
|
||||
*
|
||||
* @fires Texture#dispose
|
||||
*/
|
||||
dispose() {
|
||||
|
||||
this.dispatchEvent( { type: 'dispose' } );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the values of the given uniforms group to this instance.
|
||||
*
|
||||
* @param {UniformsGroup} source - The uniforms group to copy.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
copy( source ) {
|
||||
|
||||
this.name = source.name;
|
||||
this.usage = source.usage;
|
||||
|
||||
const uniformsSource = source.uniforms;
|
||||
|
||||
this.uniforms.length = 0;
|
||||
|
||||
for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {
|
||||
|
||||
const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];
|
||||
|
||||
for ( let j = 0; j < uniforms.length; j ++ ) {
|
||||
|
||||
this.uniforms.push( uniforms[ j ].clone() );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new uniforms group with copied values from this instance.
|
||||
*
|
||||
* @return {UniformsGroup} A clone of this instance.
|
||||
*/
|
||||
clone() {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { UniformsGroup };
|
||||
Reference in New Issue
Block a user