webvr js meetup initial commit
This commit is contained in:
1453
node_modules/three/src/Three.Legacy.js
generated
vendored
Normal file
1453
node_modules/three/src/Three.Legacy.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
156
node_modules/three/src/Three.js
generated
vendored
Normal file
156
node_modules/three/src/Three.js
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
import './polyfills.js';
|
||||
|
||||
export { WebGLRenderTargetCube } from './renderers/WebGLRenderTargetCube.js';
|
||||
export { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js';
|
||||
export { WebGLRenderer } from './renderers/WebGLRenderer.js';
|
||||
// export { WebGL2Renderer } from './renderers/WebGL2Renderer.js';
|
||||
export { ShaderLib } from './renderers/shaders/ShaderLib.js';
|
||||
export { UniformsLib } from './renderers/shaders/UniformsLib.js';
|
||||
export { UniformsUtils } from './renderers/shaders/UniformsUtils.js';
|
||||
export { ShaderChunk } from './renderers/shaders/ShaderChunk.js';
|
||||
export { FogExp2 } from './scenes/FogExp2.js';
|
||||
export { Fog } from './scenes/Fog.js';
|
||||
export { Scene } from './scenes/Scene.js';
|
||||
export { LensFlare } from './objects/LensFlare.js';
|
||||
export { Sprite } from './objects/Sprite.js';
|
||||
export { LOD } from './objects/LOD.js';
|
||||
export { SkinnedMesh } from './objects/SkinnedMesh.js';
|
||||
export { Skeleton } from './objects/Skeleton.js';
|
||||
export { Bone } from './objects/Bone.js';
|
||||
export { Mesh } from './objects/Mesh.js';
|
||||
export { LineSegments } from './objects/LineSegments.js';
|
||||
export { Line } from './objects/Line.js';
|
||||
export { Points } from './objects/Points.js';
|
||||
export { Group } from './objects/Group.js';
|
||||
export { VideoTexture } from './textures/VideoTexture.js';
|
||||
export { DataTexture } from './textures/DataTexture.js';
|
||||
export { CompressedTexture } from './textures/CompressedTexture.js';
|
||||
export { CubeTexture } from './textures/CubeTexture.js';
|
||||
export { CanvasTexture } from './textures/CanvasTexture.js';
|
||||
export { DepthTexture } from './textures/DepthTexture.js';
|
||||
export { Texture } from './textures/Texture.js';
|
||||
export * from './geometries/Geometries.js';
|
||||
export * from './materials/Materials.js';
|
||||
export { CompressedTextureLoader } from './loaders/CompressedTextureLoader.js';
|
||||
export { DataTextureLoader } from './loaders/DataTextureLoader.js';
|
||||
export { CubeTextureLoader } from './loaders/CubeTextureLoader.js';
|
||||
export { TextureLoader } from './loaders/TextureLoader.js';
|
||||
export { ObjectLoader } from './loaders/ObjectLoader.js';
|
||||
export { MaterialLoader } from './loaders/MaterialLoader.js';
|
||||
export { BufferGeometryLoader } from './loaders/BufferGeometryLoader.js';
|
||||
export { DefaultLoadingManager, LoadingManager } from './loaders/LoadingManager.js';
|
||||
export { JSONLoader } from './loaders/JSONLoader.js';
|
||||
export { ImageLoader } from './loaders/ImageLoader.js';
|
||||
export { FontLoader } from './loaders/FontLoader.js';
|
||||
export { FileLoader } from './loaders/FileLoader.js';
|
||||
export { Loader } from './loaders/Loader.js';
|
||||
export { Cache } from './loaders/Cache.js';
|
||||
export { AudioLoader } from './loaders/AudioLoader.js';
|
||||
export { SpotLightShadow } from './lights/SpotLightShadow.js';
|
||||
export { SpotLight } from './lights/SpotLight.js';
|
||||
export { PointLight } from './lights/PointLight.js';
|
||||
export { RectAreaLight } from './lights/RectAreaLight.js';
|
||||
export { HemisphereLight } from './lights/HemisphereLight.js';
|
||||
export { DirectionalLightShadow } from './lights/DirectionalLightShadow.js';
|
||||
export { DirectionalLight } from './lights/DirectionalLight.js';
|
||||
export { AmbientLight } from './lights/AmbientLight.js';
|
||||
export { LightShadow } from './lights/LightShadow.js';
|
||||
export { Light } from './lights/Light.js';
|
||||
export { StereoCamera } from './cameras/StereoCamera.js';
|
||||
export { PerspectiveCamera } from './cameras/PerspectiveCamera.js';
|
||||
export { OrthographicCamera } from './cameras/OrthographicCamera.js';
|
||||
export { CubeCamera } from './cameras/CubeCamera.js';
|
||||
export { Camera } from './cameras/Camera.js';
|
||||
export { AudioListener } from './audio/AudioListener.js';
|
||||
export { PositionalAudio } from './audio/PositionalAudio.js';
|
||||
export { AudioContext } from './audio/AudioContext.js';
|
||||
export { AudioAnalyser } from './audio/AudioAnalyser.js';
|
||||
export { Audio } from './audio/Audio.js';
|
||||
export { VectorKeyframeTrack } from './animation/tracks/VectorKeyframeTrack.js';
|
||||
export { StringKeyframeTrack } from './animation/tracks/StringKeyframeTrack.js';
|
||||
export { QuaternionKeyframeTrack } from './animation/tracks/QuaternionKeyframeTrack.js';
|
||||
export { NumberKeyframeTrack } from './animation/tracks/NumberKeyframeTrack.js';
|
||||
export { ColorKeyframeTrack } from './animation/tracks/ColorKeyframeTrack.js';
|
||||
export { BooleanKeyframeTrack } from './animation/tracks/BooleanKeyframeTrack.js';
|
||||
export { PropertyMixer } from './animation/PropertyMixer.js';
|
||||
export { PropertyBinding } from './animation/PropertyBinding.js';
|
||||
export { KeyframeTrack } from './animation/KeyframeTrack.js';
|
||||
export { AnimationUtils } from './animation/AnimationUtils.js';
|
||||
export { AnimationObjectGroup } from './animation/AnimationObjectGroup.js';
|
||||
export { AnimationMixer } from './animation/AnimationMixer.js';
|
||||
export { AnimationClip } from './animation/AnimationClip.js';
|
||||
export { Uniform } from './core/Uniform.js';
|
||||
export { InstancedBufferGeometry } from './core/InstancedBufferGeometry.js';
|
||||
export { BufferGeometry } from './core/BufferGeometry.js';
|
||||
export { GeometryIdCount, Geometry } from './core/Geometry.js';
|
||||
export { InterleavedBufferAttribute } from './core/InterleavedBufferAttribute.js';
|
||||
export { InstancedInterleavedBuffer } from './core/InstancedInterleavedBuffer.js';
|
||||
export { InterleavedBuffer } from './core/InterleavedBuffer.js';
|
||||
export { InstancedBufferAttribute } from './core/InstancedBufferAttribute.js';
|
||||
export * from './core/BufferAttribute.js';
|
||||
export { Face3 } from './core/Face3.js';
|
||||
export { Object3D } from './core/Object3D.js';
|
||||
export { Raycaster } from './core/Raycaster.js';
|
||||
export { Layers } from './core/Layers.js';
|
||||
export { EventDispatcher } from './core/EventDispatcher.js';
|
||||
export { Clock } from './core/Clock.js';
|
||||
export { QuaternionLinearInterpolant } from './math/interpolants/QuaternionLinearInterpolant.js';
|
||||
export { LinearInterpolant } from './math/interpolants/LinearInterpolant.js';
|
||||
export { DiscreteInterpolant } from './math/interpolants/DiscreteInterpolant.js';
|
||||
export { CubicInterpolant } from './math/interpolants/CubicInterpolant.js';
|
||||
export { Interpolant } from './math/Interpolant.js';
|
||||
export { Triangle } from './math/Triangle.js';
|
||||
export { _Math as Math } from './math/Math.js';
|
||||
export { Spherical } from './math/Spherical.js';
|
||||
export { Cylindrical } from './math/Cylindrical.js';
|
||||
export { Plane } from './math/Plane.js';
|
||||
export { Frustum } from './math/Frustum.js';
|
||||
export { Sphere } from './math/Sphere.js';
|
||||
export { Ray } from './math/Ray.js';
|
||||
export { Matrix4 } from './math/Matrix4.js';
|
||||
export { Matrix3 } from './math/Matrix3.js';
|
||||
export { Box3 } from './math/Box3.js';
|
||||
export { Box2 } from './math/Box2.js';
|
||||
export { Line3 } from './math/Line3.js';
|
||||
export { Euler } from './math/Euler.js';
|
||||
export { Vector4 } from './math/Vector4.js';
|
||||
export { Vector3 } from './math/Vector3.js';
|
||||
export { Vector2 } from './math/Vector2.js';
|
||||
export { Quaternion } from './math/Quaternion.js';
|
||||
export { Color } from './math/Color.js';
|
||||
export { MorphBlendMesh } from './extras/objects/MorphBlendMesh.js';
|
||||
export { ImmediateRenderObject } from './extras/objects/ImmediateRenderObject.js';
|
||||
export { VertexNormalsHelper } from './helpers/VertexNormalsHelper.js';
|
||||
export { SpotLightHelper } from './helpers/SpotLightHelper.js';
|
||||
export { SkeletonHelper } from './helpers/SkeletonHelper.js';
|
||||
export { PointLightHelper } from './helpers/PointLightHelper.js';
|
||||
export { RectAreaLightHelper } from './helpers/RectAreaLightHelper.js';
|
||||
export { HemisphereLightHelper } from './helpers/HemisphereLightHelper.js';
|
||||
export { GridHelper } from './helpers/GridHelper.js';
|
||||
export { PolarGridHelper } from './helpers/PolarGridHelper.js';
|
||||
export { FaceNormalsHelper } from './helpers/FaceNormalsHelper.js';
|
||||
export { DirectionalLightHelper } from './helpers/DirectionalLightHelper.js';
|
||||
export { CameraHelper } from './helpers/CameraHelper.js';
|
||||
export { BoxHelper } from './helpers/BoxHelper.js';
|
||||
export { ArrowHelper } from './helpers/ArrowHelper.js';
|
||||
export { AxisHelper } from './helpers/AxisHelper.js';
|
||||
export { CatmullRomCurve3 } from './extras/curves/CatmullRomCurve3.js';
|
||||
export { CubicBezierCurve3 } from './extras/curves/CubicBezierCurve3.js';
|
||||
export { QuadraticBezierCurve3 } from './extras/curves/QuadraticBezierCurve3.js';
|
||||
export { LineCurve3 } from './extras/curves/LineCurve3.js';
|
||||
export { ArcCurve } from './extras/curves/ArcCurve.js';
|
||||
export { EllipseCurve } from './extras/curves/EllipseCurve.js';
|
||||
export { SplineCurve } from './extras/curves/SplineCurve.js';
|
||||
export { CubicBezierCurve } from './extras/curves/CubicBezierCurve.js';
|
||||
export { QuadraticBezierCurve } from './extras/curves/QuadraticBezierCurve.js';
|
||||
export { LineCurve } from './extras/curves/LineCurve.js';
|
||||
export { Shape } from './extras/core/Shape.js';
|
||||
export { Path } from './extras/core/Path.js';
|
||||
export { ShapePath } from './extras/core/ShapePath.js';
|
||||
export { Font } from './extras/core/Font.js';
|
||||
export { CurvePath } from './extras/core/CurvePath.js';
|
||||
export { Curve } from './extras/core/Curve.js';
|
||||
export { ShapeUtils } from './extras/ShapeUtils.js';
|
||||
export { SceneUtils } from './extras/SceneUtils.js';
|
||||
export * from './constants.js';
|
||||
export * from './Three.Legacy.js';
|
||||
657
node_modules/three/src/animation/AnimationAction.js
generated
vendored
Normal file
657
node_modules/three/src/animation/AnimationAction.js
generated
vendored
Normal file
@@ -0,0 +1,657 @@
|
||||
import { WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, LoopPingPong, LoopOnce, LoopRepeat } from '../constants';
|
||||
|
||||
/**
|
||||
*
|
||||
* Action provided by AnimationMixer for scheduling clip playback on specific
|
||||
* objects.
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*
|
||||
*/
|
||||
|
||||
function AnimationAction( mixer, clip, localRoot ) {
|
||||
|
||||
this._mixer = mixer;
|
||||
this._clip = clip;
|
||||
this._localRoot = localRoot || null;
|
||||
|
||||
var tracks = clip.tracks,
|
||||
nTracks = tracks.length,
|
||||
interpolants = new Array( nTracks );
|
||||
|
||||
var interpolantSettings = {
|
||||
endingStart: ZeroCurvatureEnding,
|
||||
endingEnd: ZeroCurvatureEnding
|
||||
};
|
||||
|
||||
for ( var i = 0; i !== nTracks; ++ i ) {
|
||||
|
||||
var interpolant = tracks[ i ].createInterpolant( null );
|
||||
interpolants[ i ] = interpolant;
|
||||
interpolant.settings = interpolantSettings;
|
||||
|
||||
}
|
||||
|
||||
this._interpolantSettings = interpolantSettings;
|
||||
|
||||
this._interpolants = interpolants; // bound by the mixer
|
||||
|
||||
// inside: PropertyMixer (managed by the mixer)
|
||||
this._propertyBindings = new Array( nTracks );
|
||||
|
||||
this._cacheIndex = null; // for the memory manager
|
||||
this._byClipCacheIndex = null; // for the memory manager
|
||||
|
||||
this._timeScaleInterpolant = null;
|
||||
this._weightInterpolant = null;
|
||||
|
||||
this.loop = LoopRepeat;
|
||||
this._loopCount = -1;
|
||||
|
||||
// global mixer time when the action is to be started
|
||||
// it's set back to 'null' upon start of the action
|
||||
this._startTime = null;
|
||||
|
||||
// scaled local time of the action
|
||||
// gets clamped or wrapped to 0..clip.duration according to loop
|
||||
this.time = 0;
|
||||
|
||||
this.timeScale = 1;
|
||||
this._effectiveTimeScale = 1;
|
||||
|
||||
this.weight = 1;
|
||||
this._effectiveWeight = 1;
|
||||
|
||||
this.repetitions = Infinity; // no. of repetitions when looping
|
||||
|
||||
this.paused = false; // false -> zero effective time scale
|
||||
this.enabled = true; // true -> zero effective weight
|
||||
|
||||
this.clampWhenFinished = false; // keep feeding the last frame?
|
||||
|
||||
this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
|
||||
this.zeroSlopeAtEnd = true; // clips for start, loop and end
|
||||
|
||||
}
|
||||
|
||||
AnimationAction.prototype = {
|
||||
|
||||
constructor: AnimationAction,
|
||||
|
||||
// State & Scheduling
|
||||
|
||||
play: function() {
|
||||
|
||||
this._mixer._activateAction( this );
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
|
||||
this._mixer._deactivateAction( this );
|
||||
|
||||
return this.reset();
|
||||
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
|
||||
this.paused = false;
|
||||
this.enabled = true;
|
||||
|
||||
this.time = 0; // restart clip
|
||||
this._loopCount = -1; // forget previous loops
|
||||
this._startTime = null; // forget scheduling
|
||||
|
||||
return this.stopFading().stopWarping();
|
||||
|
||||
},
|
||||
|
||||
isRunning: function() {
|
||||
|
||||
return this.enabled && ! this.paused && this.timeScale !== 0 &&
|
||||
this._startTime === null && this._mixer._isActiveAction( this );
|
||||
|
||||
},
|
||||
|
||||
// return true when play has been called
|
||||
isScheduled: function() {
|
||||
|
||||
return this._mixer._isActiveAction( this );
|
||||
|
||||
},
|
||||
|
||||
startAt: function( time ) {
|
||||
|
||||
this._startTime = time;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setLoop: function( mode, repetitions ) {
|
||||
|
||||
this.loop = mode;
|
||||
this.repetitions = repetitions;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
// Weight
|
||||
|
||||
// set the weight stopping any scheduled fading
|
||||
// although .enabled = false yields an effective weight of zero, this
|
||||
// method does *not* change .enabled, because it would be confusing
|
||||
setEffectiveWeight: function( weight ) {
|
||||
|
||||
this.weight = weight;
|
||||
|
||||
// note: same logic as when updated at runtime
|
||||
this._effectiveWeight = this.enabled ? weight : 0;
|
||||
|
||||
return this.stopFading();
|
||||
|
||||
},
|
||||
|
||||
// return the weight considering fading and .enabled
|
||||
getEffectiveWeight: function() {
|
||||
|
||||
return this._effectiveWeight;
|
||||
|
||||
},
|
||||
|
||||
fadeIn: function( duration ) {
|
||||
|
||||
return this._scheduleFading( duration, 0, 1 );
|
||||
|
||||
},
|
||||
|
||||
fadeOut: function( duration ) {
|
||||
|
||||
return this._scheduleFading( duration, 1, 0 );
|
||||
|
||||
},
|
||||
|
||||
crossFadeFrom: function( fadeOutAction, duration, warp ) {
|
||||
|
||||
fadeOutAction.fadeOut( duration );
|
||||
this.fadeIn( duration );
|
||||
|
||||
if( warp ) {
|
||||
|
||||
var fadeInDuration = this._clip.duration,
|
||||
fadeOutDuration = fadeOutAction._clip.duration,
|
||||
|
||||
startEndRatio = fadeOutDuration / fadeInDuration,
|
||||
endStartRatio = fadeInDuration / fadeOutDuration;
|
||||
|
||||
fadeOutAction.warp( 1.0, startEndRatio, duration );
|
||||
this.warp( endStartRatio, 1.0, duration );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
crossFadeTo: function( fadeInAction, duration, warp ) {
|
||||
|
||||
return fadeInAction.crossFadeFrom( this, duration, warp );
|
||||
|
||||
},
|
||||
|
||||
stopFading: function() {
|
||||
|
||||
var weightInterpolant = this._weightInterpolant;
|
||||
|
||||
if ( weightInterpolant !== null ) {
|
||||
|
||||
this._weightInterpolant = null;
|
||||
this._mixer._takeBackControlInterpolant( weightInterpolant );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
// Time Scale Control
|
||||
|
||||
// set the weight stopping any scheduled warping
|
||||
// although .paused = true yields an effective time scale of zero, this
|
||||
// method does *not* change .paused, because it would be confusing
|
||||
setEffectiveTimeScale: function( timeScale ) {
|
||||
|
||||
this.timeScale = timeScale;
|
||||
this._effectiveTimeScale = this.paused ? 0 :timeScale;
|
||||
|
||||
return this.stopWarping();
|
||||
|
||||
},
|
||||
|
||||
// return the time scale considering warping and .paused
|
||||
getEffectiveTimeScale: function() {
|
||||
|
||||
return this._effectiveTimeScale;
|
||||
|
||||
},
|
||||
|
||||
setDuration: function( duration ) {
|
||||
|
||||
this.timeScale = this._clip.duration / duration;
|
||||
|
||||
return this.stopWarping();
|
||||
|
||||
},
|
||||
|
||||
syncWith: function( action ) {
|
||||
|
||||
this.time = action.time;
|
||||
this.timeScale = action.timeScale;
|
||||
|
||||
return this.stopWarping();
|
||||
|
||||
},
|
||||
|
||||
halt: function( duration ) {
|
||||
|
||||
return this.warp( this._effectiveTimeScale, 0, duration );
|
||||
|
||||
},
|
||||
|
||||
warp: function( startTimeScale, endTimeScale, duration ) {
|
||||
|
||||
var mixer = this._mixer, now = mixer.time,
|
||||
interpolant = this._timeScaleInterpolant,
|
||||
|
||||
timeScale = this.timeScale;
|
||||
|
||||
if ( interpolant === null ) {
|
||||
|
||||
interpolant = mixer._lendControlInterpolant();
|
||||
this._timeScaleInterpolant = interpolant;
|
||||
|
||||
}
|
||||
|
||||
var times = interpolant.parameterPositions,
|
||||
values = interpolant.sampleValues;
|
||||
|
||||
times[ 0 ] = now;
|
||||
times[ 1 ] = now + duration;
|
||||
|
||||
values[ 0 ] = startTimeScale / timeScale;
|
||||
values[ 1 ] = endTimeScale / timeScale;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
stopWarping: function() {
|
||||
|
||||
var timeScaleInterpolant = this._timeScaleInterpolant;
|
||||
|
||||
if ( timeScaleInterpolant !== null ) {
|
||||
|
||||
this._timeScaleInterpolant = null;
|
||||
this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
// Object Accessors
|
||||
|
||||
getMixer: function() {
|
||||
|
||||
return this._mixer;
|
||||
|
||||
},
|
||||
|
||||
getClip: function() {
|
||||
|
||||
return this._clip;
|
||||
|
||||
},
|
||||
|
||||
getRoot: function() {
|
||||
|
||||
return this._localRoot || this._mixer._root;
|
||||
|
||||
},
|
||||
|
||||
// Interna
|
||||
|
||||
_update: function( time, deltaTime, timeDirection, accuIndex ) {
|
||||
// called by the mixer
|
||||
|
||||
var startTime = this._startTime;
|
||||
|
||||
if ( startTime !== null ) {
|
||||
|
||||
// check for scheduled start of action
|
||||
|
||||
var timeRunning = ( time - startTime ) * timeDirection;
|
||||
if ( timeRunning < 0 || timeDirection === 0 ) {
|
||||
|
||||
return; // yet to come / don't decide when delta = 0
|
||||
|
||||
}
|
||||
|
||||
// start
|
||||
|
||||
this._startTime = null; // unschedule
|
||||
deltaTime = timeDirection * timeRunning;
|
||||
|
||||
}
|
||||
|
||||
// apply time scale and advance time
|
||||
|
||||
deltaTime *= this._updateTimeScale( time );
|
||||
var clipTime = this._updateTime( deltaTime );
|
||||
|
||||
// note: _updateTime may disable the action resulting in
|
||||
// an effective weight of 0
|
||||
|
||||
var weight = this._updateWeight( time );
|
||||
|
||||
if ( weight > 0 ) {
|
||||
|
||||
var interpolants = this._interpolants;
|
||||
var propertyMixers = this._propertyBindings;
|
||||
|
||||
for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
|
||||
|
||||
interpolants[ j ].evaluate( clipTime );
|
||||
propertyMixers[ j ].accumulate( accuIndex, weight );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_updateWeight: function( time ) {
|
||||
|
||||
var weight = 0;
|
||||
|
||||
if ( this.enabled ) {
|
||||
|
||||
weight = this.weight;
|
||||
var interpolant = this._weightInterpolant;
|
||||
|
||||
if ( interpolant !== null ) {
|
||||
|
||||
var interpolantValue = interpolant.evaluate( time )[ 0 ];
|
||||
|
||||
weight *= interpolantValue;
|
||||
|
||||
if ( time > interpolant.parameterPositions[ 1 ] ) {
|
||||
|
||||
this.stopFading();
|
||||
|
||||
if ( interpolantValue === 0 ) {
|
||||
|
||||
// faded out, disable
|
||||
this.enabled = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this._effectiveWeight = weight;
|
||||
return weight;
|
||||
|
||||
},
|
||||
|
||||
_updateTimeScale: function( time ) {
|
||||
|
||||
var timeScale = 0;
|
||||
|
||||
if ( ! this.paused ) {
|
||||
|
||||
timeScale = this.timeScale;
|
||||
|
||||
var interpolant = this._timeScaleInterpolant;
|
||||
|
||||
if ( interpolant !== null ) {
|
||||
|
||||
var interpolantValue = interpolant.evaluate( time )[ 0 ];
|
||||
|
||||
timeScale *= interpolantValue;
|
||||
|
||||
if ( time > interpolant.parameterPositions[ 1 ] ) {
|
||||
|
||||
this.stopWarping();
|
||||
|
||||
if ( timeScale === 0 ) {
|
||||
|
||||
// motion has halted, pause
|
||||
this.paused = true;
|
||||
|
||||
} else {
|
||||
|
||||
// warp done - apply final time scale
|
||||
this.timeScale = timeScale;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this._effectiveTimeScale = timeScale;
|
||||
return timeScale;
|
||||
|
||||
},
|
||||
|
||||
_updateTime: function( deltaTime ) {
|
||||
|
||||
var time = this.time + deltaTime;
|
||||
|
||||
if ( deltaTime === 0 ) return time;
|
||||
|
||||
var duration = this._clip.duration,
|
||||
|
||||
loop = this.loop,
|
||||
loopCount = this._loopCount;
|
||||
|
||||
if ( loop === LoopOnce ) {
|
||||
|
||||
if ( loopCount === -1 ) {
|
||||
// just started
|
||||
|
||||
this._loopCount = 0;
|
||||
this._setEndings( true, true, false );
|
||||
|
||||
}
|
||||
|
||||
handle_stop: {
|
||||
|
||||
if ( time >= duration ) {
|
||||
|
||||
time = duration;
|
||||
|
||||
} else if ( time < 0 ) {
|
||||
|
||||
time = 0;
|
||||
|
||||
} else break handle_stop;
|
||||
|
||||
if ( this.clampWhenFinished ) this.paused = true;
|
||||
else this.enabled = false;
|
||||
|
||||
this._mixer.dispatchEvent( {
|
||||
type: 'finished', action: this,
|
||||
direction: deltaTime < 0 ? -1 : 1
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
} else { // repetitive Repeat or PingPong
|
||||
|
||||
var pingPong = ( loop === LoopPingPong );
|
||||
|
||||
if ( loopCount === -1 ) {
|
||||
// just started
|
||||
|
||||
if ( deltaTime >= 0 ) {
|
||||
|
||||
loopCount = 0;
|
||||
|
||||
this._setEndings(
|
||||
true, this.repetitions === 0, pingPong );
|
||||
|
||||
} else {
|
||||
|
||||
// when looping in reverse direction, the initial
|
||||
// transition through zero counts as a repetition,
|
||||
// so leave loopCount at -1
|
||||
|
||||
this._setEndings(
|
||||
this.repetitions === 0, true, pingPong );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( time >= duration || time < 0 ) {
|
||||
// wrap around
|
||||
|
||||
var loopDelta = Math.floor( time / duration ); // signed
|
||||
time -= duration * loopDelta;
|
||||
|
||||
loopCount += Math.abs( loopDelta );
|
||||
|
||||
var pending = this.repetitions - loopCount;
|
||||
|
||||
if ( pending < 0 ) {
|
||||
// have to stop (switch state, clamp time, fire event)
|
||||
|
||||
if ( this.clampWhenFinished ) this.paused = true;
|
||||
else this.enabled = false;
|
||||
|
||||
time = deltaTime > 0 ? duration : 0;
|
||||
|
||||
this._mixer.dispatchEvent( {
|
||||
type: 'finished', action: this,
|
||||
direction: deltaTime > 0 ? 1 : -1
|
||||
} );
|
||||
|
||||
} else {
|
||||
// keep running
|
||||
|
||||
if ( pending === 0 ) {
|
||||
// entering the last round
|
||||
|
||||
var atStart = deltaTime < 0;
|
||||
this._setEndings( atStart, ! atStart, pingPong );
|
||||
|
||||
} else {
|
||||
|
||||
this._setEndings( false, false, pingPong );
|
||||
|
||||
}
|
||||
|
||||
this._loopCount = loopCount;
|
||||
|
||||
this._mixer.dispatchEvent( {
|
||||
type: 'loop', action: this, loopDelta: loopDelta
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( pingPong && ( loopCount & 1 ) === 1 ) {
|
||||
// invert time for the "pong round"
|
||||
|
||||
this.time = time;
|
||||
return duration - time;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.time = time;
|
||||
return time;
|
||||
|
||||
},
|
||||
|
||||
_setEndings: function( atStart, atEnd, pingPong ) {
|
||||
|
||||
var settings = this._interpolantSettings;
|
||||
|
||||
if ( pingPong ) {
|
||||
|
||||
settings.endingStart = ZeroSlopeEnding;
|
||||
settings.endingEnd = ZeroSlopeEnding;
|
||||
|
||||
} else {
|
||||
|
||||
// assuming for LoopOnce atStart == atEnd == true
|
||||
|
||||
if ( atStart ) {
|
||||
|
||||
settings.endingStart = this.zeroSlopeAtStart ?
|
||||
ZeroSlopeEnding : ZeroCurvatureEnding;
|
||||
|
||||
} else {
|
||||
|
||||
settings.endingStart = WrapAroundEnding;
|
||||
|
||||
}
|
||||
|
||||
if ( atEnd ) {
|
||||
|
||||
settings.endingEnd = this.zeroSlopeAtEnd ?
|
||||
ZeroSlopeEnding : ZeroCurvatureEnding;
|
||||
|
||||
} else {
|
||||
|
||||
settings.endingEnd = WrapAroundEnding;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_scheduleFading: function( duration, weightNow, weightThen ) {
|
||||
|
||||
var mixer = this._mixer, now = mixer.time,
|
||||
interpolant = this._weightInterpolant;
|
||||
|
||||
if ( interpolant === null ) {
|
||||
|
||||
interpolant = mixer._lendControlInterpolant();
|
||||
this._weightInterpolant = interpolant;
|
||||
|
||||
}
|
||||
|
||||
var times = interpolant.parameterPositions,
|
||||
values = interpolant.sampleValues;
|
||||
|
||||
times[ 0 ] = now; values[ 0 ] = weightNow;
|
||||
times[ 1 ] = now + duration; values[ 1 ] = weightThen;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { AnimationAction };
|
||||
363
node_modules/three/src/animation/AnimationClip.js
generated
vendored
Normal file
363
node_modules/three/src/animation/AnimationClip.js
generated
vendored
Normal file
@@ -0,0 +1,363 @@
|
||||
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack';
|
||||
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack';
|
||||
import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack';
|
||||
import { AnimationUtils } from './AnimationUtils';
|
||||
import { KeyframeTrack } from './KeyframeTrack';
|
||||
import { _Math } from '../math/Math';
|
||||
|
||||
/**
|
||||
*
|
||||
* Reusable set of Tracks that represent an animation.
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
*/
|
||||
|
||||
function AnimationClip( name, duration, tracks ) {
|
||||
|
||||
this.name = name;
|
||||
this.tracks = tracks;
|
||||
this.duration = ( duration !== undefined ) ? duration : -1;
|
||||
|
||||
this.uuid = _Math.generateUUID();
|
||||
|
||||
// this means it should figure out its duration by scanning the tracks
|
||||
if ( this.duration < 0 ) {
|
||||
|
||||
this.resetDuration();
|
||||
|
||||
}
|
||||
|
||||
this.optimize();
|
||||
|
||||
}
|
||||
|
||||
AnimationClip.prototype = {
|
||||
|
||||
constructor: AnimationClip,
|
||||
|
||||
resetDuration: function() {
|
||||
|
||||
var tracks = this.tracks,
|
||||
duration = 0;
|
||||
|
||||
for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
|
||||
|
||||
var track = this.tracks[ i ];
|
||||
|
||||
duration = Math.max( duration, track.times[ track.times.length - 1 ] );
|
||||
|
||||
}
|
||||
|
||||
this.duration = duration;
|
||||
|
||||
},
|
||||
|
||||
trim: function() {
|
||||
|
||||
for ( var i = 0; i < this.tracks.length; i ++ ) {
|
||||
|
||||
this.tracks[ i ].trim( 0, this.duration );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
optimize: function() {
|
||||
|
||||
for ( var i = 0; i < this.tracks.length; i ++ ) {
|
||||
|
||||
this.tracks[ i ].optimize();
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Static methods:
|
||||
|
||||
Object.assign( AnimationClip, {
|
||||
|
||||
parse: function( json ) {
|
||||
|
||||
var tracks = [],
|
||||
jsonTracks = json.tracks,
|
||||
frameTime = 1.0 / ( json.fps || 1.0 );
|
||||
|
||||
for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
|
||||
|
||||
tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
|
||||
|
||||
}
|
||||
|
||||
return new AnimationClip( json.name, json.duration, tracks );
|
||||
|
||||
},
|
||||
|
||||
|
||||
toJSON: function( clip ) {
|
||||
|
||||
var tracks = [],
|
||||
clipTracks = clip.tracks;
|
||||
|
||||
var json = {
|
||||
|
||||
'name': clip.name,
|
||||
'duration': clip.duration,
|
||||
'tracks': tracks
|
||||
|
||||
};
|
||||
|
||||
for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
|
||||
|
||||
tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
|
||||
|
||||
}
|
||||
|
||||
return json;
|
||||
|
||||
},
|
||||
|
||||
|
||||
CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps, noLoop ) {
|
||||
|
||||
var numMorphTargets = morphTargetSequence.length;
|
||||
var tracks = [];
|
||||
|
||||
for ( var i = 0; i < numMorphTargets; i ++ ) {
|
||||
|
||||
var times = [];
|
||||
var values = [];
|
||||
|
||||
times.push(
|
||||
( i + numMorphTargets - 1 ) % numMorphTargets,
|
||||
i,
|
||||
( i + 1 ) % numMorphTargets );
|
||||
|
||||
values.push( 0, 1, 0 );
|
||||
|
||||
var order = AnimationUtils.getKeyframeOrder( times );
|
||||
times = AnimationUtils.sortedArray( times, 1, order );
|
||||
values = AnimationUtils.sortedArray( values, 1, order );
|
||||
|
||||
// if there is a key at the first frame, duplicate it as the
|
||||
// last frame as well for perfect loop.
|
||||
if ( ! noLoop && times[ 0 ] === 0 ) {
|
||||
|
||||
times.push( numMorphTargets );
|
||||
values.push( values[ 0 ] );
|
||||
|
||||
}
|
||||
|
||||
tracks.push(
|
||||
new NumberKeyframeTrack(
|
||||
'.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
|
||||
times, values
|
||||
).scale( 1.0 / fps ) );
|
||||
}
|
||||
|
||||
return new AnimationClip( name, -1, tracks );
|
||||
|
||||
},
|
||||
|
||||
findByName: function( objectOrClipArray, name ) {
|
||||
|
||||
var clipArray = objectOrClipArray;
|
||||
|
||||
if ( ! Array.isArray( objectOrClipArray ) ) {
|
||||
|
||||
var o = objectOrClipArray;
|
||||
clipArray = o.geometry && o.geometry.animations || o.animations;
|
||||
|
||||
}
|
||||
|
||||
for ( var i = 0; i < clipArray.length; i ++ ) {
|
||||
|
||||
if ( clipArray[ i ].name === name ) {
|
||||
|
||||
return clipArray[ i ];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
},
|
||||
|
||||
CreateClipsFromMorphTargetSequences: function( morphTargets, fps, noLoop ) {
|
||||
|
||||
var animationToMorphTargets = {};
|
||||
|
||||
// tested with https://regex101.com/ on trick sequences
|
||||
// such flamingo_flyA_003, flamingo_run1_003, crdeath0059
|
||||
var pattern = /^([\w-]*?)([\d]+)$/;
|
||||
|
||||
// sort morph target names into animation groups based
|
||||
// patterns like Walk_001, Walk_002, Run_001, Run_002
|
||||
for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
|
||||
|
||||
var morphTarget = morphTargets[ i ];
|
||||
var parts = morphTarget.name.match( pattern );
|
||||
|
||||
if ( parts && parts.length > 1 ) {
|
||||
|
||||
var name = parts[ 1 ];
|
||||
|
||||
var animationMorphTargets = animationToMorphTargets[ name ];
|
||||
if ( ! animationMorphTargets ) {
|
||||
|
||||
animationToMorphTargets[ name ] = animationMorphTargets = [];
|
||||
|
||||
}
|
||||
|
||||
animationMorphTargets.push( morphTarget );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var clips = [];
|
||||
|
||||
for ( var name in animationToMorphTargets ) {
|
||||
|
||||
clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
|
||||
|
||||
}
|
||||
|
||||
return clips;
|
||||
|
||||
},
|
||||
|
||||
// parse the animation.hierarchy format
|
||||
parseAnimation: function( animation, bones ) {
|
||||
|
||||
if ( ! animation ) {
|
||||
|
||||
console.error( " no animation in JSONLoader data" );
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
var addNonemptyTrack = function(
|
||||
trackType, trackName, animationKeys, propertyName, destTracks ) {
|
||||
|
||||
// only return track if there are actually keys.
|
||||
if ( animationKeys.length !== 0 ) {
|
||||
|
||||
var times = [];
|
||||
var values = [];
|
||||
|
||||
AnimationUtils.flattenJSON(
|
||||
animationKeys, times, values, propertyName );
|
||||
|
||||
// empty keys are filtered out, so check again
|
||||
if ( times.length !== 0 ) {
|
||||
|
||||
destTracks.push( new trackType( trackName, times, values ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var tracks = [];
|
||||
|
||||
var clipName = animation.name || 'default';
|
||||
// automatic length determination in AnimationClip.
|
||||
var duration = animation.length || -1;
|
||||
var fps = animation.fps || 30;
|
||||
|
||||
var hierarchyTracks = animation.hierarchy || [];
|
||||
|
||||
for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
|
||||
|
||||
var animationKeys = hierarchyTracks[ h ].keys;
|
||||
|
||||
// skip empty tracks
|
||||
if ( ! animationKeys || animationKeys.length === 0 ) continue;
|
||||
|
||||
// process morph targets in a way exactly compatible
|
||||
// with AnimationHandler.init( animation )
|
||||
if ( animationKeys[0].morphTargets ) {
|
||||
|
||||
// figure out all morph targets used in this track
|
||||
var morphTargetNames = {};
|
||||
for ( var k = 0; k < animationKeys.length; k ++ ) {
|
||||
|
||||
if ( animationKeys[k].morphTargets ) {
|
||||
|
||||
for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
|
||||
|
||||
morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// create a track for each morph target with all zero
|
||||
// morphTargetInfluences except for the keys in which
|
||||
// the morphTarget is named.
|
||||
for ( var morphTargetName in morphTargetNames ) {
|
||||
|
||||
var times = [];
|
||||
var values = [];
|
||||
|
||||
for ( var m = 0; m !== animationKeys[k].morphTargets.length; ++ m ) {
|
||||
|
||||
var animationKey = animationKeys[k];
|
||||
|
||||
times.push( animationKey.time );
|
||||
values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
|
||||
|
||||
}
|
||||
|
||||
tracks.push( new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
|
||||
|
||||
}
|
||||
|
||||
duration = morphTargetNames.length * ( fps || 1.0 );
|
||||
|
||||
} else {
|
||||
// ...assume skeletal animation
|
||||
|
||||
var boneName = '.bones[' + bones[ h ].name + ']';
|
||||
|
||||
addNonemptyTrack(
|
||||
VectorKeyframeTrack, boneName + '.position',
|
||||
animationKeys, 'pos', tracks );
|
||||
|
||||
addNonemptyTrack(
|
||||
QuaternionKeyframeTrack, boneName + '.quaternion',
|
||||
animationKeys, 'rot', tracks );
|
||||
|
||||
addNonemptyTrack(
|
||||
VectorKeyframeTrack, boneName + '.scale',
|
||||
animationKeys, 'scl', tracks );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( tracks.length === 0 ) {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
var clip = new AnimationClip( clipName, duration, tracks );
|
||||
|
||||
return clip;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { AnimationClip };
|
||||
748
node_modules/three/src/animation/AnimationMixer.js
generated
vendored
Normal file
748
node_modules/three/src/animation/AnimationMixer.js
generated
vendored
Normal file
@@ -0,0 +1,748 @@
|
||||
import { AnimationAction } from './AnimationAction';
|
||||
import { EventDispatcher } from '../core/EventDispatcher';
|
||||
import { LinearInterpolant } from '../math/interpolants/LinearInterpolant';
|
||||
import { PropertyBinding } from './PropertyBinding';
|
||||
import { PropertyMixer } from './PropertyMixer';
|
||||
import { AnimationClip } from './AnimationClip';
|
||||
|
||||
/**
|
||||
*
|
||||
* Player for AnimationClips.
|
||||
*
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function AnimationMixer( root ) {
|
||||
|
||||
this._root = root;
|
||||
this._initMemoryManager();
|
||||
this._accuIndex = 0;
|
||||
|
||||
this.time = 0;
|
||||
|
||||
this.timeScale = 1.0;
|
||||
|
||||
}
|
||||
|
||||
AnimationMixer.prototype = {
|
||||
|
||||
constructor: AnimationMixer,
|
||||
|
||||
// return an action for a clip optionally using a custom root target
|
||||
// object (this method allocates a lot of dynamic memory in case a
|
||||
// previously unknown clip/root combination is specified)
|
||||
clipAction: function ( clip, optionalRoot ) {
|
||||
|
||||
var root = optionalRoot || this._root,
|
||||
rootUuid = root.uuid,
|
||||
|
||||
clipObject = typeof clip === 'string' ?
|
||||
AnimationClip.findByName( root, clip ) : clip,
|
||||
|
||||
clipUuid = clipObject !== null ? clipObject.uuid : clip,
|
||||
|
||||
actionsForClip = this._actionsByClip[ clipUuid ],
|
||||
prototypeAction = null;
|
||||
|
||||
if ( actionsForClip !== undefined ) {
|
||||
|
||||
var existingAction =
|
||||
actionsForClip.actionByRoot[ rootUuid ];
|
||||
|
||||
if ( existingAction !== undefined ) {
|
||||
|
||||
return existingAction;
|
||||
|
||||
}
|
||||
|
||||
// we know the clip, so we don't have to parse all
|
||||
// the bindings again but can just copy
|
||||
prototypeAction = actionsForClip.knownActions[ 0 ];
|
||||
|
||||
// also, take the clip from the prototype action
|
||||
if ( clipObject === null )
|
||||
clipObject = prototypeAction._clip;
|
||||
|
||||
}
|
||||
|
||||
// clip must be known when specified via string
|
||||
if ( clipObject === null ) return null;
|
||||
|
||||
// allocate all resources required to run it
|
||||
var newAction = new AnimationAction( this, clipObject, optionalRoot );
|
||||
|
||||
this._bindAction( newAction, prototypeAction );
|
||||
|
||||
// and make the action known to the memory manager
|
||||
this._addInactiveAction( newAction, clipUuid, rootUuid );
|
||||
|
||||
return newAction;
|
||||
|
||||
},
|
||||
|
||||
// get an existing action
|
||||
existingAction: function ( clip, optionalRoot ) {
|
||||
|
||||
var root = optionalRoot || this._root,
|
||||
rootUuid = root.uuid,
|
||||
|
||||
clipObject = typeof clip === 'string' ?
|
||||
AnimationClip.findByName( root, clip ) : clip,
|
||||
|
||||
clipUuid = clipObject ? clipObject.uuid : clip,
|
||||
|
||||
actionsForClip = this._actionsByClip[ clipUuid ];
|
||||
|
||||
if ( actionsForClip !== undefined ) {
|
||||
|
||||
return actionsForClip.actionByRoot[ rootUuid ] || null;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
},
|
||||
|
||||
// deactivates all previously scheduled actions
|
||||
stopAllAction: function () {
|
||||
|
||||
var actions = this._actions,
|
||||
nActions = this._nActiveActions,
|
||||
bindings = this._bindings,
|
||||
nBindings = this._nActiveBindings;
|
||||
|
||||
this._nActiveActions = 0;
|
||||
this._nActiveBindings = 0;
|
||||
|
||||
for ( var i = 0; i !== nActions; ++ i ) {
|
||||
|
||||
actions[ i ].reset();
|
||||
|
||||
}
|
||||
|
||||
for ( var i = 0; i !== nBindings; ++ i ) {
|
||||
|
||||
bindings[ i ].useCount = 0;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
// advance the time and update apply the animation
|
||||
update: function ( deltaTime ) {
|
||||
|
||||
deltaTime *= this.timeScale;
|
||||
|
||||
var actions = this._actions,
|
||||
nActions = this._nActiveActions,
|
||||
|
||||
time = this.time += deltaTime,
|
||||
timeDirection = Math.sign( deltaTime ),
|
||||
|
||||
accuIndex = this._accuIndex ^= 1;
|
||||
|
||||
// run active actions
|
||||
|
||||
for ( var i = 0; i !== nActions; ++ i ) {
|
||||
|
||||
var action = actions[ i ];
|
||||
|
||||
if ( action.enabled ) {
|
||||
|
||||
action._update( time, deltaTime, timeDirection, accuIndex );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// update scene graph
|
||||
|
||||
var bindings = this._bindings,
|
||||
nBindings = this._nActiveBindings;
|
||||
|
||||
for ( var i = 0; i !== nBindings; ++ i ) {
|
||||
|
||||
bindings[ i ].apply( accuIndex );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
// return this mixer's root target object
|
||||
getRoot: function () {
|
||||
|
||||
return this._root;
|
||||
|
||||
},
|
||||
|
||||
// free all resources specific to a particular clip
|
||||
uncacheClip: function ( clip ) {
|
||||
|
||||
var actions = this._actions,
|
||||
clipUuid = clip.uuid,
|
||||
actionsByClip = this._actionsByClip,
|
||||
actionsForClip = actionsByClip[ clipUuid ];
|
||||
|
||||
if ( actionsForClip !== undefined ) {
|
||||
|
||||
// note: just calling _removeInactiveAction would mess up the
|
||||
// iteration state and also require updating the state we can
|
||||
// just throw away
|
||||
|
||||
var actionsToRemove = actionsForClip.knownActions;
|
||||
|
||||
for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
|
||||
|
||||
var action = actionsToRemove[ i ];
|
||||
|
||||
this._deactivateAction( action );
|
||||
|
||||
var cacheIndex = action._cacheIndex,
|
||||
lastInactiveAction = actions[ actions.length - 1 ];
|
||||
|
||||
action._cacheIndex = null;
|
||||
action._byClipCacheIndex = null;
|
||||
|
||||
lastInactiveAction._cacheIndex = cacheIndex;
|
||||
actions[ cacheIndex ] = lastInactiveAction;
|
||||
actions.pop();
|
||||
|
||||
this._removeInactiveBindingsForAction( action );
|
||||
|
||||
}
|
||||
|
||||
delete actionsByClip[ clipUuid ];
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// free all resources specific to a particular root target object
|
||||
uncacheRoot: function ( root ) {
|
||||
|
||||
var rootUuid = root.uuid,
|
||||
actionsByClip = this._actionsByClip;
|
||||
|
||||
for ( var clipUuid in actionsByClip ) {
|
||||
|
||||
var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
|
||||
action = actionByRoot[ rootUuid ];
|
||||
|
||||
if ( action !== undefined ) {
|
||||
|
||||
this._deactivateAction( action );
|
||||
this._removeInactiveAction( action );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var bindingsByRoot = this._bindingsByRootAndName,
|
||||
bindingByName = bindingsByRoot[ rootUuid ];
|
||||
|
||||
if ( bindingByName !== undefined ) {
|
||||
|
||||
for ( var trackName in bindingByName ) {
|
||||
|
||||
var binding = bindingByName[ trackName ];
|
||||
binding.restoreOriginalState();
|
||||
this._removeInactiveBinding( binding );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// remove a targeted clip from the cache
|
||||
uncacheAction: function ( clip, optionalRoot ) {
|
||||
|
||||
var action = this.existingAction( clip, optionalRoot );
|
||||
|
||||
if ( action !== null ) {
|
||||
|
||||
this._deactivateAction( action );
|
||||
this._removeInactiveAction( action );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Implementation details:
|
||||
|
||||
Object.assign( AnimationMixer.prototype, {
|
||||
|
||||
_bindAction: function ( action, prototypeAction ) {
|
||||
|
||||
var root = action._localRoot || this._root,
|
||||
tracks = action._clip.tracks,
|
||||
nTracks = tracks.length,
|
||||
bindings = action._propertyBindings,
|
||||
interpolants = action._interpolants,
|
||||
rootUuid = root.uuid,
|
||||
bindingsByRoot = this._bindingsByRootAndName,
|
||||
bindingsByName = bindingsByRoot[ rootUuid ];
|
||||
|
||||
if ( bindingsByName === undefined ) {
|
||||
|
||||
bindingsByName = {};
|
||||
bindingsByRoot[ rootUuid ] = bindingsByName;
|
||||
|
||||
}
|
||||
|
||||
for ( var i = 0; i !== nTracks; ++ i ) {
|
||||
|
||||
var track = tracks[ i ],
|
||||
trackName = track.name,
|
||||
binding = bindingsByName[ trackName ];
|
||||
|
||||
if ( binding !== undefined ) {
|
||||
|
||||
bindings[ i ] = binding;
|
||||
|
||||
} else {
|
||||
|
||||
binding = bindings[ i ];
|
||||
|
||||
if ( binding !== undefined ) {
|
||||
|
||||
// existing binding, make sure the cache knows
|
||||
|
||||
if ( binding._cacheIndex === null ) {
|
||||
|
||||
++ binding.referenceCount;
|
||||
this._addInactiveBinding( binding, rootUuid, trackName );
|
||||
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
var path = prototypeAction && prototypeAction.
|
||||
_propertyBindings[ i ].binding.parsedPath;
|
||||
|
||||
binding = new PropertyMixer(
|
||||
PropertyBinding.create( root, trackName, path ),
|
||||
track.ValueTypeName, track.getValueSize() );
|
||||
|
||||
++ binding.referenceCount;
|
||||
this._addInactiveBinding( binding, rootUuid, trackName );
|
||||
|
||||
bindings[ i ] = binding;
|
||||
|
||||
}
|
||||
|
||||
interpolants[ i ].resultBuffer = binding.buffer;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_activateAction: function ( action ) {
|
||||
|
||||
if ( ! this._isActiveAction( action ) ) {
|
||||
|
||||
if ( action._cacheIndex === null ) {
|
||||
|
||||
// this action has been forgotten by the cache, but the user
|
||||
// appears to be still using it -> rebind
|
||||
|
||||
var rootUuid = ( action._localRoot || this._root ).uuid,
|
||||
clipUuid = action._clip.uuid,
|
||||
actionsForClip = this._actionsByClip[ clipUuid ];
|
||||
|
||||
this._bindAction( action,
|
||||
actionsForClip && actionsForClip.knownActions[ 0 ] );
|
||||
|
||||
this._addInactiveAction( action, clipUuid, rootUuid );
|
||||
|
||||
}
|
||||
|
||||
var bindings = action._propertyBindings;
|
||||
|
||||
// increment reference counts / sort out state
|
||||
for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
var binding = bindings[ i ];
|
||||
|
||||
if ( binding.useCount ++ === 0 ) {
|
||||
|
||||
this._lendBinding( binding );
|
||||
binding.saveOriginalState();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this._lendAction( action );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_deactivateAction: function ( action ) {
|
||||
|
||||
if ( this._isActiveAction( action ) ) {
|
||||
|
||||
var bindings = action._propertyBindings;
|
||||
|
||||
// decrement reference counts / sort out state
|
||||
for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
var binding = bindings[ i ];
|
||||
|
||||
if ( -- binding.useCount === 0 ) {
|
||||
|
||||
binding.restoreOriginalState();
|
||||
this._takeBackBinding( binding );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this._takeBackAction( action );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// Memory manager
|
||||
|
||||
_initMemoryManager: function () {
|
||||
|
||||
this._actions = []; // 'nActiveActions' followed by inactive ones
|
||||
this._nActiveActions = 0;
|
||||
|
||||
this._actionsByClip = {};
|
||||
// inside:
|
||||
// {
|
||||
// knownActions: Array< AnimationAction > - used as prototypes
|
||||
// actionByRoot: AnimationAction - lookup
|
||||
// }
|
||||
|
||||
|
||||
this._bindings = []; // 'nActiveBindings' followed by inactive ones
|
||||
this._nActiveBindings = 0;
|
||||
|
||||
this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
|
||||
|
||||
|
||||
this._controlInterpolants = []; // same game as above
|
||||
this._nActiveControlInterpolants = 0;
|
||||
|
||||
var scope = this;
|
||||
|
||||
this.stats = {
|
||||
|
||||
actions: {
|
||||
get total() { return scope._actions.length; },
|
||||
get inUse() { return scope._nActiveActions; }
|
||||
},
|
||||
bindings: {
|
||||
get total() { return scope._bindings.length; },
|
||||
get inUse() { return scope._nActiveBindings; }
|
||||
},
|
||||
controlInterpolants: {
|
||||
get total() { return scope._controlInterpolants.length; },
|
||||
get inUse() { return scope._nActiveControlInterpolants; }
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
// Memory management for AnimationAction objects
|
||||
|
||||
_isActiveAction: function ( action ) {
|
||||
|
||||
var index = action._cacheIndex;
|
||||
return index !== null && index < this._nActiveActions;
|
||||
|
||||
},
|
||||
|
||||
_addInactiveAction: function ( action, clipUuid, rootUuid ) {
|
||||
|
||||
var actions = this._actions,
|
||||
actionsByClip = this._actionsByClip,
|
||||
actionsForClip = actionsByClip[ clipUuid ];
|
||||
|
||||
if ( actionsForClip === undefined ) {
|
||||
|
||||
actionsForClip = {
|
||||
|
||||
knownActions: [ action ],
|
||||
actionByRoot: {}
|
||||
|
||||
};
|
||||
|
||||
action._byClipCacheIndex = 0;
|
||||
|
||||
actionsByClip[ clipUuid ] = actionsForClip;
|
||||
|
||||
} else {
|
||||
|
||||
var knownActions = actionsForClip.knownActions;
|
||||
|
||||
action._byClipCacheIndex = knownActions.length;
|
||||
knownActions.push( action );
|
||||
|
||||
}
|
||||
|
||||
action._cacheIndex = actions.length;
|
||||
actions.push( action );
|
||||
|
||||
actionsForClip.actionByRoot[ rootUuid ] = action;
|
||||
|
||||
},
|
||||
|
||||
_removeInactiveAction: function ( action ) {
|
||||
|
||||
var actions = this._actions,
|
||||
lastInactiveAction = actions[ actions.length - 1 ],
|
||||
cacheIndex = action._cacheIndex;
|
||||
|
||||
lastInactiveAction._cacheIndex = cacheIndex;
|
||||
actions[ cacheIndex ] = lastInactiveAction;
|
||||
actions.pop();
|
||||
|
||||
action._cacheIndex = null;
|
||||
|
||||
|
||||
var clipUuid = action._clip.uuid,
|
||||
actionsByClip = this._actionsByClip,
|
||||
actionsForClip = actionsByClip[ clipUuid ],
|
||||
knownActionsForClip = actionsForClip.knownActions,
|
||||
|
||||
lastKnownAction =
|
||||
knownActionsForClip[ knownActionsForClip.length - 1 ],
|
||||
|
||||
byClipCacheIndex = action._byClipCacheIndex;
|
||||
|
||||
lastKnownAction._byClipCacheIndex = byClipCacheIndex;
|
||||
knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
|
||||
knownActionsForClip.pop();
|
||||
|
||||
action._byClipCacheIndex = null;
|
||||
|
||||
|
||||
var actionByRoot = actionsForClip.actionByRoot,
|
||||
rootUuid = ( actions._localRoot || this._root ).uuid;
|
||||
|
||||
delete actionByRoot[ rootUuid ];
|
||||
|
||||
if ( knownActionsForClip.length === 0 ) {
|
||||
|
||||
delete actionsByClip[ clipUuid ];
|
||||
|
||||
}
|
||||
|
||||
this._removeInactiveBindingsForAction( action );
|
||||
|
||||
},
|
||||
|
||||
_removeInactiveBindingsForAction: function ( action ) {
|
||||
|
||||
var bindings = action._propertyBindings;
|
||||
for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
var binding = bindings[ i ];
|
||||
|
||||
if ( -- binding.referenceCount === 0 ) {
|
||||
|
||||
this._removeInactiveBinding( binding );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_lendAction: function ( action ) {
|
||||
|
||||
// [ active actions | inactive actions ]
|
||||
// [ active actions >| inactive actions ]
|
||||
// s a
|
||||
// <-swap->
|
||||
// a s
|
||||
|
||||
var actions = this._actions,
|
||||
prevIndex = action._cacheIndex,
|
||||
|
||||
lastActiveIndex = this._nActiveActions ++,
|
||||
|
||||
firstInactiveAction = actions[ lastActiveIndex ];
|
||||
|
||||
action._cacheIndex = lastActiveIndex;
|
||||
actions[ lastActiveIndex ] = action;
|
||||
|
||||
firstInactiveAction._cacheIndex = prevIndex;
|
||||
actions[ prevIndex ] = firstInactiveAction;
|
||||
|
||||
},
|
||||
|
||||
_takeBackAction: function ( action ) {
|
||||
|
||||
// [ active actions | inactive actions ]
|
||||
// [ active actions |< inactive actions ]
|
||||
// a s
|
||||
// <-swap->
|
||||
// s a
|
||||
|
||||
var actions = this._actions,
|
||||
prevIndex = action._cacheIndex,
|
||||
|
||||
firstInactiveIndex = -- this._nActiveActions,
|
||||
|
||||
lastActiveAction = actions[ firstInactiveIndex ];
|
||||
|
||||
action._cacheIndex = firstInactiveIndex;
|
||||
actions[ firstInactiveIndex ] = action;
|
||||
|
||||
lastActiveAction._cacheIndex = prevIndex;
|
||||
actions[ prevIndex ] = lastActiveAction;
|
||||
|
||||
},
|
||||
|
||||
// Memory management for PropertyMixer objects
|
||||
|
||||
_addInactiveBinding: function ( binding, rootUuid, trackName ) {
|
||||
|
||||
var bindingsByRoot = this._bindingsByRootAndName,
|
||||
bindingByName = bindingsByRoot[ rootUuid ],
|
||||
|
||||
bindings = this._bindings;
|
||||
|
||||
if ( bindingByName === undefined ) {
|
||||
|
||||
bindingByName = {};
|
||||
bindingsByRoot[ rootUuid ] = bindingByName;
|
||||
|
||||
}
|
||||
|
||||
bindingByName[ trackName ] = binding;
|
||||
|
||||
binding._cacheIndex = bindings.length;
|
||||
bindings.push( binding );
|
||||
|
||||
},
|
||||
|
||||
_removeInactiveBinding: function ( binding ) {
|
||||
|
||||
var bindings = this._bindings,
|
||||
propBinding = binding.binding,
|
||||
rootUuid = propBinding.rootNode.uuid,
|
||||
trackName = propBinding.path,
|
||||
bindingsByRoot = this._bindingsByRootAndName,
|
||||
bindingByName = bindingsByRoot[ rootUuid ],
|
||||
|
||||
lastInactiveBinding = bindings[ bindings.length - 1 ],
|
||||
cacheIndex = binding._cacheIndex;
|
||||
|
||||
lastInactiveBinding._cacheIndex = cacheIndex;
|
||||
bindings[ cacheIndex ] = lastInactiveBinding;
|
||||
bindings.pop();
|
||||
|
||||
delete bindingByName[ trackName ];
|
||||
|
||||
remove_empty_map: {
|
||||
|
||||
for ( var _ in bindingByName ) break remove_empty_map;
|
||||
|
||||
delete bindingsByRoot[ rootUuid ];
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_lendBinding: function ( binding ) {
|
||||
|
||||
var bindings = this._bindings,
|
||||
prevIndex = binding._cacheIndex,
|
||||
|
||||
lastActiveIndex = this._nActiveBindings ++,
|
||||
|
||||
firstInactiveBinding = bindings[ lastActiveIndex ];
|
||||
|
||||
binding._cacheIndex = lastActiveIndex;
|
||||
bindings[ lastActiveIndex ] = binding;
|
||||
|
||||
firstInactiveBinding._cacheIndex = prevIndex;
|
||||
bindings[ prevIndex ] = firstInactiveBinding;
|
||||
|
||||
},
|
||||
|
||||
_takeBackBinding: function ( binding ) {
|
||||
|
||||
var bindings = this._bindings,
|
||||
prevIndex = binding._cacheIndex,
|
||||
|
||||
firstInactiveIndex = -- this._nActiveBindings,
|
||||
|
||||
lastActiveBinding = bindings[ firstInactiveIndex ];
|
||||
|
||||
binding._cacheIndex = firstInactiveIndex;
|
||||
bindings[ firstInactiveIndex ] = binding;
|
||||
|
||||
lastActiveBinding._cacheIndex = prevIndex;
|
||||
bindings[ prevIndex ] = lastActiveBinding;
|
||||
|
||||
},
|
||||
|
||||
|
||||
// Memory management of Interpolants for weight and time scale
|
||||
|
||||
_lendControlInterpolant: function () {
|
||||
|
||||
var interpolants = this._controlInterpolants,
|
||||
lastActiveIndex = this._nActiveControlInterpolants ++,
|
||||
interpolant = interpolants[ lastActiveIndex ];
|
||||
|
||||
if ( interpolant === undefined ) {
|
||||
|
||||
interpolant = new LinearInterpolant(
|
||||
new Float32Array( 2 ), new Float32Array( 2 ),
|
||||
1, this._controlInterpolantsResultBuffer );
|
||||
|
||||
interpolant.__cacheIndex = lastActiveIndex;
|
||||
interpolants[ lastActiveIndex ] = interpolant;
|
||||
|
||||
}
|
||||
|
||||
return interpolant;
|
||||
|
||||
},
|
||||
|
||||
_takeBackControlInterpolant: function ( interpolant ) {
|
||||
|
||||
var interpolants = this._controlInterpolants,
|
||||
prevIndex = interpolant.__cacheIndex,
|
||||
|
||||
firstInactiveIndex = -- this._nActiveControlInterpolants,
|
||||
|
||||
lastActiveInterpolant = interpolants[ firstInactiveIndex ];
|
||||
|
||||
interpolant.__cacheIndex = firstInactiveIndex;
|
||||
interpolants[ firstInactiveIndex ] = interpolant;
|
||||
|
||||
lastActiveInterpolant.__cacheIndex = prevIndex;
|
||||
interpolants[ prevIndex ] = lastActiveInterpolant;
|
||||
|
||||
},
|
||||
|
||||
_controlInterpolantsResultBuffer: new Float32Array( 1 )
|
||||
|
||||
} );
|
||||
|
||||
Object.assign( AnimationMixer.prototype, EventDispatcher.prototype );
|
||||
|
||||
export { AnimationMixer };
|
||||
378
node_modules/three/src/animation/AnimationObjectGroup.js
generated
vendored
Normal file
378
node_modules/three/src/animation/AnimationObjectGroup.js
generated
vendored
Normal file
@@ -0,0 +1,378 @@
|
||||
import { PropertyBinding } from './PropertyBinding';
|
||||
import { _Math } from '../math/Math';
|
||||
|
||||
/**
|
||||
*
|
||||
* A group of objects that receives a shared animation state.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* - Add objects you would otherwise pass as 'root' to the
|
||||
* constructor or the .clipAction method of AnimationMixer.
|
||||
*
|
||||
* - Instead pass this object as 'root'.
|
||||
*
|
||||
* - You can also add and remove objects later when the mixer
|
||||
* is running.
|
||||
*
|
||||
* Note:
|
||||
*
|
||||
* Objects of this class appear as one object to the mixer,
|
||||
* so cache control of the individual objects must be done
|
||||
* on the group.
|
||||
*
|
||||
* Limitation:
|
||||
*
|
||||
* - The animated properties must be compatible among the
|
||||
* all objects in the group.
|
||||
*
|
||||
* - A single property can either be controlled through a
|
||||
* target group or directly, but not both.
|
||||
*
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function AnimationObjectGroup( var_args ) {
|
||||
|
||||
this.uuid = _Math.generateUUID();
|
||||
|
||||
// cached objects followed by the active ones
|
||||
this._objects = Array.prototype.slice.call( arguments );
|
||||
|
||||
this.nCachedObjects_ = 0; // threshold
|
||||
// note: read by PropertyBinding.Composite
|
||||
|
||||
var indices = {};
|
||||
this._indicesByUUID = indices; // for bookkeeping
|
||||
|
||||
for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
|
||||
|
||||
indices[ arguments[ i ].uuid ] = i;
|
||||
|
||||
}
|
||||
|
||||
this._paths = []; // inside: string
|
||||
this._parsedPaths = []; // inside: { we don't care, here }
|
||||
this._bindings = []; // inside: Array< PropertyBinding >
|
||||
this._bindingsIndicesByPath = {}; // inside: indices in these arrays
|
||||
|
||||
var scope = this;
|
||||
|
||||
this.stats = {
|
||||
|
||||
objects: {
|
||||
get total() { return scope._objects.length; },
|
||||
get inUse() { return this.total - scope.nCachedObjects_; }
|
||||
},
|
||||
|
||||
get bindingsPerObject() { return scope._bindings.length; }
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
AnimationObjectGroup.prototype = {
|
||||
|
||||
constructor: AnimationObjectGroup,
|
||||
|
||||
isAnimationObjectGroup: true,
|
||||
|
||||
add: function( var_args ) {
|
||||
|
||||
var objects = this._objects,
|
||||
nObjects = objects.length,
|
||||
nCachedObjects = this.nCachedObjects_,
|
||||
indicesByUUID = this._indicesByUUID,
|
||||
paths = this._paths,
|
||||
parsedPaths = this._parsedPaths,
|
||||
bindings = this._bindings,
|
||||
nBindings = bindings.length;
|
||||
|
||||
for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
|
||||
|
||||
var object = arguments[ i ],
|
||||
uuid = object.uuid,
|
||||
index = indicesByUUID[ uuid ],
|
||||
knownObject = undefined;
|
||||
|
||||
if ( index === undefined ) {
|
||||
|
||||
// unknown object -> add it to the ACTIVE region
|
||||
|
||||
index = nObjects ++;
|
||||
indicesByUUID[ uuid ] = index;
|
||||
objects.push( object );
|
||||
|
||||
// accounting is done, now do the same for all bindings
|
||||
|
||||
for ( var j = 0, m = nBindings; j !== m; ++ j ) {
|
||||
|
||||
bindings[ j ].push(
|
||||
new PropertyBinding(
|
||||
object, paths[ j ], parsedPaths[ j ] ) );
|
||||
|
||||
}
|
||||
|
||||
} else if ( index < nCachedObjects ) {
|
||||
|
||||
knownObject = objects[ index ];
|
||||
|
||||
// move existing object to the ACTIVE region
|
||||
|
||||
var firstActiveIndex = -- nCachedObjects,
|
||||
lastCachedObject = objects[ firstActiveIndex ];
|
||||
|
||||
indicesByUUID[ lastCachedObject.uuid ] = index;
|
||||
objects[ index ] = lastCachedObject;
|
||||
|
||||
indicesByUUID[ uuid ] = firstActiveIndex;
|
||||
objects[ firstActiveIndex ] = object;
|
||||
|
||||
// accounting is done, now do the same for all bindings
|
||||
|
||||
for ( var j = 0, m = nBindings; j !== m; ++ j ) {
|
||||
|
||||
var bindingsForPath = bindings[ j ],
|
||||
lastCached = bindingsForPath[ firstActiveIndex ],
|
||||
binding = bindingsForPath[ index ];
|
||||
|
||||
bindingsForPath[ index ] = lastCached;
|
||||
|
||||
if ( binding === undefined ) {
|
||||
|
||||
// since we do not bother to create new bindings
|
||||
// for objects that are cached, the binding may
|
||||
// or may not exist
|
||||
|
||||
binding = new PropertyBinding(
|
||||
object, paths[ j ], parsedPaths[ j ] );
|
||||
|
||||
}
|
||||
|
||||
bindingsForPath[ firstActiveIndex ] = binding;
|
||||
|
||||
}
|
||||
|
||||
} else if ( objects[ index ] !== knownObject) {
|
||||
|
||||
console.error( "Different objects with the same UUID " +
|
||||
"detected. Clean the caches or recreate your " +
|
||||
"infrastructure when reloading scenes..." );
|
||||
|
||||
} // else the object is already where we want it to be
|
||||
|
||||
} // for arguments
|
||||
|
||||
this.nCachedObjects_ = nCachedObjects;
|
||||
|
||||
},
|
||||
|
||||
remove: function( var_args ) {
|
||||
|
||||
var objects = this._objects,
|
||||
nCachedObjects = this.nCachedObjects_,
|
||||
indicesByUUID = this._indicesByUUID,
|
||||
bindings = this._bindings,
|
||||
nBindings = bindings.length;
|
||||
|
||||
for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
|
||||
|
||||
var object = arguments[ i ],
|
||||
uuid = object.uuid,
|
||||
index = indicesByUUID[ uuid ];
|
||||
|
||||
if ( index !== undefined && index >= nCachedObjects ) {
|
||||
|
||||
// move existing object into the CACHED region
|
||||
|
||||
var lastCachedIndex = nCachedObjects ++,
|
||||
firstActiveObject = objects[ lastCachedIndex ];
|
||||
|
||||
indicesByUUID[ firstActiveObject.uuid ] = index;
|
||||
objects[ index ] = firstActiveObject;
|
||||
|
||||
indicesByUUID[ uuid ] = lastCachedIndex;
|
||||
objects[ lastCachedIndex ] = object;
|
||||
|
||||
// accounting is done, now do the same for all bindings
|
||||
|
||||
for ( var j = 0, m = nBindings; j !== m; ++ j ) {
|
||||
|
||||
var bindingsForPath = bindings[ j ],
|
||||
firstActive = bindingsForPath[ lastCachedIndex ],
|
||||
binding = bindingsForPath[ index ];
|
||||
|
||||
bindingsForPath[ index ] = firstActive;
|
||||
bindingsForPath[ lastCachedIndex ] = binding;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // for arguments
|
||||
|
||||
this.nCachedObjects_ = nCachedObjects;
|
||||
|
||||
},
|
||||
|
||||
// remove & forget
|
||||
uncache: function( var_args ) {
|
||||
|
||||
var objects = this._objects,
|
||||
nObjects = objects.length,
|
||||
nCachedObjects = this.nCachedObjects_,
|
||||
indicesByUUID = this._indicesByUUID,
|
||||
bindings = this._bindings,
|
||||
nBindings = bindings.length;
|
||||
|
||||
for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
|
||||
|
||||
var object = arguments[ i ],
|
||||
uuid = object.uuid,
|
||||
index = indicesByUUID[ uuid ];
|
||||
|
||||
if ( index !== undefined ) {
|
||||
|
||||
delete indicesByUUID[ uuid ];
|
||||
|
||||
if ( index < nCachedObjects ) {
|
||||
|
||||
// object is cached, shrink the CACHED region
|
||||
|
||||
var firstActiveIndex = -- nCachedObjects,
|
||||
lastCachedObject = objects[ firstActiveIndex ],
|
||||
lastIndex = -- nObjects,
|
||||
lastObject = objects[ lastIndex ];
|
||||
|
||||
// last cached object takes this object's place
|
||||
indicesByUUID[ lastCachedObject.uuid ] = index;
|
||||
objects[ index ] = lastCachedObject;
|
||||
|
||||
// last object goes to the activated slot and pop
|
||||
indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
|
||||
objects[ firstActiveIndex ] = lastObject;
|
||||
objects.pop();
|
||||
|
||||
// accounting is done, now do the same for all bindings
|
||||
|
||||
for ( var j = 0, m = nBindings; j !== m; ++ j ) {
|
||||
|
||||
var bindingsForPath = bindings[ j ],
|
||||
lastCached = bindingsForPath[ firstActiveIndex ],
|
||||
last = bindingsForPath[ lastIndex ];
|
||||
|
||||
bindingsForPath[ index ] = lastCached;
|
||||
bindingsForPath[ firstActiveIndex ] = last;
|
||||
bindingsForPath.pop();
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// object is active, just swap with the last and pop
|
||||
|
||||
var lastIndex = -- nObjects,
|
||||
lastObject = objects[ lastIndex ];
|
||||
|
||||
indicesByUUID[ lastObject.uuid ] = index;
|
||||
objects[ index ] = lastObject;
|
||||
objects.pop();
|
||||
|
||||
// accounting is done, now do the same for all bindings
|
||||
|
||||
for ( var j = 0, m = nBindings; j !== m; ++ j ) {
|
||||
|
||||
var bindingsForPath = bindings[ j ];
|
||||
|
||||
bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
|
||||
bindingsForPath.pop();
|
||||
|
||||
}
|
||||
|
||||
} // cached or active
|
||||
|
||||
} // if object is known
|
||||
|
||||
} // for arguments
|
||||
|
||||
this.nCachedObjects_ = nCachedObjects;
|
||||
|
||||
},
|
||||
|
||||
// Internal interface used by befriended PropertyBinding.Composite:
|
||||
|
||||
subscribe_: function( path, parsedPath ) {
|
||||
// returns an array of bindings for the given path that is changed
|
||||
// according to the contained objects in the group
|
||||
|
||||
var indicesByPath = this._bindingsIndicesByPath,
|
||||
index = indicesByPath[ path ],
|
||||
bindings = this._bindings;
|
||||
|
||||
if ( index !== undefined ) return bindings[ index ];
|
||||
|
||||
var paths = this._paths,
|
||||
parsedPaths = this._parsedPaths,
|
||||
objects = this._objects,
|
||||
nObjects = objects.length,
|
||||
nCachedObjects = this.nCachedObjects_,
|
||||
bindingsForPath = new Array( nObjects );
|
||||
|
||||
index = bindings.length;
|
||||
|
||||
indicesByPath[ path ] = index;
|
||||
|
||||
paths.push( path );
|
||||
parsedPaths.push( parsedPath );
|
||||
bindings.push( bindingsForPath );
|
||||
|
||||
for ( var i = nCachedObjects,
|
||||
n = objects.length; i !== n; ++ i ) {
|
||||
|
||||
var object = objects[ i ];
|
||||
|
||||
bindingsForPath[ i ] =
|
||||
new PropertyBinding( object, path, parsedPath );
|
||||
|
||||
}
|
||||
|
||||
return bindingsForPath;
|
||||
|
||||
},
|
||||
|
||||
unsubscribe_: function( path ) {
|
||||
// tells the group to forget about a property path and no longer
|
||||
// update the array previously obtained with 'subscribe_'
|
||||
|
||||
var indicesByPath = this._bindingsIndicesByPath,
|
||||
index = indicesByPath[ path ];
|
||||
|
||||
if ( index !== undefined ) {
|
||||
|
||||
var paths = this._paths,
|
||||
parsedPaths = this._parsedPaths,
|
||||
bindings = this._bindings,
|
||||
lastBindingsIndex = bindings.length - 1,
|
||||
lastBindings = bindings[ lastBindingsIndex ],
|
||||
lastBindingsPath = path[ lastBindingsIndex ];
|
||||
|
||||
indicesByPath[ lastBindingsPath ] = index;
|
||||
|
||||
bindings[ index ] = lastBindings;
|
||||
bindings.pop();
|
||||
|
||||
parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
|
||||
parsedPaths.pop();
|
||||
|
||||
paths[ index ] = paths[ lastBindingsIndex ];
|
||||
paths.pop();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
export { AnimationObjectGroup };
|
||||
162
node_modules/three/src/animation/AnimationUtils.js
generated
vendored
Normal file
162
node_modules/three/src/animation/AnimationUtils.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* @author tschw
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
*/
|
||||
|
||||
var AnimationUtils = {
|
||||
|
||||
// same as Array.prototype.slice, but also works on typed arrays
|
||||
arraySlice: function( array, from, to ) {
|
||||
|
||||
if ( AnimationUtils.isTypedArray( array ) ) {
|
||||
|
||||
return new array.constructor( array.subarray( from, to ) );
|
||||
|
||||
}
|
||||
|
||||
return array.slice( from, to );
|
||||
|
||||
},
|
||||
|
||||
// converts an array to a specific type
|
||||
convertArray: function( array, type, forceClone ) {
|
||||
|
||||
if ( ! array || // let 'undefined' and 'null' pass
|
||||
! forceClone && array.constructor === type ) return array;
|
||||
|
||||
if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
|
||||
|
||||
return new type( array ); // create typed array
|
||||
|
||||
}
|
||||
|
||||
return Array.prototype.slice.call( array ); // create Array
|
||||
|
||||
},
|
||||
|
||||
isTypedArray: function( object ) {
|
||||
|
||||
return ArrayBuffer.isView( object ) &&
|
||||
! ( object instanceof DataView );
|
||||
|
||||
},
|
||||
|
||||
// returns an array by which times and values can be sorted
|
||||
getKeyframeOrder: function( times ) {
|
||||
|
||||
function compareTime( i, j ) {
|
||||
|
||||
return times[ i ] - times[ j ];
|
||||
|
||||
}
|
||||
|
||||
var n = times.length;
|
||||
var result = new Array( n );
|
||||
for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
|
||||
|
||||
result.sort( compareTime );
|
||||
|
||||
return result;
|
||||
|
||||
},
|
||||
|
||||
// uses the array previously returned by 'getKeyframeOrder' to sort data
|
||||
sortedArray: function( values, stride, order ) {
|
||||
|
||||
var nValues = values.length;
|
||||
var result = new values.constructor( nValues );
|
||||
|
||||
for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
|
||||
|
||||
var srcOffset = order[ i ] * stride;
|
||||
|
||||
for ( var j = 0; j !== stride; ++ j ) {
|
||||
|
||||
result[ dstOffset ++ ] = values[ srcOffset + j ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
},
|
||||
|
||||
// function for parsing AOS keyframe formats
|
||||
flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
|
||||
|
||||
var i = 1, key = jsonKeys[ 0 ];
|
||||
|
||||
while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
|
||||
|
||||
key = jsonKeys[ i ++ ];
|
||||
|
||||
}
|
||||
|
||||
if ( key === undefined ) return; // no data
|
||||
|
||||
var value = key[ valuePropertyName ];
|
||||
if ( value === undefined ) return; // no data
|
||||
|
||||
if ( Array.isArray( value ) ) {
|
||||
|
||||
do {
|
||||
|
||||
value = key[ valuePropertyName ];
|
||||
|
||||
if ( value !== undefined ) {
|
||||
|
||||
times.push( key.time );
|
||||
values.push.apply( values, value ); // push all elements
|
||||
|
||||
}
|
||||
|
||||
key = jsonKeys[ i ++ ];
|
||||
|
||||
} while ( key !== undefined );
|
||||
|
||||
} else if ( value.toArray !== undefined ) {
|
||||
// ...assume THREE.Math-ish
|
||||
|
||||
do {
|
||||
|
||||
value = key[ valuePropertyName ];
|
||||
|
||||
if ( value !== undefined ) {
|
||||
|
||||
times.push( key.time );
|
||||
value.toArray( values, values.length );
|
||||
|
||||
}
|
||||
|
||||
key = jsonKeys[ i ++ ];
|
||||
|
||||
} while ( key !== undefined );
|
||||
|
||||
} else {
|
||||
// otherwise push as-is
|
||||
|
||||
do {
|
||||
|
||||
value = key[ valuePropertyName ];
|
||||
|
||||
if ( value !== undefined ) {
|
||||
|
||||
times.push( key.time );
|
||||
values.push( value );
|
||||
|
||||
}
|
||||
|
||||
key = jsonKeys[ i ++ ];
|
||||
|
||||
} while ( key !== undefined );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { AnimationUtils };
|
||||
156
node_modules/three/src/animation/KeyframeTrack.js
generated
vendored
Normal file
156
node_modules/three/src/animation/KeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
import { KeyframeTrackPrototype } from './KeyframeTrackPrototype';
|
||||
import { StringKeyframeTrack } from './tracks/StringKeyframeTrack';
|
||||
import { BooleanKeyframeTrack } from './tracks/BooleanKeyframeTrack';
|
||||
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack';
|
||||
import { ColorKeyframeTrack } from './tracks/ColorKeyframeTrack';
|
||||
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack';
|
||||
import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack';
|
||||
import { AnimationUtils } from './AnimationUtils';
|
||||
import { KeyframeTrackConstructor } from './KeyframeTrackConstructor';
|
||||
|
||||
/**
|
||||
*
|
||||
* A timed sequence of keyframes for a specific property.
|
||||
*
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function KeyframeTrack( name, times, values, interpolation ) {
|
||||
|
||||
KeyframeTrackConstructor.apply( this, arguments );
|
||||
|
||||
}
|
||||
|
||||
KeyframeTrack.prototype = KeyframeTrackPrototype;
|
||||
KeyframeTrackPrototype.constructor = KeyframeTrack;
|
||||
|
||||
// Static methods:
|
||||
|
||||
Object.assign( KeyframeTrack, {
|
||||
|
||||
// Serialization (in static context, because of constructor invocation
|
||||
// and automatic invocation of .toJSON):
|
||||
|
||||
parse: function( json ) {
|
||||
|
||||
if( json.type === undefined ) {
|
||||
|
||||
throw new Error( "track type undefined, can not parse" );
|
||||
|
||||
}
|
||||
|
||||
var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
|
||||
|
||||
if ( json.times === undefined ) {
|
||||
|
||||
var times = [], values = [];
|
||||
|
||||
AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
|
||||
|
||||
json.times = times;
|
||||
json.values = values;
|
||||
|
||||
}
|
||||
|
||||
// derived classes can define a static parse method
|
||||
if ( trackType.parse !== undefined ) {
|
||||
|
||||
return trackType.parse( json );
|
||||
|
||||
} else {
|
||||
|
||||
// by default, we asssume a constructor compatible with the base
|
||||
return new trackType(
|
||||
json.name, json.times, json.values, json.interpolation );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
toJSON: function( track ) {
|
||||
|
||||
var trackType = track.constructor;
|
||||
|
||||
var json;
|
||||
|
||||
// derived classes can define a static toJSON method
|
||||
if ( trackType.toJSON !== undefined ) {
|
||||
|
||||
json = trackType.toJSON( track );
|
||||
|
||||
} else {
|
||||
|
||||
// by default, we assume the data can be serialized as-is
|
||||
json = {
|
||||
|
||||
'name': track.name,
|
||||
'times': AnimationUtils.convertArray( track.times, Array ),
|
||||
'values': AnimationUtils.convertArray( track.values, Array )
|
||||
|
||||
};
|
||||
|
||||
var interpolation = track.getInterpolation();
|
||||
|
||||
if ( interpolation !== track.DefaultInterpolation ) {
|
||||
|
||||
json.interpolation = interpolation;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
json.type = track.ValueTypeName; // mandatory
|
||||
|
||||
return json;
|
||||
|
||||
},
|
||||
|
||||
_getTrackTypeForValueTypeName: function( typeName ) {
|
||||
|
||||
switch( typeName.toLowerCase() ) {
|
||||
|
||||
case "scalar":
|
||||
case "double":
|
||||
case "float":
|
||||
case "number":
|
||||
case "integer":
|
||||
|
||||
return NumberKeyframeTrack;
|
||||
|
||||
case "vector":
|
||||
case "vector2":
|
||||
case "vector3":
|
||||
case "vector4":
|
||||
|
||||
return VectorKeyframeTrack;
|
||||
|
||||
case "color":
|
||||
|
||||
return ColorKeyframeTrack;
|
||||
|
||||
case "quaternion":
|
||||
|
||||
return QuaternionKeyframeTrack;
|
||||
|
||||
case "bool":
|
||||
case "boolean":
|
||||
|
||||
return BooleanKeyframeTrack;
|
||||
|
||||
case "string":
|
||||
|
||||
return StringKeyframeTrack;
|
||||
|
||||
}
|
||||
|
||||
throw new Error( "Unsupported typeName: " + typeName );
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { KeyframeTrack };
|
||||
25
node_modules/three/src/animation/KeyframeTrackConstructor.js
generated
vendored
Normal file
25
node_modules/three/src/animation/KeyframeTrackConstructor.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { AnimationUtils } from './AnimationUtils';
|
||||
|
||||
function KeyframeTrackConstructor( name, times, values, interpolation ) {
|
||||
|
||||
if( name === undefined ) throw new Error( "track name is undefined" );
|
||||
|
||||
if( times === undefined || times.length === 0 ) {
|
||||
|
||||
throw new Error( "no keyframes in track named " + name );
|
||||
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
|
||||
this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
|
||||
|
||||
this.setInterpolation( interpolation || this.DefaultInterpolation );
|
||||
|
||||
this.validate();
|
||||
this.optimize();
|
||||
|
||||
}
|
||||
|
||||
export { KeyframeTrackConstructor };
|
||||
364
node_modules/three/src/animation/KeyframeTrackPrototype.js
generated
vendored
Normal file
364
node_modules/three/src/animation/KeyframeTrackPrototype.js
generated
vendored
Normal file
@@ -0,0 +1,364 @@
|
||||
import { InterpolateLinear } from '../constants';
|
||||
import { AnimationUtils } from './AnimationUtils';
|
||||
import { InterpolateSmooth, InterpolateDiscrete } from '../constants';
|
||||
import { CubicInterpolant } from '../math/interpolants/CubicInterpolant';
|
||||
import { LinearInterpolant } from '../math/interpolants/LinearInterpolant';
|
||||
import { DiscreteInterpolant } from '../math/interpolants/DiscreteInterpolant';
|
||||
|
||||
var KeyframeTrackPrototype;
|
||||
|
||||
KeyframeTrackPrototype = {
|
||||
|
||||
TimeBufferType: Float32Array,
|
||||
ValueBufferType: Float32Array,
|
||||
|
||||
DefaultInterpolation: InterpolateLinear,
|
||||
|
||||
InterpolantFactoryMethodDiscrete: function ( result ) {
|
||||
|
||||
return new DiscreteInterpolant(
|
||||
this.times, this.values, this.getValueSize(), result );
|
||||
|
||||
},
|
||||
|
||||
InterpolantFactoryMethodLinear: function ( result ) {
|
||||
|
||||
return new LinearInterpolant(
|
||||
this.times, this.values, this.getValueSize(), result );
|
||||
|
||||
},
|
||||
|
||||
InterpolantFactoryMethodSmooth: function ( result ) {
|
||||
|
||||
return new CubicInterpolant(
|
||||
this.times, this.values, this.getValueSize(), result );
|
||||
|
||||
},
|
||||
|
||||
setInterpolation: function ( interpolation ) {
|
||||
|
||||
var factoryMethod;
|
||||
|
||||
switch ( interpolation ) {
|
||||
|
||||
case InterpolateDiscrete:
|
||||
|
||||
factoryMethod = this.InterpolantFactoryMethodDiscrete;
|
||||
|
||||
break;
|
||||
|
||||
case InterpolateLinear:
|
||||
|
||||
factoryMethod = this.InterpolantFactoryMethodLinear;
|
||||
|
||||
break;
|
||||
|
||||
case InterpolateSmooth:
|
||||
|
||||
factoryMethod = this.InterpolantFactoryMethodSmooth;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( factoryMethod === undefined ) {
|
||||
|
||||
var message = "unsupported interpolation for " +
|
||||
this.ValueTypeName + " keyframe track named " + this.name;
|
||||
|
||||
if ( this.createInterpolant === undefined ) {
|
||||
|
||||
// fall back to default, unless the default itself is messed up
|
||||
if ( interpolation !== this.DefaultInterpolation ) {
|
||||
|
||||
this.setInterpolation( this.DefaultInterpolation );
|
||||
|
||||
} else {
|
||||
|
||||
throw new Error( message ); // fatal, in this case
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
console.warn( message );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this.createInterpolant = factoryMethod;
|
||||
|
||||
},
|
||||
|
||||
getInterpolation: function () {
|
||||
|
||||
switch ( this.createInterpolant ) {
|
||||
|
||||
case this.InterpolantFactoryMethodDiscrete:
|
||||
|
||||
return InterpolateDiscrete;
|
||||
|
||||
case this.InterpolantFactoryMethodLinear:
|
||||
|
||||
return InterpolateLinear;
|
||||
|
||||
case this.InterpolantFactoryMethodSmooth:
|
||||
|
||||
return InterpolateSmooth;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getValueSize: function () {
|
||||
|
||||
return this.values.length / this.times.length;
|
||||
|
||||
},
|
||||
|
||||
// move all keyframes either forwards or backwards in time
|
||||
shift: function ( timeOffset ) {
|
||||
|
||||
if ( timeOffset !== 0.0 ) {
|
||||
|
||||
var times = this.times;
|
||||
|
||||
for ( var i = 0, n = times.length; i !== n; ++ i ) {
|
||||
|
||||
times[ i ] += timeOffset;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
// scale all keyframe times by a factor (useful for frame <-> seconds conversions)
|
||||
scale: function ( timeScale ) {
|
||||
|
||||
if ( timeScale !== 1.0 ) {
|
||||
|
||||
var times = this.times;
|
||||
|
||||
for ( var i = 0, n = times.length; i !== n; ++ i ) {
|
||||
|
||||
times[ i ] *= timeScale;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
// removes keyframes before and after animation without changing any values within the range [startTime, endTime].
|
||||
// IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
|
||||
trim: function ( startTime, endTime ) {
|
||||
|
||||
var times = this.times,
|
||||
nKeys = times.length,
|
||||
from = 0,
|
||||
to = nKeys - 1;
|
||||
|
||||
while ( from !== nKeys && times[ from ] < startTime ) ++ from;
|
||||
while ( to !== - 1 && times[ to ] > endTime ) -- to;
|
||||
|
||||
++ to; // inclusive -> exclusive bound
|
||||
|
||||
if ( from !== 0 || to !== nKeys ) {
|
||||
|
||||
// empty tracks are forbidden, so keep at least one keyframe
|
||||
if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
|
||||
|
||||
var stride = this.getValueSize();
|
||||
this.times = AnimationUtils.arraySlice( times, from, to );
|
||||
this.values = AnimationUtils.
|
||||
arraySlice( this.values, from * stride, to * stride );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
// ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
|
||||
validate: function () {
|
||||
|
||||
var valid = true;
|
||||
|
||||
var valueSize = this.getValueSize();
|
||||
if ( valueSize - Math.floor( valueSize ) !== 0 ) {
|
||||
|
||||
console.error( "invalid value size in track", this );
|
||||
valid = false;
|
||||
|
||||
}
|
||||
|
||||
var times = this.times,
|
||||
values = this.values,
|
||||
|
||||
nKeys = times.length;
|
||||
|
||||
if ( nKeys === 0 ) {
|
||||
|
||||
console.error( "track is empty", this );
|
||||
valid = false;
|
||||
|
||||
}
|
||||
|
||||
var prevTime = null;
|
||||
|
||||
for ( var i = 0; i !== nKeys; i ++ ) {
|
||||
|
||||
var currTime = times[ i ];
|
||||
|
||||
if ( typeof currTime === 'number' && isNaN( currTime ) ) {
|
||||
|
||||
console.error( "time is not a valid number", this, i, currTime );
|
||||
valid = false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( prevTime !== null && prevTime > currTime ) {
|
||||
|
||||
console.error( "out of order keys", this, i, currTime, prevTime );
|
||||
valid = false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
prevTime = currTime;
|
||||
|
||||
}
|
||||
|
||||
if ( values !== undefined ) {
|
||||
|
||||
if ( AnimationUtils.isTypedArray( values ) ) {
|
||||
|
||||
for ( var i = 0, n = values.length; i !== n; ++ i ) {
|
||||
|
||||
var value = values[ i ];
|
||||
|
||||
if ( isNaN( value ) ) {
|
||||
|
||||
console.error( "value is not a valid number", this, i, value );
|
||||
valid = false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return valid;
|
||||
|
||||
},
|
||||
|
||||
// removes equivalent sequential keys as common in morph target sequences
|
||||
// (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
|
||||
optimize: function () {
|
||||
|
||||
var times = this.times,
|
||||
values = this.values,
|
||||
stride = this.getValueSize(),
|
||||
|
||||
smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
|
||||
|
||||
writeIndex = 1,
|
||||
lastIndex = times.length - 1;
|
||||
|
||||
for ( var i = 1; i < lastIndex; ++ i ) {
|
||||
|
||||
var keep = false;
|
||||
|
||||
var time = times[ i ];
|
||||
var timeNext = times[ i + 1 ];
|
||||
|
||||
// remove adjacent keyframes scheduled at the same time
|
||||
|
||||
if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
|
||||
|
||||
if ( ! smoothInterpolation ) {
|
||||
|
||||
// remove unnecessary keyframes same as their neighbors
|
||||
|
||||
var offset = i * stride,
|
||||
offsetP = offset - stride,
|
||||
offsetN = offset + stride;
|
||||
|
||||
for ( var j = 0; j !== stride; ++ j ) {
|
||||
|
||||
var value = values[ offset + j ];
|
||||
|
||||
if ( value !== values[ offsetP + j ] ||
|
||||
value !== values[ offsetN + j ] ) {
|
||||
|
||||
keep = true;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else keep = true;
|
||||
|
||||
}
|
||||
|
||||
// in-place compaction
|
||||
|
||||
if ( keep ) {
|
||||
|
||||
if ( i !== writeIndex ) {
|
||||
|
||||
times[ writeIndex ] = times[ i ];
|
||||
|
||||
var readOffset = i * stride,
|
||||
writeOffset = writeIndex * stride;
|
||||
|
||||
for ( var j = 0; j !== stride; ++ j )
|
||||
|
||||
values[ writeOffset + j ] = values[ readOffset + j ];
|
||||
|
||||
}
|
||||
|
||||
++ writeIndex;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// flush last keyframe (compaction looks ahead)
|
||||
|
||||
if ( lastIndex > 0 ) {
|
||||
|
||||
times[ writeIndex ] = times[ lastIndex ];
|
||||
|
||||
for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j )
|
||||
|
||||
values[ writeOffset + j ] = values[ readOffset + j ];
|
||||
|
||||
++ writeIndex;
|
||||
|
||||
}
|
||||
|
||||
if ( writeIndex !== times.length ) {
|
||||
|
||||
this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
|
||||
this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export { KeyframeTrackPrototype };
|
||||
652
node_modules/three/src/animation/PropertyBinding.js
generated
vendored
Normal file
652
node_modules/three/src/animation/PropertyBinding.js
generated
vendored
Normal file
@@ -0,0 +1,652 @@
|
||||
/**
|
||||
*
|
||||
* A reference to a real property in the scene graph.
|
||||
*
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function PropertyBinding( rootNode, path, parsedPath ) {
|
||||
|
||||
this.path = path;
|
||||
this.parsedPath = parsedPath ||
|
||||
PropertyBinding.parseTrackName( path );
|
||||
|
||||
this.node = PropertyBinding.findNode(
|
||||
rootNode, this.parsedPath.nodeName ) || rootNode;
|
||||
|
||||
this.rootNode = rootNode;
|
||||
|
||||
}
|
||||
|
||||
PropertyBinding.prototype = {
|
||||
|
||||
constructor: PropertyBinding,
|
||||
|
||||
getValue: function getValue_unbound( targetArray, offset ) {
|
||||
|
||||
this.bind();
|
||||
this.getValue( targetArray, offset );
|
||||
|
||||
// Note: This class uses a State pattern on a per-method basis:
|
||||
// 'bind' sets 'this.getValue' / 'setValue' and shadows the
|
||||
// prototype version of these methods with one that represents
|
||||
// the bound state. When the property is not found, the methods
|
||||
// become no-ops.
|
||||
|
||||
},
|
||||
|
||||
setValue: function getValue_unbound( sourceArray, offset ) {
|
||||
|
||||
this.bind();
|
||||
this.setValue( sourceArray, offset );
|
||||
|
||||
},
|
||||
|
||||
// create getter / setter pair for a property in the scene graph
|
||||
bind: function() {
|
||||
|
||||
var targetObject = this.node,
|
||||
parsedPath = this.parsedPath,
|
||||
|
||||
objectName = parsedPath.objectName,
|
||||
propertyName = parsedPath.propertyName,
|
||||
propertyIndex = parsedPath.propertyIndex;
|
||||
|
||||
if ( ! targetObject ) {
|
||||
|
||||
targetObject = PropertyBinding.findNode(
|
||||
this.rootNode, parsedPath.nodeName ) || this.rootNode;
|
||||
|
||||
this.node = targetObject;
|
||||
|
||||
}
|
||||
|
||||
// set fail state so we can just 'return' on error
|
||||
this.getValue = this._getValue_unavailable;
|
||||
this.setValue = this._setValue_unavailable;
|
||||
|
||||
// ensure there is a value node
|
||||
if ( ! targetObject ) {
|
||||
|
||||
console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( objectName ) {
|
||||
|
||||
var objectIndex = parsedPath.objectIndex;
|
||||
|
||||
// special cases were we need to reach deeper into the hierarchy to get the face materials....
|
||||
switch ( objectName ) {
|
||||
|
||||
case 'materials':
|
||||
|
||||
if ( ! targetObject.material ) {
|
||||
|
||||
console.error( ' can not bind to material as node does not have a material', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( ! targetObject.material.materials ) {
|
||||
|
||||
console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
targetObject = targetObject.material.materials;
|
||||
|
||||
break;
|
||||
|
||||
case 'bones':
|
||||
|
||||
if ( ! targetObject.skeleton ) {
|
||||
|
||||
console.error( ' can not bind to bones as node does not have a skeleton', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// potential future optimization: skip this if propertyIndex is already an integer
|
||||
// and convert the integer string to a true integer.
|
||||
|
||||
targetObject = targetObject.skeleton.bones;
|
||||
|
||||
// support resolving morphTarget names into indices.
|
||||
for ( var i = 0; i < targetObject.length; i ++ ) {
|
||||
|
||||
if ( targetObject[ i ].name === objectIndex ) {
|
||||
|
||||
objectIndex = i;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
if ( targetObject[ objectName ] === undefined ) {
|
||||
|
||||
console.error( ' can not bind to objectName of node, undefined', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
targetObject = targetObject[ objectName ];
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ( objectIndex !== undefined ) {
|
||||
|
||||
if ( targetObject[ objectIndex ] === undefined ) {
|
||||
|
||||
console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
targetObject = targetObject[ objectIndex ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// resolve property
|
||||
var nodeProperty = targetObject[ propertyName ];
|
||||
|
||||
if ( nodeProperty === undefined ) {
|
||||
|
||||
var nodeName = parsedPath.nodeName;
|
||||
|
||||
console.error( " trying to update property for track: " + nodeName +
|
||||
'.' + propertyName + " but it wasn't found.", targetObject );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// determine versioning scheme
|
||||
var versioning = this.Versioning.None;
|
||||
|
||||
if ( targetObject.needsUpdate !== undefined ) { // material
|
||||
|
||||
versioning = this.Versioning.NeedsUpdate;
|
||||
this.targetObject = targetObject;
|
||||
|
||||
} else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
|
||||
|
||||
versioning = this.Versioning.MatrixWorldNeedsUpdate;
|
||||
this.targetObject = targetObject;
|
||||
|
||||
}
|
||||
|
||||
// determine how the property gets bound
|
||||
var bindingType = this.BindingType.Direct;
|
||||
|
||||
if ( propertyIndex !== undefined ) {
|
||||
// access a sub element of the property array (only primitives are supported right now)
|
||||
|
||||
if ( propertyName === "morphTargetInfluences" ) {
|
||||
// potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
|
||||
|
||||
// support resolving morphTarget names into indices.
|
||||
if ( ! targetObject.geometry ) {
|
||||
|
||||
console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( ! targetObject.geometry.morphTargets ) {
|
||||
|
||||
console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
|
||||
|
||||
if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
|
||||
|
||||
propertyIndex = i;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bindingType = this.BindingType.ArrayElement;
|
||||
|
||||
this.resolvedProperty = nodeProperty;
|
||||
this.propertyIndex = propertyIndex;
|
||||
|
||||
} else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
|
||||
// must use copy for Object3D.Euler/Quaternion
|
||||
|
||||
bindingType = this.BindingType.HasFromToArray;
|
||||
|
||||
this.resolvedProperty = nodeProperty;
|
||||
|
||||
} else if ( nodeProperty.length !== undefined ) {
|
||||
|
||||
bindingType = this.BindingType.EntireArray;
|
||||
|
||||
this.resolvedProperty = nodeProperty;
|
||||
|
||||
} else {
|
||||
|
||||
this.propertyName = propertyName;
|
||||
|
||||
}
|
||||
|
||||
// select getter / setter
|
||||
this.getValue = this.GetterByBindingType[ bindingType ];
|
||||
this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
|
||||
|
||||
},
|
||||
|
||||
unbind: function() {
|
||||
|
||||
this.node = null;
|
||||
|
||||
// back to the prototype version of getValue / setValue
|
||||
// note: avoiding to mutate the shape of 'this' via 'delete'
|
||||
this.getValue = this._getValue_unbound;
|
||||
this.setValue = this._setValue_unbound;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.assign( PropertyBinding.prototype, { // prototype, continued
|
||||
|
||||
// these are used to "bind" a nonexistent property
|
||||
_getValue_unavailable: function() {},
|
||||
_setValue_unavailable: function() {},
|
||||
|
||||
// initial state of these methods that calls 'bind'
|
||||
_getValue_unbound: PropertyBinding.prototype.getValue,
|
||||
_setValue_unbound: PropertyBinding.prototype.setValue,
|
||||
|
||||
BindingType: {
|
||||
Direct: 0,
|
||||
EntireArray: 1,
|
||||
ArrayElement: 2,
|
||||
HasFromToArray: 3
|
||||
},
|
||||
|
||||
Versioning: {
|
||||
None: 0,
|
||||
NeedsUpdate: 1,
|
||||
MatrixWorldNeedsUpdate: 2
|
||||
},
|
||||
|
||||
GetterByBindingType: [
|
||||
|
||||
function getValue_direct( buffer, offset ) {
|
||||
|
||||
buffer[ offset ] = this.node[ this.propertyName ];
|
||||
|
||||
},
|
||||
|
||||
function getValue_array( buffer, offset ) {
|
||||
|
||||
var source = this.resolvedProperty;
|
||||
|
||||
for ( var i = 0, n = source.length; i !== n; ++ i ) {
|
||||
|
||||
buffer[ offset ++ ] = source[ i ];
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
function getValue_arrayElement( buffer, offset ) {
|
||||
|
||||
buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
|
||||
|
||||
},
|
||||
|
||||
function getValue_toArray( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty.toArray( buffer, offset );
|
||||
|
||||
}
|
||||
|
||||
],
|
||||
|
||||
SetterByBindingTypeAndVersioning: [
|
||||
|
||||
[
|
||||
// Direct
|
||||
|
||||
function setValue_direct( buffer, offset ) {
|
||||
|
||||
this.node[ this.propertyName ] = buffer[ offset ];
|
||||
|
||||
},
|
||||
|
||||
function setValue_direct_setNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.node[ this.propertyName ] = buffer[ offset ];
|
||||
this.targetObject.needsUpdate = true;
|
||||
|
||||
},
|
||||
|
||||
function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.node[ this.propertyName ] = buffer[ offset ];
|
||||
this.targetObject.matrixWorldNeedsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
], [
|
||||
|
||||
// EntireArray
|
||||
|
||||
function setValue_array( buffer, offset ) {
|
||||
|
||||
var dest = this.resolvedProperty;
|
||||
|
||||
for ( var i = 0, n = dest.length; i !== n; ++ i ) {
|
||||
|
||||
dest[ i ] = buffer[ offset ++ ];
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
function setValue_array_setNeedsUpdate( buffer, offset ) {
|
||||
|
||||
var dest = this.resolvedProperty;
|
||||
|
||||
for ( var i = 0, n = dest.length; i !== n; ++ i ) {
|
||||
|
||||
dest[ i ] = buffer[ offset ++ ];
|
||||
|
||||
}
|
||||
|
||||
this.targetObject.needsUpdate = true;
|
||||
|
||||
},
|
||||
|
||||
function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
|
||||
|
||||
var dest = this.resolvedProperty;
|
||||
|
||||
for ( var i = 0, n = dest.length; i !== n; ++ i ) {
|
||||
|
||||
dest[ i ] = buffer[ offset ++ ];
|
||||
|
||||
}
|
||||
|
||||
this.targetObject.matrixWorldNeedsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
], [
|
||||
|
||||
// ArrayElement
|
||||
|
||||
function setValue_arrayElement( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
|
||||
|
||||
},
|
||||
|
||||
function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
|
||||
this.targetObject.needsUpdate = true;
|
||||
|
||||
},
|
||||
|
||||
function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
|
||||
this.targetObject.matrixWorldNeedsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
], [
|
||||
|
||||
// HasToFromArray
|
||||
|
||||
function setValue_fromArray( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty.fromArray( buffer, offset );
|
||||
|
||||
},
|
||||
|
||||
function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty.fromArray( buffer, offset );
|
||||
this.targetObject.needsUpdate = true;
|
||||
|
||||
},
|
||||
|
||||
function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty.fromArray( buffer, offset );
|
||||
this.targetObject.matrixWorldNeedsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
]
|
||||
|
||||
} );
|
||||
|
||||
PropertyBinding.Composite =
|
||||
function( targetGroup, path, optionalParsedPath ) {
|
||||
|
||||
var parsedPath = optionalParsedPath ||
|
||||
PropertyBinding.parseTrackName( path );
|
||||
|
||||
this._targetGroup = targetGroup;
|
||||
this._bindings = targetGroup.subscribe_( path, parsedPath );
|
||||
|
||||
};
|
||||
|
||||
PropertyBinding.Composite.prototype = {
|
||||
|
||||
constructor: PropertyBinding.Composite,
|
||||
|
||||
getValue: function( array, offset ) {
|
||||
|
||||
this.bind(); // bind all binding
|
||||
|
||||
var firstValidIndex = this._targetGroup.nCachedObjects_,
|
||||
binding = this._bindings[ firstValidIndex ];
|
||||
|
||||
// and only call .getValue on the first
|
||||
if ( binding !== undefined ) binding.getValue( array, offset );
|
||||
|
||||
},
|
||||
|
||||
setValue: function( array, offset ) {
|
||||
|
||||
var bindings = this._bindings;
|
||||
|
||||
for ( var i = this._targetGroup.nCachedObjects_,
|
||||
n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
bindings[ i ].setValue( array, offset );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
bind: function() {
|
||||
|
||||
var bindings = this._bindings;
|
||||
|
||||
for ( var i = this._targetGroup.nCachedObjects_,
|
||||
n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
bindings[ i ].bind();
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
unbind: function() {
|
||||
|
||||
var bindings = this._bindings;
|
||||
|
||||
for ( var i = this._targetGroup.nCachedObjects_,
|
||||
n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
bindings[ i ].unbind();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
PropertyBinding.create = function( root, path, parsedPath ) {
|
||||
|
||||
if ( ! ( root && root.isAnimationObjectGroup ) ) {
|
||||
|
||||
return new PropertyBinding( root, path, parsedPath );
|
||||
|
||||
} else {
|
||||
|
||||
return new PropertyBinding.Composite( root, path, parsedPath );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
PropertyBinding.parseTrackName = function( trackName ) {
|
||||
|
||||
// matches strings in the form of:
|
||||
// nodeName.property
|
||||
// nodeName.property[accessor]
|
||||
// nodeName.material.property[accessor]
|
||||
// uuid.property[accessor]
|
||||
// uuid.objectName[objectIndex].propertyName[propertyIndex]
|
||||
// parentName/nodeName.property
|
||||
// parentName/parentName/nodeName.property[index]
|
||||
// .bone[Armature.DEF_cog].position
|
||||
// scene:helium_balloon_model:helium_balloon_model.position
|
||||
// created and tested via https://regex101.com/#javascript
|
||||
|
||||
var re = /^((?:[\w-]+[\/:])*)([\w-]+)?(?:\.([\w-]+)(?:\[(.+)\])?)?\.([\w-]+)(?:\[(.+)\])?$/;
|
||||
var matches = re.exec( trackName );
|
||||
|
||||
if ( ! matches ) {
|
||||
|
||||
throw new Error( "cannot parse trackName at all: " + trackName );
|
||||
|
||||
}
|
||||
|
||||
var results = {
|
||||
// directoryName: matches[ 1 ], // (tschw) currently unused
|
||||
nodeName: matches[ 2 ], // allowed to be null, specified root node.
|
||||
objectName: matches[ 3 ],
|
||||
objectIndex: matches[ 4 ],
|
||||
propertyName: matches[ 5 ],
|
||||
propertyIndex: matches[ 6 ] // allowed to be null, specifies that the whole property is set.
|
||||
};
|
||||
|
||||
if ( results.propertyName === null || results.propertyName.length === 0 ) {
|
||||
|
||||
throw new Error( "can not parse propertyName from trackName: " + trackName );
|
||||
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
};
|
||||
|
||||
PropertyBinding.findNode = function( root, nodeName ) {
|
||||
|
||||
if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
|
||||
|
||||
return root;
|
||||
|
||||
}
|
||||
|
||||
// search into skeleton bones.
|
||||
if ( root.skeleton ) {
|
||||
|
||||
var searchSkeleton = function( skeleton ) {
|
||||
|
||||
for( var i = 0; i < skeleton.bones.length; i ++ ) {
|
||||
|
||||
var bone = skeleton.bones[ i ];
|
||||
|
||||
if ( bone.name === nodeName ) {
|
||||
|
||||
return bone;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
};
|
||||
|
||||
var bone = searchSkeleton( root.skeleton );
|
||||
|
||||
if ( bone ) {
|
||||
|
||||
return bone;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// search into node subtree.
|
||||
if ( root.children ) {
|
||||
|
||||
var searchNodeSubtree = function( children ) {
|
||||
|
||||
for( var i = 0; i < children.length; i ++ ) {
|
||||
|
||||
var childNode = children[ i ];
|
||||
|
||||
if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
|
||||
|
||||
return childNode;
|
||||
|
||||
}
|
||||
|
||||
var result = searchNodeSubtree( childNode.children );
|
||||
|
||||
if ( result ) return result;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
};
|
||||
|
||||
var subTreeNode = searchNodeSubtree( root.children );
|
||||
|
||||
if ( subTreeNode ) {
|
||||
|
||||
return subTreeNode;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { PropertyBinding };
|
||||
212
node_modules/three/src/animation/PropertyMixer.js
generated
vendored
Normal file
212
node_modules/three/src/animation/PropertyMixer.js
generated
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
import { Quaternion } from '../math/Quaternion';
|
||||
|
||||
/**
|
||||
*
|
||||
* Buffered scene graph property that allows weighted accumulation.
|
||||
*
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function PropertyMixer( binding, typeName, valueSize ) {
|
||||
|
||||
this.binding = binding;
|
||||
this.valueSize = valueSize;
|
||||
|
||||
var bufferType = Float64Array,
|
||||
mixFunction;
|
||||
|
||||
switch ( typeName ) {
|
||||
|
||||
case 'quaternion':
|
||||
mixFunction = this._slerp;
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
case 'bool':
|
||||
bufferType = Array;
|
||||
mixFunction = this._select;
|
||||
break;
|
||||
|
||||
default:
|
||||
mixFunction = this._lerp;
|
||||
|
||||
}
|
||||
|
||||
this.buffer = new bufferType( valueSize * 4 );
|
||||
// layout: [ incoming | accu0 | accu1 | orig ]
|
||||
//
|
||||
// interpolators can use .buffer as their .result
|
||||
// the data then goes to 'incoming'
|
||||
//
|
||||
// 'accu0' and 'accu1' are used frame-interleaved for
|
||||
// the cumulative result and are compared to detect
|
||||
// changes
|
||||
//
|
||||
// 'orig' stores the original state of the property
|
||||
|
||||
this._mixBufferRegion = mixFunction;
|
||||
|
||||
this.cumulativeWeight = 0;
|
||||
|
||||
this.useCount = 0;
|
||||
this.referenceCount = 0;
|
||||
|
||||
}
|
||||
|
||||
PropertyMixer.prototype = {
|
||||
|
||||
constructor: PropertyMixer,
|
||||
|
||||
// accumulate data in the 'incoming' region into 'accu<i>'
|
||||
accumulate: function( accuIndex, weight ) {
|
||||
|
||||
// note: happily accumulating nothing when weight = 0, the caller knows
|
||||
// the weight and shouldn't have made the call in the first place
|
||||
|
||||
var buffer = this.buffer,
|
||||
stride = this.valueSize,
|
||||
offset = accuIndex * stride + stride,
|
||||
|
||||
currentWeight = this.cumulativeWeight;
|
||||
|
||||
if ( currentWeight === 0 ) {
|
||||
|
||||
// accuN := incoming * weight
|
||||
|
||||
for ( var i = 0; i !== stride; ++ i ) {
|
||||
|
||||
buffer[ offset + i ] = buffer[ i ];
|
||||
|
||||
}
|
||||
|
||||
currentWeight = weight;
|
||||
|
||||
} else {
|
||||
|
||||
// accuN := accuN + incoming * weight
|
||||
|
||||
currentWeight += weight;
|
||||
var mix = weight / currentWeight;
|
||||
this._mixBufferRegion( buffer, offset, 0, mix, stride );
|
||||
|
||||
}
|
||||
|
||||
this.cumulativeWeight = currentWeight;
|
||||
|
||||
},
|
||||
|
||||
// apply the state of 'accu<i>' to the binding when accus differ
|
||||
apply: function( accuIndex ) {
|
||||
|
||||
var stride = this.valueSize,
|
||||
buffer = this.buffer,
|
||||
offset = accuIndex * stride + stride,
|
||||
|
||||
weight = this.cumulativeWeight,
|
||||
|
||||
binding = this.binding;
|
||||
|
||||
this.cumulativeWeight = 0;
|
||||
|
||||
if ( weight < 1 ) {
|
||||
|
||||
// accuN := accuN + original * ( 1 - cumulativeWeight )
|
||||
|
||||
var originalValueOffset = stride * 3;
|
||||
|
||||
this._mixBufferRegion(
|
||||
buffer, offset, originalValueOffset, 1 - weight, stride );
|
||||
|
||||
}
|
||||
|
||||
for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
|
||||
|
||||
if ( buffer[ i ] !== buffer[ i + stride ] ) {
|
||||
|
||||
// value has changed -> update scene graph
|
||||
|
||||
binding.setValue( buffer, offset );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// remember the state of the bound property and copy it to both accus
|
||||
saveOriginalState: function() {
|
||||
|
||||
var binding = this.binding;
|
||||
|
||||
var buffer = this.buffer,
|
||||
stride = this.valueSize,
|
||||
|
||||
originalValueOffset = stride * 3;
|
||||
|
||||
binding.getValue( buffer, originalValueOffset );
|
||||
|
||||
// accu[0..1] := orig -- initially detect changes against the original
|
||||
for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
|
||||
|
||||
buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
|
||||
|
||||
}
|
||||
|
||||
this.cumulativeWeight = 0;
|
||||
|
||||
},
|
||||
|
||||
// apply the state previously taken via 'saveOriginalState' to the binding
|
||||
restoreOriginalState: function() {
|
||||
|
||||
var originalValueOffset = this.valueSize * 3;
|
||||
this.binding.setValue( this.buffer, originalValueOffset );
|
||||
|
||||
},
|
||||
|
||||
|
||||
// mix functions
|
||||
|
||||
_select: function( buffer, dstOffset, srcOffset, t, stride ) {
|
||||
|
||||
if ( t >= 0.5 ) {
|
||||
|
||||
for ( var i = 0; i !== stride; ++ i ) {
|
||||
|
||||
buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
|
||||
|
||||
Quaternion.slerpFlat( buffer, dstOffset,
|
||||
buffer, dstOffset, buffer, srcOffset, t );
|
||||
|
||||
},
|
||||
|
||||
_lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
|
||||
|
||||
var s = 1 - t;
|
||||
|
||||
for ( var i = 0; i !== stride; ++ i ) {
|
||||
|
||||
var j = dstOffset + i;
|
||||
|
||||
buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { PropertyMixer };
|
||||
41
node_modules/three/src/animation/tracks/BooleanKeyframeTrack.js
generated
vendored
Normal file
41
node_modules/three/src/animation/tracks/BooleanKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { InterpolateDiscrete } from '../../constants';
|
||||
import { KeyframeTrackPrototype } from '../KeyframeTrackPrototype';
|
||||
import { KeyframeTrackConstructor } from '../KeyframeTrackConstructor';
|
||||
|
||||
/**
|
||||
*
|
||||
* A Track of Boolean keyframe values.
|
||||
*
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function BooleanKeyframeTrack( name, times, values ) {
|
||||
|
||||
KeyframeTrackConstructor.call( this, name, times, values );
|
||||
|
||||
}
|
||||
|
||||
BooleanKeyframeTrack.prototype =
|
||||
Object.assign( Object.create( KeyframeTrackPrototype ), {
|
||||
|
||||
constructor: BooleanKeyframeTrack,
|
||||
|
||||
ValueTypeName: 'bool',
|
||||
ValueBufferType: Array,
|
||||
|
||||
DefaultInterpolation: InterpolateDiscrete,
|
||||
|
||||
InterpolantFactoryMethodLinear: undefined,
|
||||
InterpolantFactoryMethodSmooth: undefined
|
||||
|
||||
// Note: Actually this track could have a optimized / compressed
|
||||
// representation of a single value and a custom interpolant that
|
||||
// computes "firstValue ^ isOdd( index )".
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { BooleanKeyframeTrack };
|
||||
38
node_modules/three/src/animation/tracks/ColorKeyframeTrack.js
generated
vendored
Normal file
38
node_modules/three/src/animation/tracks/ColorKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import { KeyframeTrackPrototype } from '../KeyframeTrackPrototype';
|
||||
import { KeyframeTrackConstructor } from '../KeyframeTrackConstructor';
|
||||
|
||||
/**
|
||||
*
|
||||
* A Track of keyframe values that represent color.
|
||||
*
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function ColorKeyframeTrack( name, times, values, interpolation ) {
|
||||
|
||||
KeyframeTrackConstructor.call( this, name, times, values, interpolation );
|
||||
|
||||
}
|
||||
|
||||
ColorKeyframeTrack.prototype =
|
||||
Object.assign( Object.create( KeyframeTrackPrototype ), {
|
||||
|
||||
constructor: ColorKeyframeTrack,
|
||||
|
||||
ValueTypeName: 'color'
|
||||
|
||||
// ValueBufferType is inherited
|
||||
|
||||
// DefaultInterpolation is inherited
|
||||
|
||||
|
||||
// Note: Very basic implementation and nothing special yet.
|
||||
// However, this is the place for color space parameterization.
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { ColorKeyframeTrack };
|
||||
33
node_modules/three/src/animation/tracks/NumberKeyframeTrack.js
generated
vendored
Normal file
33
node_modules/three/src/animation/tracks/NumberKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { KeyframeTrackPrototype } from '../KeyframeTrackPrototype';
|
||||
import { KeyframeTrackConstructor } from '../KeyframeTrackConstructor';
|
||||
|
||||
/**
|
||||
*
|
||||
* A Track of numeric keyframe values.
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function NumberKeyframeTrack( name, times, values, interpolation ) {
|
||||
|
||||
KeyframeTrackConstructor.call( this, name, times, values, interpolation );
|
||||
|
||||
}
|
||||
|
||||
NumberKeyframeTrack.prototype =
|
||||
Object.assign( Object.create( KeyframeTrackPrototype ), {
|
||||
|
||||
constructor: NumberKeyframeTrack,
|
||||
|
||||
ValueTypeName: 'number'
|
||||
|
||||
// ValueBufferType is inherited
|
||||
|
||||
// DefaultInterpolation is inherited
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { NumberKeyframeTrack };
|
||||
44
node_modules/three/src/animation/tracks/QuaternionKeyframeTrack.js
generated
vendored
Normal file
44
node_modules/three/src/animation/tracks/QuaternionKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import { InterpolateLinear } from '../../constants';
|
||||
import { KeyframeTrackPrototype } from '../KeyframeTrackPrototype';
|
||||
import { QuaternionLinearInterpolant } from '../../math/interpolants/QuaternionLinearInterpolant';
|
||||
import { KeyframeTrackConstructor } from '../KeyframeTrackConstructor';
|
||||
|
||||
/**
|
||||
*
|
||||
* A Track of quaternion keyframe values.
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function QuaternionKeyframeTrack( name, times, values, interpolation ) {
|
||||
|
||||
KeyframeTrackConstructor.call( this, name, times, values, interpolation );
|
||||
|
||||
}
|
||||
|
||||
QuaternionKeyframeTrack.prototype =
|
||||
Object.assign( Object.create( KeyframeTrackPrototype ), {
|
||||
|
||||
constructor: QuaternionKeyframeTrack,
|
||||
|
||||
ValueTypeName: 'quaternion',
|
||||
|
||||
// ValueBufferType is inherited
|
||||
|
||||
DefaultInterpolation: InterpolateLinear,
|
||||
|
||||
InterpolantFactoryMethodLinear: function( result ) {
|
||||
|
||||
return new QuaternionLinearInterpolant(
|
||||
this.times, this.values, this.getValueSize(), result );
|
||||
|
||||
},
|
||||
|
||||
InterpolantFactoryMethodSmooth: undefined // not yet implemented
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { QuaternionKeyframeTrack };
|
||||
38
node_modules/three/src/animation/tracks/StringKeyframeTrack.js
generated
vendored
Normal file
38
node_modules/three/src/animation/tracks/StringKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import { InterpolateDiscrete } from '../../constants';
|
||||
import { KeyframeTrackPrototype } from '../KeyframeTrackPrototype';
|
||||
import { KeyframeTrackConstructor } from '../KeyframeTrackConstructor';
|
||||
|
||||
/**
|
||||
*
|
||||
* A Track that interpolates Strings
|
||||
*
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function StringKeyframeTrack( name, times, values, interpolation ) {
|
||||
|
||||
KeyframeTrackConstructor.call( this, name, times, values, interpolation );
|
||||
|
||||
}
|
||||
|
||||
StringKeyframeTrack.prototype =
|
||||
Object.assign( Object.create( KeyframeTrackPrototype ), {
|
||||
|
||||
constructor: StringKeyframeTrack,
|
||||
|
||||
ValueTypeName: 'string',
|
||||
ValueBufferType: Array,
|
||||
|
||||
DefaultInterpolation: InterpolateDiscrete,
|
||||
|
||||
InterpolantFactoryMethodLinear: undefined,
|
||||
|
||||
InterpolantFactoryMethodSmooth: undefined
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { StringKeyframeTrack };
|
||||
34
node_modules/three/src/animation/tracks/VectorKeyframeTrack.js
generated
vendored
Normal file
34
node_modules/three/src/animation/tracks/VectorKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { KeyframeTrackPrototype } from '../KeyframeTrackPrototype';
|
||||
import { KeyframeTrackConstructor } from '../KeyframeTrackConstructor';
|
||||
|
||||
/**
|
||||
*
|
||||
* A Track of vectored keyframe values.
|
||||
*
|
||||
*
|
||||
* @author Ben Houston / http://clara.io/
|
||||
* @author David Sarno / http://lighthaus.us/
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function VectorKeyframeTrack( name, times, values, interpolation ) {
|
||||
|
||||
KeyframeTrackConstructor.call( this, name, times, values, interpolation );
|
||||
|
||||
}
|
||||
|
||||
VectorKeyframeTrack.prototype =
|
||||
Object.assign( Object.create( KeyframeTrackPrototype ), {
|
||||
|
||||
constructor: VectorKeyframeTrack,
|
||||
|
||||
ValueTypeName: 'vector'
|
||||
|
||||
// ValueBufferType is inherited
|
||||
|
||||
// DefaultInterpolation is inherited
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { VectorKeyframeTrack };
|
||||
301
node_modules/three/src/audio/Audio.js
generated
vendored
Normal file
301
node_modules/three/src/audio/Audio.js
generated
vendored
Normal file
@@ -0,0 +1,301 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author Reece Aaron Lecrivain / http://reecenotes.com/
|
||||
*/
|
||||
|
||||
import { Object3D } from '../core/Object3D';
|
||||
|
||||
function Audio( listener ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.type = 'Audio';
|
||||
|
||||
this.context = listener.context;
|
||||
|
||||
this.gain = this.context.createGain();
|
||||
this.gain.connect( listener.getInput() );
|
||||
|
||||
this.autoplay = false;
|
||||
|
||||
this.buffer = null;
|
||||
this.loop = false;
|
||||
this.startTime = 0;
|
||||
this.playbackRate = 1;
|
||||
this.isPlaying = false;
|
||||
this.hasPlaybackControl = true;
|
||||
this.sourceType = 'empty';
|
||||
|
||||
this.filters = [];
|
||||
|
||||
}
|
||||
|
||||
Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
||||
|
||||
constructor: Audio,
|
||||
|
||||
getOutput: function () {
|
||||
|
||||
return this.gain;
|
||||
|
||||
},
|
||||
|
||||
setNodeSource: function ( audioNode ) {
|
||||
|
||||
this.hasPlaybackControl = false;
|
||||
this.sourceType = 'audioNode';
|
||||
this.source = audioNode;
|
||||
this.connect();
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setBuffer: function ( audioBuffer ) {
|
||||
|
||||
this.buffer = audioBuffer;
|
||||
this.sourceType = 'buffer';
|
||||
|
||||
if ( this.autoplay ) this.play();
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
play: function () {
|
||||
|
||||
if ( this.isPlaying === true ) {
|
||||
|
||||
console.warn( 'THREE.Audio: Audio is already playing.' );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( this.hasPlaybackControl === false ) {
|
||||
|
||||
console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
var source = this.context.createBufferSource();
|
||||
|
||||
source.buffer = this.buffer;
|
||||
source.loop = this.loop;
|
||||
source.onended = this.onEnded.bind( this );
|
||||
source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
|
||||
source.start( 0, this.startTime );
|
||||
|
||||
this.isPlaying = true;
|
||||
|
||||
this.source = source;
|
||||
|
||||
return this.connect();
|
||||
|
||||
},
|
||||
|
||||
pause: function () {
|
||||
|
||||
if ( this.hasPlaybackControl === false ) {
|
||||
|
||||
console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this.source.stop();
|
||||
this.startTime = this.context.currentTime;
|
||||
this.isPlaying = false;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
stop: function () {
|
||||
|
||||
if ( this.hasPlaybackControl === false ) {
|
||||
|
||||
console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this.source.stop();
|
||||
this.startTime = 0;
|
||||
this.isPlaying = false;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
connect: function () {
|
||||
|
||||
if ( this.filters.length > 0 ) {
|
||||
|
||||
this.source.connect( this.filters[ 0 ] );
|
||||
|
||||
for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
|
||||
|
||||
this.filters[ i - 1 ].connect( this.filters[ i ] );
|
||||
|
||||
}
|
||||
|
||||
this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
|
||||
|
||||
} else {
|
||||
|
||||
this.source.connect( this.getOutput() );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
disconnect: function () {
|
||||
|
||||
if ( this.filters.length > 0 ) {
|
||||
|
||||
this.source.disconnect( this.filters[ 0 ] );
|
||||
|
||||
for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
|
||||
|
||||
this.filters[ i - 1 ].disconnect( this.filters[ i ] );
|
||||
|
||||
}
|
||||
|
||||
this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
|
||||
|
||||
} else {
|
||||
|
||||
this.source.disconnect( this.getOutput() );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
getFilters: function () {
|
||||
|
||||
return this.filters;
|
||||
|
||||
},
|
||||
|
||||
setFilters: function ( value ) {
|
||||
|
||||
if ( ! value ) value = [];
|
||||
|
||||
if ( this.isPlaying === true ) {
|
||||
|
||||
this.disconnect();
|
||||
this.filters = value;
|
||||
this.connect();
|
||||
|
||||
} else {
|
||||
|
||||
this.filters = value;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
getFilter: function () {
|
||||
|
||||
return this.getFilters()[ 0 ];
|
||||
|
||||
},
|
||||
|
||||
setFilter: function ( filter ) {
|
||||
|
||||
return this.setFilters( filter ? [ filter ] : [] );
|
||||
|
||||
},
|
||||
|
||||
setPlaybackRate: function ( value ) {
|
||||
|
||||
if ( this.hasPlaybackControl === false ) {
|
||||
|
||||
console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this.playbackRate = value;
|
||||
|
||||
if ( this.isPlaying === true ) {
|
||||
|
||||
this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
getPlaybackRate: function () {
|
||||
|
||||
return this.playbackRate;
|
||||
|
||||
},
|
||||
|
||||
onEnded: function () {
|
||||
|
||||
this.isPlaying = false;
|
||||
|
||||
},
|
||||
|
||||
getLoop: function () {
|
||||
|
||||
if ( this.hasPlaybackControl === false ) {
|
||||
|
||||
console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return this.loop;
|
||||
|
||||
},
|
||||
|
||||
setLoop: function ( value ) {
|
||||
|
||||
if ( this.hasPlaybackControl === false ) {
|
||||
|
||||
console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this.loop = value;
|
||||
|
||||
if ( this.isPlaying === true ) {
|
||||
|
||||
this.source.loop = this.loop;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
getVolume: function () {
|
||||
|
||||
return this.gain.gain.value;
|
||||
|
||||
},
|
||||
|
||||
|
||||
setVolume: function ( value ) {
|
||||
|
||||
this.gain.gain.value = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
export { Audio };
|
||||
42
node_modules/three/src/audio/AudioAnalyser.js
generated
vendored
Normal file
42
node_modules/three/src/audio/AudioAnalyser.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function AudioAnalyser( audio, fftSize ) {
|
||||
|
||||
this.analyser = audio.context.createAnalyser();
|
||||
this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
|
||||
|
||||
this.data = new Uint8Array( this.analyser.frequencyBinCount );
|
||||
|
||||
audio.getOutput().connect( this.analyser );
|
||||
|
||||
}
|
||||
|
||||
Object.assign( AudioAnalyser.prototype, {
|
||||
|
||||
getFrequencyData: function () {
|
||||
|
||||
this.analyser.getByteFrequencyData( this.data );
|
||||
|
||||
return this.data;
|
||||
|
||||
},
|
||||
|
||||
getAverageFrequency: function () {
|
||||
|
||||
var value = 0, data = this.getFrequencyData();
|
||||
|
||||
for ( var i = 0; i < data.length; i ++ ) {
|
||||
|
||||
value += data[ i ];
|
||||
|
||||
}
|
||||
|
||||
return value / data.length;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
export { AudioAnalyser };
|
||||
25
node_modules/three/src/audio/AudioContext.js
generated
vendored
Normal file
25
node_modules/three/src/audio/AudioContext.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var context;
|
||||
|
||||
var AudioContext = {
|
||||
|
||||
getContext: function () {
|
||||
|
||||
if ( context === undefined ) {
|
||||
|
||||
context = new ( window.AudioContext || window.webkitAudioContext )();
|
||||
|
||||
}
|
||||
|
||||
return context;
|
||||
|
||||
},
|
||||
|
||||
setContext: function ( value ) {
|
||||
|
||||
context = value;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export { AudioContext };
|
||||
129
node_modules/three/src/audio/AudioListener.js
generated
vendored
Normal file
129
node_modules/three/src/audio/AudioListener.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Quaternion } from '../math/Quaternion';
|
||||
import { Object3D } from '../core/Object3D';
|
||||
import { AudioContext } from './AudioContext';
|
||||
|
||||
function AudioListener() {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.type = 'AudioListener';
|
||||
|
||||
this.context = AudioContext.getContext();
|
||||
|
||||
this.gain = this.context.createGain();
|
||||
this.gain.connect( this.context.destination );
|
||||
|
||||
this.filter = null;
|
||||
|
||||
}
|
||||
|
||||
AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
||||
|
||||
constructor: AudioListener,
|
||||
|
||||
getInput: function () {
|
||||
|
||||
return this.gain;
|
||||
|
||||
},
|
||||
|
||||
removeFilter: function ( ) {
|
||||
|
||||
if ( this.filter !== null ) {
|
||||
|
||||
this.gain.disconnect( this.filter );
|
||||
this.filter.disconnect( this.context.destination );
|
||||
this.gain.connect( this.context.destination );
|
||||
this.filter = null;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getFilter: function () {
|
||||
|
||||
return this.filter;
|
||||
|
||||
},
|
||||
|
||||
setFilter: function ( value ) {
|
||||
|
||||
if ( this.filter !== null ) {
|
||||
|
||||
this.gain.disconnect( this.filter );
|
||||
this.filter.disconnect( this.context.destination );
|
||||
|
||||
} else {
|
||||
|
||||
this.gain.disconnect( this.context.destination );
|
||||
|
||||
}
|
||||
|
||||
this.filter = value;
|
||||
this.gain.connect( this.filter );
|
||||
this.filter.connect( this.context.destination );
|
||||
|
||||
},
|
||||
|
||||
getMasterVolume: function () {
|
||||
|
||||
return this.gain.gain.value;
|
||||
|
||||
},
|
||||
|
||||
setMasterVolume: function ( value ) {
|
||||
|
||||
this.gain.gain.value = value;
|
||||
|
||||
},
|
||||
|
||||
updateMatrixWorld: ( function () {
|
||||
|
||||
var position = new Vector3();
|
||||
var quaternion = new Quaternion();
|
||||
var scale = new Vector3();
|
||||
|
||||
var orientation = new Vector3();
|
||||
|
||||
return function updateMatrixWorld( force ) {
|
||||
|
||||
Object3D.prototype.updateMatrixWorld.call( this, force );
|
||||
|
||||
var listener = this.context.listener;
|
||||
var up = this.up;
|
||||
|
||||
this.matrixWorld.decompose( position, quaternion, scale );
|
||||
|
||||
orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
|
||||
|
||||
if ( listener.positionX ) {
|
||||
|
||||
listener.positionX.setValueAtTime( position.x, this.context.currentTime );
|
||||
listener.positionY.setValueAtTime( position.y, this.context.currentTime );
|
||||
listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
|
||||
listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
|
||||
listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
|
||||
listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
|
||||
listener.upX.setValueAtTime( up.x, this.context.currentTime );
|
||||
listener.upY.setValueAtTime( up.y, this.context.currentTime );
|
||||
listener.upZ.setValueAtTime( up.z, this.context.currentTime );
|
||||
|
||||
} else {
|
||||
|
||||
listener.setPosition( position.x, position.y, position.z );
|
||||
listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} )()
|
||||
|
||||
} );
|
||||
|
||||
export { AudioListener };
|
||||
95
node_modules/three/src/audio/PositionalAudio.js
generated
vendored
Normal file
95
node_modules/three/src/audio/PositionalAudio.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Audio } from './Audio';
|
||||
import { Object3D } from '../core/Object3D';
|
||||
|
||||
function PositionalAudio( listener ) {
|
||||
|
||||
Audio.call( this, listener );
|
||||
|
||||
this.panner = this.context.createPanner();
|
||||
this.panner.connect( this.gain );
|
||||
|
||||
}
|
||||
|
||||
PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
|
||||
|
||||
constructor: PositionalAudio,
|
||||
|
||||
getOutput: function () {
|
||||
|
||||
return this.panner;
|
||||
|
||||
},
|
||||
|
||||
getRefDistance: function () {
|
||||
|
||||
return this.panner.refDistance;
|
||||
|
||||
},
|
||||
|
||||
setRefDistance: function ( value ) {
|
||||
|
||||
this.panner.refDistance = value;
|
||||
|
||||
},
|
||||
|
||||
getRolloffFactor: function () {
|
||||
|
||||
return this.panner.rolloffFactor;
|
||||
|
||||
},
|
||||
|
||||
setRolloffFactor: function ( value ) {
|
||||
|
||||
this.panner.rolloffFactor = value;
|
||||
|
||||
},
|
||||
|
||||
getDistanceModel: function () {
|
||||
|
||||
return this.panner.distanceModel;
|
||||
|
||||
},
|
||||
|
||||
setDistanceModel: function ( value ) {
|
||||
|
||||
this.panner.distanceModel = value;
|
||||
|
||||
},
|
||||
|
||||
getMaxDistance: function () {
|
||||
|
||||
return this.panner.maxDistance;
|
||||
|
||||
},
|
||||
|
||||
setMaxDistance: function ( value ) {
|
||||
|
||||
this.panner.maxDistance = value;
|
||||
|
||||
},
|
||||
|
||||
updateMatrixWorld: ( function () {
|
||||
|
||||
var position = new Vector3();
|
||||
|
||||
return function updateMatrixWorld( force ) {
|
||||
|
||||
Object3D.prototype.updateMatrixWorld.call( this, force );
|
||||
|
||||
position.setFromMatrixPosition( this.matrixWorld );
|
||||
|
||||
this.panner.setPosition( position.x, position.y, position.z );
|
||||
|
||||
};
|
||||
|
||||
} )()
|
||||
|
||||
|
||||
} );
|
||||
|
||||
export { PositionalAudio };
|
||||
78
node_modules/three/src/cameras/Camera.js
generated
vendored
Normal file
78
node_modules/three/src/cameras/Camera.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
import { Matrix4 } from '../math/Matrix4';
|
||||
import { Quaternion } from '../math/Quaternion';
|
||||
import { Object3D } from '../core/Object3D';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author mikael emtinger / http://gomo.se/
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
function Camera() {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.type = 'Camera';
|
||||
|
||||
this.matrixWorldInverse = new Matrix4();
|
||||
this.projectionMatrix = new Matrix4();
|
||||
|
||||
}
|
||||
|
||||
Camera.prototype = Object.create( Object3D.prototype );
|
||||
Camera.prototype.constructor = Camera;
|
||||
|
||||
Camera.prototype.isCamera = true;
|
||||
|
||||
Camera.prototype.getWorldDirection = function () {
|
||||
|
||||
var quaternion = new Quaternion();
|
||||
|
||||
return function getWorldDirection( optionalTarget ) {
|
||||
|
||||
var result = optionalTarget || new Vector3();
|
||||
|
||||
this.getWorldQuaternion( quaternion );
|
||||
|
||||
return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
Camera.prototype.lookAt = function () {
|
||||
|
||||
// This routine does not support cameras with rotated and/or translated parent(s)
|
||||
|
||||
var m1 = new Matrix4();
|
||||
|
||||
return function lookAt( vector ) {
|
||||
|
||||
m1.lookAt( this.position, vector, this.up );
|
||||
|
||||
this.quaternion.setFromRotationMatrix( m1 );
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
Camera.prototype.clone = function () {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
};
|
||||
|
||||
Camera.prototype.copy = function ( source ) {
|
||||
|
||||
Object3D.prototype.copy.call( this, source );
|
||||
|
||||
this.matrixWorldInverse.copy( source.matrixWorldInverse );
|
||||
this.projectionMatrix.copy( source.projectionMatrix );
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { Camera };
|
||||
95
node_modules/three/src/cameras/CubeCamera.js
generated
vendored
Normal file
95
node_modules/three/src/cameras/CubeCamera.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import { Object3D } from '../core/Object3D';
|
||||
import { WebGLRenderTargetCube } from '../renderers/WebGLRenderTargetCube';
|
||||
import { LinearFilter, RGBFormat } from '../constants';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { PerspectiveCamera } from './PerspectiveCamera';
|
||||
|
||||
/**
|
||||
* Camera for rendering cube maps
|
||||
* - renders scene into axis-aligned cube
|
||||
*
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
function CubeCamera( near, far, cubeResolution ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.type = 'CubeCamera';
|
||||
|
||||
var fov = 90, aspect = 1;
|
||||
|
||||
var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraPX.up.set( 0, - 1, 0 );
|
||||
cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
|
||||
this.add( cameraPX );
|
||||
|
||||
var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraNX.up.set( 0, - 1, 0 );
|
||||
cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
|
||||
this.add( cameraNX );
|
||||
|
||||
var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraPY.up.set( 0, 0, 1 );
|
||||
cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
|
||||
this.add( cameraPY );
|
||||
|
||||
var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraNY.up.set( 0, 0, - 1 );
|
||||
cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
|
||||
this.add( cameraNY );
|
||||
|
||||
var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraPZ.up.set( 0, - 1, 0 );
|
||||
cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
|
||||
this.add( cameraPZ );
|
||||
|
||||
var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraNZ.up.set( 0, - 1, 0 );
|
||||
cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
|
||||
this.add( cameraNZ );
|
||||
|
||||
var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
|
||||
|
||||
this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
|
||||
|
||||
this.updateCubeMap = function ( renderer, scene ) {
|
||||
|
||||
if ( this.parent === null ) this.updateMatrixWorld();
|
||||
|
||||
var renderTarget = this.renderTarget;
|
||||
var generateMipmaps = renderTarget.texture.generateMipmaps;
|
||||
|
||||
renderTarget.texture.generateMipmaps = false;
|
||||
|
||||
renderTarget.activeCubeFace = 0;
|
||||
renderer.render( scene, cameraPX, renderTarget );
|
||||
|
||||
renderTarget.activeCubeFace = 1;
|
||||
renderer.render( scene, cameraNX, renderTarget );
|
||||
|
||||
renderTarget.activeCubeFace = 2;
|
||||
renderer.render( scene, cameraPY, renderTarget );
|
||||
|
||||
renderTarget.activeCubeFace = 3;
|
||||
renderer.render( scene, cameraNY, renderTarget );
|
||||
|
||||
renderTarget.activeCubeFace = 4;
|
||||
renderer.render( scene, cameraPZ, renderTarget );
|
||||
|
||||
renderTarget.texture.generateMipmaps = generateMipmaps;
|
||||
|
||||
renderTarget.activeCubeFace = 5;
|
||||
renderer.render( scene, cameraNZ, renderTarget );
|
||||
|
||||
renderer.setRenderTarget( null );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
CubeCamera.prototype = Object.create( Object3D.prototype );
|
||||
CubeCamera.prototype.constructor = CubeCamera;
|
||||
|
||||
|
||||
export { CubeCamera };
|
||||
127
node_modules/three/src/cameras/OrthographicCamera.js
generated
vendored
Normal file
127
node_modules/three/src/cameras/OrthographicCamera.js
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
import { Camera } from './Camera';
|
||||
import { Object3D } from '../core/Object3D';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author arose / http://github.com/arose
|
||||
*/
|
||||
|
||||
function OrthographicCamera( left, right, top, bottom, near, far ) {
|
||||
|
||||
Camera.call( this );
|
||||
|
||||
this.type = 'OrthographicCamera';
|
||||
|
||||
this.zoom = 1;
|
||||
this.view = null;
|
||||
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.top = top;
|
||||
this.bottom = bottom;
|
||||
|
||||
this.near = ( near !== undefined ) ? near : 0.1;
|
||||
this.far = ( far !== undefined ) ? far : 2000;
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
|
||||
|
||||
constructor: OrthographicCamera,
|
||||
|
||||
isOrthographicCamera: true,
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
Camera.prototype.copy.call( this, source );
|
||||
|
||||
this.left = source.left;
|
||||
this.right = source.right;
|
||||
this.top = source.top;
|
||||
this.bottom = source.bottom;
|
||||
this.near = source.near;
|
||||
this.far = source.far;
|
||||
|
||||
this.zoom = source.zoom;
|
||||
this.view = source.view === null ? null : Object.assign( {}, source.view );
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setViewOffset: function( fullWidth, fullHeight, x, y, width, height ) {
|
||||
|
||||
this.view = {
|
||||
fullWidth: fullWidth,
|
||||
fullHeight: fullHeight,
|
||||
offsetX: x,
|
||||
offsetY: y,
|
||||
width: width,
|
||||
height: height
|
||||
};
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
},
|
||||
|
||||
clearViewOffset: function() {
|
||||
|
||||
this.view = null;
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
},
|
||||
|
||||
updateProjectionMatrix: function () {
|
||||
|
||||
var dx = ( this.right - this.left ) / ( 2 * this.zoom );
|
||||
var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
|
||||
var cx = ( this.right + this.left ) / 2;
|
||||
var cy = ( this.top + this.bottom ) / 2;
|
||||
|
||||
var left = cx - dx;
|
||||
var right = cx + dx;
|
||||
var top = cy + dy;
|
||||
var bottom = cy - dy;
|
||||
|
||||
if ( this.view !== null ) {
|
||||
|
||||
var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
|
||||
var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
|
||||
var scaleW = ( this.right - this.left ) / this.view.width;
|
||||
var scaleH = ( this.top - this.bottom ) / this.view.height;
|
||||
|
||||
left += scaleW * ( this.view.offsetX / zoomW );
|
||||
right = left + scaleW * ( this.view.width / zoomW );
|
||||
top -= scaleH * ( this.view.offsetY / zoomH );
|
||||
bottom = top - scaleH * ( this.view.height / zoomH );
|
||||
|
||||
}
|
||||
|
||||
this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
|
||||
|
||||
},
|
||||
|
||||
toJSON: function ( meta ) {
|
||||
|
||||
var data = Object3D.prototype.toJSON.call( this, meta );
|
||||
|
||||
data.object.zoom = this.zoom;
|
||||
data.object.left = this.left;
|
||||
data.object.right = this.right;
|
||||
data.object.top = this.top;
|
||||
data.object.bottom = this.bottom;
|
||||
data.object.near = this.near;
|
||||
data.object.far = this.far;
|
||||
|
||||
if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { OrthographicCamera };
|
||||
225
node_modules/three/src/cameras/PerspectiveCamera.js
generated
vendored
Normal file
225
node_modules/three/src/cameras/PerspectiveCamera.js
generated
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
import { Camera } from './Camera';
|
||||
import { Object3D } from '../core/Object3D';
|
||||
import { _Math } from '../math/Math';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author greggman / http://games.greggman.com/
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
* @author tschw
|
||||
*/
|
||||
|
||||
function PerspectiveCamera( fov, aspect, near, far ) {
|
||||
|
||||
Camera.call( this );
|
||||
|
||||
this.type = 'PerspectiveCamera';
|
||||
|
||||
this.fov = fov !== undefined ? fov : 50;
|
||||
this.zoom = 1;
|
||||
|
||||
this.near = near !== undefined ? near : 0.1;
|
||||
this.far = far !== undefined ? far : 2000;
|
||||
this.focus = 10;
|
||||
|
||||
this.aspect = aspect !== undefined ? aspect : 1;
|
||||
this.view = null;
|
||||
|
||||
this.filmGauge = 35; // width of the film (default in millimeters)
|
||||
this.filmOffset = 0; // horizontal film offset (same unit as gauge)
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
|
||||
|
||||
constructor: PerspectiveCamera,
|
||||
|
||||
isPerspectiveCamera: true,
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
Camera.prototype.copy.call( this, source );
|
||||
|
||||
this.fov = source.fov;
|
||||
this.zoom = source.zoom;
|
||||
|
||||
this.near = source.near;
|
||||
this.far = source.far;
|
||||
this.focus = source.focus;
|
||||
|
||||
this.aspect = source.aspect;
|
||||
this.view = source.view === null ? null : Object.assign( {}, source.view );
|
||||
|
||||
this.filmGauge = source.filmGauge;
|
||||
this.filmOffset = source.filmOffset;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the FOV by focal length in respect to the current .filmGauge.
|
||||
*
|
||||
* The default film gauge is 35, so that the focal length can be specified for
|
||||
* a 35mm (full frame) camera.
|
||||
*
|
||||
* Values for focal length and film gauge must have the same unit.
|
||||
*/
|
||||
setFocalLength: function ( focalLength ) {
|
||||
|
||||
// see http://www.bobatkins.com/photography/technical/field_of_view.html
|
||||
var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
|
||||
|
||||
this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculates the focal length from the current .fov and .filmGauge.
|
||||
*/
|
||||
getFocalLength: function () {
|
||||
|
||||
var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
|
||||
|
||||
return 0.5 * this.getFilmHeight() / vExtentSlope;
|
||||
|
||||
},
|
||||
|
||||
getEffectiveFOV: function () {
|
||||
|
||||
return _Math.RAD2DEG * 2 * Math.atan(
|
||||
Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
|
||||
|
||||
},
|
||||
|
||||
getFilmWidth: function () {
|
||||
|
||||
// film not completely covered in portrait format (aspect < 1)
|
||||
return this.filmGauge * Math.min( this.aspect, 1 );
|
||||
|
||||
},
|
||||
|
||||
getFilmHeight: function () {
|
||||
|
||||
// film not completely covered in landscape format (aspect > 1)
|
||||
return this.filmGauge / Math.max( this.aspect, 1 );
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets an offset in a larger frustum. This is useful for multi-window or
|
||||
* multi-monitor/multi-machine setups.
|
||||
*
|
||||
* For example, if you have 3x2 monitors and each monitor is 1920x1080 and
|
||||
* the monitors are in grid like this
|
||||
*
|
||||
* +---+---+---+
|
||||
* | A | B | C |
|
||||
* +---+---+---+
|
||||
* | D | E | F |
|
||||
* +---+---+---+
|
||||
*
|
||||
* then for each monitor you would call it like this
|
||||
*
|
||||
* var w = 1920;
|
||||
* var h = 1080;
|
||||
* var fullWidth = w * 3;
|
||||
* var fullHeight = h * 2;
|
||||
*
|
||||
* --A--
|
||||
* camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
|
||||
* --B--
|
||||
* camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
|
||||
* --C--
|
||||
* camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
|
||||
* --D--
|
||||
* camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
|
||||
* --E--
|
||||
* camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
|
||||
* --F--
|
||||
* camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
|
||||
*
|
||||
* Note there is no reason monitors have to be the same size or in a grid.
|
||||
*/
|
||||
setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
|
||||
|
||||
this.aspect = fullWidth / fullHeight;
|
||||
|
||||
this.view = {
|
||||
fullWidth: fullWidth,
|
||||
fullHeight: fullHeight,
|
||||
offsetX: x,
|
||||
offsetY: y,
|
||||
width: width,
|
||||
height: height
|
||||
};
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
},
|
||||
|
||||
clearViewOffset: function() {
|
||||
|
||||
this.view = null;
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
},
|
||||
|
||||
updateProjectionMatrix: function () {
|
||||
|
||||
var near = this.near,
|
||||
top = near * Math.tan(
|
||||
_Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
|
||||
height = 2 * top,
|
||||
width = this.aspect * height,
|
||||
left = - 0.5 * width,
|
||||
view = this.view;
|
||||
|
||||
if ( view !== null ) {
|
||||
|
||||
var fullWidth = view.fullWidth,
|
||||
fullHeight = view.fullHeight;
|
||||
|
||||
left += view.offsetX * width / fullWidth;
|
||||
top -= view.offsetY * height / fullHeight;
|
||||
width *= view.width / fullWidth;
|
||||
height *= view.height / fullHeight;
|
||||
|
||||
}
|
||||
|
||||
var skew = this.filmOffset;
|
||||
if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
|
||||
|
||||
this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
|
||||
|
||||
},
|
||||
|
||||
toJSON: function ( meta ) {
|
||||
|
||||
var data = Object3D.prototype.toJSON.call( this, meta );
|
||||
|
||||
data.object.fov = this.fov;
|
||||
data.object.zoom = this.zoom;
|
||||
|
||||
data.object.near = this.near;
|
||||
data.object.far = this.far;
|
||||
data.object.focus = this.focus;
|
||||
|
||||
data.object.aspect = this.aspect;
|
||||
|
||||
if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
|
||||
|
||||
data.object.filmGauge = this.filmGauge;
|
||||
data.object.filmOffset = this.filmOffset;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { PerspectiveCamera };
|
||||
98
node_modules/three/src/cameras/StereoCamera.js
generated
vendored
Normal file
98
node_modules/three/src/cameras/StereoCamera.js
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
import { Matrix4 } from '../math/Matrix4';
|
||||
import { _Math } from '../math/Math';
|
||||
import { PerspectiveCamera } from './PerspectiveCamera';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function StereoCamera() {
|
||||
|
||||
this.type = 'StereoCamera';
|
||||
|
||||
this.aspect = 1;
|
||||
|
||||
this.eyeSep = 0.064;
|
||||
|
||||
this.cameraL = new PerspectiveCamera();
|
||||
this.cameraL.layers.enable( 1 );
|
||||
this.cameraL.matrixAutoUpdate = false;
|
||||
|
||||
this.cameraR = new PerspectiveCamera();
|
||||
this.cameraR.layers.enable( 2 );
|
||||
this.cameraR.matrixAutoUpdate = false;
|
||||
|
||||
}
|
||||
|
||||
Object.assign( StereoCamera.prototype, {
|
||||
|
||||
update: ( function () {
|
||||
|
||||
var instance, focus, fov, aspect, near, far, zoom;
|
||||
|
||||
var eyeRight = new Matrix4();
|
||||
var eyeLeft = new Matrix4();
|
||||
|
||||
return function update( camera ) {
|
||||
|
||||
var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
|
||||
aspect !== camera.aspect * this.aspect || near !== camera.near ||
|
||||
far !== camera.far || zoom !== camera.zoom;
|
||||
|
||||
if ( needsUpdate ) {
|
||||
|
||||
instance = this;
|
||||
focus = camera.focus;
|
||||
fov = camera.fov;
|
||||
aspect = camera.aspect * this.aspect;
|
||||
near = camera.near;
|
||||
far = camera.far;
|
||||
zoom = camera.zoom;
|
||||
|
||||
// Off-axis stereoscopic effect based on
|
||||
// http://paulbourke.net/stereographics/stereorender/
|
||||
|
||||
var projectionMatrix = camera.projectionMatrix.clone();
|
||||
var eyeSep = this.eyeSep / 2;
|
||||
var eyeSepOnProjection = eyeSep * near / focus;
|
||||
var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
|
||||
var xmin, xmax;
|
||||
|
||||
// translate xOffset
|
||||
|
||||
eyeLeft.elements[ 12 ] = - eyeSep;
|
||||
eyeRight.elements[ 12 ] = eyeSep;
|
||||
|
||||
// for left eye
|
||||
|
||||
xmin = - ymax * aspect + eyeSepOnProjection;
|
||||
xmax = ymax * aspect + eyeSepOnProjection;
|
||||
|
||||
projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
|
||||
projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
|
||||
|
||||
this.cameraL.projectionMatrix.copy( projectionMatrix );
|
||||
|
||||
// for right eye
|
||||
|
||||
xmin = - ymax * aspect - eyeSepOnProjection;
|
||||
xmax = ymax * aspect - eyeSepOnProjection;
|
||||
|
||||
projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
|
||||
projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
|
||||
|
||||
this.cameraR.projectionMatrix.copy( projectionMatrix );
|
||||
|
||||
}
|
||||
|
||||
this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
|
||||
this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
|
||||
|
||||
};
|
||||
|
||||
} )()
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { StereoCamera };
|
||||
125
node_modules/three/src/constants.js
generated
vendored
Normal file
125
node_modules/three/src/constants.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
export var REVISION = '84';
|
||||
export var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
|
||||
export var CullFaceNone = 0;
|
||||
export var CullFaceBack = 1;
|
||||
export var CullFaceFront = 2;
|
||||
export var CullFaceFrontBack = 3;
|
||||
export var FrontFaceDirectionCW = 0;
|
||||
export var FrontFaceDirectionCCW = 1;
|
||||
export var BasicShadowMap = 0;
|
||||
export var PCFShadowMap = 1;
|
||||
export var PCFSoftShadowMap = 2;
|
||||
export var FrontSide = 0;
|
||||
export var BackSide = 1;
|
||||
export var DoubleSide = 2;
|
||||
export var FlatShading = 1;
|
||||
export var SmoothShading = 2;
|
||||
export var NoColors = 0;
|
||||
export var FaceColors = 1;
|
||||
export var VertexColors = 2;
|
||||
export var NoBlending = 0;
|
||||
export var NormalBlending = 1;
|
||||
export var AdditiveBlending = 2;
|
||||
export var SubtractiveBlending = 3;
|
||||
export var MultiplyBlending = 4;
|
||||
export var CustomBlending = 5;
|
||||
export var AddEquation = 100;
|
||||
export var SubtractEquation = 101;
|
||||
export var ReverseSubtractEquation = 102;
|
||||
export var MinEquation = 103;
|
||||
export var MaxEquation = 104;
|
||||
export var ZeroFactor = 200;
|
||||
export var OneFactor = 201;
|
||||
export var SrcColorFactor = 202;
|
||||
export var OneMinusSrcColorFactor = 203;
|
||||
export var SrcAlphaFactor = 204;
|
||||
export var OneMinusSrcAlphaFactor = 205;
|
||||
export var DstAlphaFactor = 206;
|
||||
export var OneMinusDstAlphaFactor = 207;
|
||||
export var DstColorFactor = 208;
|
||||
export var OneMinusDstColorFactor = 209;
|
||||
export var SrcAlphaSaturateFactor = 210;
|
||||
export var NeverDepth = 0;
|
||||
export var AlwaysDepth = 1;
|
||||
export var LessDepth = 2;
|
||||
export var LessEqualDepth = 3;
|
||||
export var EqualDepth = 4;
|
||||
export var GreaterEqualDepth = 5;
|
||||
export var GreaterDepth = 6;
|
||||
export var NotEqualDepth = 7;
|
||||
export var MultiplyOperation = 0;
|
||||
export var MixOperation = 1;
|
||||
export var AddOperation = 2;
|
||||
export var NoToneMapping = 0;
|
||||
export var LinearToneMapping = 1;
|
||||
export var ReinhardToneMapping = 2;
|
||||
export var Uncharted2ToneMapping = 3;
|
||||
export var CineonToneMapping = 4;
|
||||
export var UVMapping = 300;
|
||||
export var CubeReflectionMapping = 301;
|
||||
export var CubeRefractionMapping = 302;
|
||||
export var EquirectangularReflectionMapping = 303;
|
||||
export var EquirectangularRefractionMapping = 304;
|
||||
export var SphericalReflectionMapping = 305;
|
||||
export var CubeUVReflectionMapping = 306;
|
||||
export var CubeUVRefractionMapping = 307;
|
||||
export var RepeatWrapping = 1000;
|
||||
export var ClampToEdgeWrapping = 1001;
|
||||
export var MirroredRepeatWrapping = 1002;
|
||||
export var NearestFilter = 1003;
|
||||
export var NearestMipMapNearestFilter = 1004;
|
||||
export var NearestMipMapLinearFilter = 1005;
|
||||
export var LinearFilter = 1006;
|
||||
export var LinearMipMapNearestFilter = 1007;
|
||||
export var LinearMipMapLinearFilter = 1008;
|
||||
export var UnsignedByteType = 1009;
|
||||
export var ByteType = 1010;
|
||||
export var ShortType = 1011;
|
||||
export var UnsignedShortType = 1012;
|
||||
export var IntType = 1013;
|
||||
export var UnsignedIntType = 1014;
|
||||
export var FloatType = 1015;
|
||||
export var HalfFloatType = 1016;
|
||||
export var UnsignedShort4444Type = 1017;
|
||||
export var UnsignedShort5551Type = 1018;
|
||||
export var UnsignedShort565Type = 1019;
|
||||
export var UnsignedInt248Type = 1020;
|
||||
export var AlphaFormat = 1021;
|
||||
export var RGBFormat = 1022;
|
||||
export var RGBAFormat = 1023;
|
||||
export var LuminanceFormat = 1024;
|
||||
export var LuminanceAlphaFormat = 1025;
|
||||
export var RGBEFormat = RGBAFormat;
|
||||
export var DepthFormat = 1026;
|
||||
export var DepthStencilFormat = 1027;
|
||||
export var RGB_S3TC_DXT1_Format = 2001;
|
||||
export var RGBA_S3TC_DXT1_Format = 2002;
|
||||
export var RGBA_S3TC_DXT3_Format = 2003;
|
||||
export var RGBA_S3TC_DXT5_Format = 2004;
|
||||
export var RGB_PVRTC_4BPPV1_Format = 2100;
|
||||
export var RGB_PVRTC_2BPPV1_Format = 2101;
|
||||
export var RGBA_PVRTC_4BPPV1_Format = 2102;
|
||||
export var RGBA_PVRTC_2BPPV1_Format = 2103;
|
||||
export var RGB_ETC1_Format = 2151;
|
||||
export var LoopOnce = 2200;
|
||||
export var LoopRepeat = 2201;
|
||||
export var LoopPingPong = 2202;
|
||||
export var InterpolateDiscrete = 2300;
|
||||
export var InterpolateLinear = 2301;
|
||||
export var InterpolateSmooth = 2302;
|
||||
export var ZeroCurvatureEnding = 2400;
|
||||
export var ZeroSlopeEnding = 2401;
|
||||
export var WrapAroundEnding = 2402;
|
||||
export var TrianglesDrawMode = 0;
|
||||
export var TriangleStripDrawMode = 1;
|
||||
export var TriangleFanDrawMode = 2;
|
||||
export var LinearEncoding = 3000;
|
||||
export var sRGBEncoding = 3001;
|
||||
export var GammaEncoding = 3007;
|
||||
export var RGBEEncoding = 3002;
|
||||
export var LogLuvEncoding = 3003;
|
||||
export var RGBM7Encoding = 3004;
|
||||
export var RGBM16Encoding = 3005;
|
||||
export var RGBDEncoding = 3006;
|
||||
export var BasicDepthPacking = 3200;
|
||||
export var RGBADepthPacking = 3201;
|
||||
444
node_modules/three/src/core/BufferAttribute.js
generated
vendored
Normal file
444
node_modules/three/src/core/BufferAttribute.js
generated
vendored
Normal file
@@ -0,0 +1,444 @@
|
||||
import { Vector4 } from '../math/Vector4';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
import { Color } from '../math/Color';
|
||||
import { _Math } from '../math/Math';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function BufferAttribute( array, itemSize, normalized ) {
|
||||
|
||||
if ( Array.isArray( array ) ) {
|
||||
|
||||
throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
|
||||
|
||||
}
|
||||
|
||||
this.uuid = _Math.generateUUID();
|
||||
|
||||
this.array = array;
|
||||
this.itemSize = itemSize;
|
||||
this.count = array !== undefined ? array.length / itemSize : 0;
|
||||
this.normalized = normalized === true;
|
||||
|
||||
this.dynamic = false;
|
||||
this.updateRange = { offset: 0, count: - 1 };
|
||||
|
||||
this.onUploadCallback = function () {};
|
||||
|
||||
this.version = 0;
|
||||
|
||||
}
|
||||
|
||||
BufferAttribute.prototype = {
|
||||
|
||||
constructor: BufferAttribute,
|
||||
|
||||
isBufferAttribute: true,
|
||||
|
||||
set needsUpdate( value ) {
|
||||
|
||||
if ( value === true ) this.version ++;
|
||||
|
||||
},
|
||||
|
||||
setArray: function ( array ) {
|
||||
|
||||
if ( Array.isArray( array ) ) {
|
||||
|
||||
throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
|
||||
|
||||
}
|
||||
|
||||
this.count = array !== undefined ? array.length / this.itemSize : 0;
|
||||
this.array = array;
|
||||
|
||||
},
|
||||
|
||||
setDynamic: function ( value ) {
|
||||
|
||||
this.dynamic = value;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
this.array = new source.array.constructor( source.array );
|
||||
this.itemSize = source.itemSize;
|
||||
this.count = source.count;
|
||||
this.normalized = source.normalized;
|
||||
|
||||
this.dynamic = source.dynamic;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copyAt: function ( index1, attribute, index2 ) {
|
||||
|
||||
index1 *= this.itemSize;
|
||||
index2 *= attribute.itemSize;
|
||||
|
||||
for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
|
||||
|
||||
this.array[ index1 + i ] = attribute.array[ index2 + i ];
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copyArray: function ( array ) {
|
||||
|
||||
this.array.set( array );
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copyColorsArray: function ( colors ) {
|
||||
|
||||
var array = this.array, offset = 0;
|
||||
|
||||
for ( var i = 0, l = colors.length; i < l; i ++ ) {
|
||||
|
||||
var color = colors[ i ];
|
||||
|
||||
if ( color === undefined ) {
|
||||
|
||||
console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
|
||||
color = new Color();
|
||||
|
||||
}
|
||||
|
||||
array[ offset ++ ] = color.r;
|
||||
array[ offset ++ ] = color.g;
|
||||
array[ offset ++ ] = color.b;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copyIndicesArray: function ( indices ) {
|
||||
|
||||
var array = this.array, offset = 0;
|
||||
|
||||
for ( var i = 0, l = indices.length; i < l; i ++ ) {
|
||||
|
||||
var index = indices[ i ];
|
||||
|
||||
array[ offset ++ ] = index.a;
|
||||
array[ offset ++ ] = index.b;
|
||||
array[ offset ++ ] = index.c;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copyVector2sArray: function ( vectors ) {
|
||||
|
||||
var array = this.array, offset = 0;
|
||||
|
||||
for ( var i = 0, l = vectors.length; i < l; i ++ ) {
|
||||
|
||||
var vector = vectors[ i ];
|
||||
|
||||
if ( vector === undefined ) {
|
||||
|
||||
console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
|
||||
vector = new Vector2();
|
||||
|
||||
}
|
||||
|
||||
array[ offset ++ ] = vector.x;
|
||||
array[ offset ++ ] = vector.y;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copyVector3sArray: function ( vectors ) {
|
||||
|
||||
var array = this.array, offset = 0;
|
||||
|
||||
for ( var i = 0, l = vectors.length; i < l; i ++ ) {
|
||||
|
||||
var vector = vectors[ i ];
|
||||
|
||||
if ( vector === undefined ) {
|
||||
|
||||
console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
|
||||
vector = new Vector3();
|
||||
|
||||
}
|
||||
|
||||
array[ offset ++ ] = vector.x;
|
||||
array[ offset ++ ] = vector.y;
|
||||
array[ offset ++ ] = vector.z;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copyVector4sArray: function ( vectors ) {
|
||||
|
||||
var array = this.array, offset = 0;
|
||||
|
||||
for ( var i = 0, l = vectors.length; i < l; i ++ ) {
|
||||
|
||||
var vector = vectors[ i ];
|
||||
|
||||
if ( vector === undefined ) {
|
||||
|
||||
console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
|
||||
vector = new Vector4();
|
||||
|
||||
}
|
||||
|
||||
array[ offset ++ ] = vector.x;
|
||||
array[ offset ++ ] = vector.y;
|
||||
array[ offset ++ ] = vector.z;
|
||||
array[ offset ++ ] = vector.w;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
set: function ( value, offset ) {
|
||||
|
||||
if ( offset === undefined ) offset = 0;
|
||||
|
||||
this.array.set( value, offset );
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
getX: function ( index ) {
|
||||
|
||||
return this.array[ index * this.itemSize ];
|
||||
|
||||
},
|
||||
|
||||
setX: function ( index, x ) {
|
||||
|
||||
this.array[ index * this.itemSize ] = x;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
getY: function ( index ) {
|
||||
|
||||
return this.array[ index * this.itemSize + 1 ];
|
||||
|
||||
},
|
||||
|
||||
setY: function ( index, y ) {
|
||||
|
||||
this.array[ index * this.itemSize + 1 ] = y;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
getZ: function ( index ) {
|
||||
|
||||
return this.array[ index * this.itemSize + 2 ];
|
||||
|
||||
},
|
||||
|
||||
setZ: function ( index, z ) {
|
||||
|
||||
this.array[ index * this.itemSize + 2 ] = z;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
getW: function ( index ) {
|
||||
|
||||
return this.array[ index * this.itemSize + 3 ];
|
||||
|
||||
},
|
||||
|
||||
setW: function ( index, w ) {
|
||||
|
||||
this.array[ index * this.itemSize + 3 ] = w;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setXY: function ( index, x, y ) {
|
||||
|
||||
index *= this.itemSize;
|
||||
|
||||
this.array[ index + 0 ] = x;
|
||||
this.array[ index + 1 ] = y;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setXYZ: function ( index, x, y, z ) {
|
||||
|
||||
index *= this.itemSize;
|
||||
|
||||
this.array[ index + 0 ] = x;
|
||||
this.array[ index + 1 ] = y;
|
||||
this.array[ index + 2 ] = z;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setXYZW: function ( index, x, y, z, w ) {
|
||||
|
||||
index *= this.itemSize;
|
||||
|
||||
this.array[ index + 0 ] = x;
|
||||
this.array[ index + 1 ] = y;
|
||||
this.array[ index + 2 ] = z;
|
||||
this.array[ index + 3 ] = w;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
onUpload: function ( callback ) {
|
||||
|
||||
this.onUploadCallback = callback;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
|
||||
return new this.constructor( this.array, this.itemSize ).copy( this );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
function Int8BufferAttribute( array, itemSize ) {
|
||||
|
||||
BufferAttribute.call( this, new Int8Array( array ), itemSize );
|
||||
|
||||
}
|
||||
|
||||
Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
|
||||
|
||||
|
||||
function Uint8BufferAttribute( array, itemSize ) {
|
||||
|
||||
BufferAttribute.call( this, new Uint8Array( array ), itemSize );
|
||||
|
||||
}
|
||||
|
||||
Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
|
||||
|
||||
|
||||
function Uint8ClampedBufferAttribute( array, itemSize ) {
|
||||
|
||||
BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize );
|
||||
|
||||
}
|
||||
|
||||
Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
|
||||
|
||||
|
||||
function Int16BufferAttribute( array, itemSize ) {
|
||||
|
||||
BufferAttribute.call( this, new Int16Array( array ), itemSize );
|
||||
|
||||
}
|
||||
|
||||
Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
|
||||
|
||||
|
||||
function Uint16BufferAttribute( array, itemSize ) {
|
||||
|
||||
BufferAttribute.call( this, new Uint16Array( array ), itemSize );
|
||||
|
||||
}
|
||||
|
||||
Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
|
||||
|
||||
|
||||
function Int32BufferAttribute( array, itemSize ) {
|
||||
|
||||
BufferAttribute.call( this, new Int32Array( array ), itemSize );
|
||||
|
||||
}
|
||||
|
||||
Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
|
||||
|
||||
|
||||
function Uint32BufferAttribute( array, itemSize ) {
|
||||
|
||||
BufferAttribute.call( this, new Uint32Array( array ), itemSize );
|
||||
|
||||
}
|
||||
|
||||
Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
|
||||
|
||||
|
||||
function Float32BufferAttribute( array, itemSize ) {
|
||||
|
||||
BufferAttribute.call( this, new Float32Array( array ), itemSize );
|
||||
|
||||
}
|
||||
|
||||
Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
|
||||
|
||||
|
||||
function Float64BufferAttribute( array, itemSize ) {
|
||||
|
||||
BufferAttribute.call( this, new Float64Array( array ), itemSize );
|
||||
|
||||
}
|
||||
|
||||
Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
|
||||
|
||||
//
|
||||
|
||||
export {
|
||||
Float64BufferAttribute,
|
||||
Float32BufferAttribute,
|
||||
Uint32BufferAttribute,
|
||||
Int32BufferAttribute,
|
||||
Uint16BufferAttribute,
|
||||
Int16BufferAttribute,
|
||||
Uint8ClampedBufferAttribute,
|
||||
Uint8BufferAttribute,
|
||||
Int8BufferAttribute,
|
||||
BufferAttribute
|
||||
};
|
||||
1118
node_modules/three/src/core/BufferGeometry.js
generated
vendored
Normal file
1118
node_modules/three/src/core/BufferGeometry.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
73
node_modules/three/src/core/Clock.js
generated
vendored
Normal file
73
node_modules/three/src/core/Clock.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
function Clock( autoStart ) {
|
||||
|
||||
this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
|
||||
|
||||
this.startTime = 0;
|
||||
this.oldTime = 0;
|
||||
this.elapsedTime = 0;
|
||||
|
||||
this.running = false;
|
||||
|
||||
}
|
||||
|
||||
Clock.prototype = {
|
||||
|
||||
constructor: Clock,
|
||||
|
||||
start: function () {
|
||||
|
||||
this.startTime = ( performance || Date ).now();
|
||||
|
||||
this.oldTime = this.startTime;
|
||||
this.elapsedTime = 0;
|
||||
this.running = true;
|
||||
|
||||
},
|
||||
|
||||
stop: function () {
|
||||
|
||||
this.getElapsedTime();
|
||||
this.running = false;
|
||||
|
||||
},
|
||||
|
||||
getElapsedTime: function () {
|
||||
|
||||
this.getDelta();
|
||||
return this.elapsedTime;
|
||||
|
||||
},
|
||||
|
||||
getDelta: function () {
|
||||
|
||||
var diff = 0;
|
||||
|
||||
if ( this.autoStart && ! this.running ) {
|
||||
|
||||
this.start();
|
||||
|
||||
}
|
||||
|
||||
if ( this.running ) {
|
||||
|
||||
var newTime = ( performance || Date ).now();
|
||||
|
||||
diff = ( newTime - this.oldTime ) / 1000;
|
||||
this.oldTime = newTime;
|
||||
|
||||
this.elapsedTime += diff;
|
||||
|
||||
}
|
||||
|
||||
return diff;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { Clock };
|
||||
263
node_modules/three/src/core/DirectGeometry.js
generated
vendored
Normal file
263
node_modules/three/src/core/DirectGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
|
||||
function DirectGeometry() {
|
||||
|
||||
this.indices = [];
|
||||
this.vertices = [];
|
||||
this.normals = [];
|
||||
this.colors = [];
|
||||
this.uvs = [];
|
||||
this.uvs2 = [];
|
||||
|
||||
this.groups = [];
|
||||
|
||||
this.morphTargets = {};
|
||||
|
||||
this.skinWeights = [];
|
||||
this.skinIndices = [];
|
||||
|
||||
// this.lineDistances = [];
|
||||
|
||||
this.boundingBox = null;
|
||||
this.boundingSphere = null;
|
||||
|
||||
// update flags
|
||||
|
||||
this.verticesNeedUpdate = false;
|
||||
this.normalsNeedUpdate = false;
|
||||
this.colorsNeedUpdate = false;
|
||||
this.uvsNeedUpdate = false;
|
||||
this.groupsNeedUpdate = false;
|
||||
|
||||
}
|
||||
|
||||
Object.assign( DirectGeometry.prototype, {
|
||||
|
||||
computeGroups: function ( geometry ) {
|
||||
|
||||
var group;
|
||||
var groups = [];
|
||||
var materialIndex = undefined;
|
||||
|
||||
var faces = geometry.faces;
|
||||
|
||||
for ( var i = 0; i < faces.length; i ++ ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
|
||||
// materials
|
||||
|
||||
if ( face.materialIndex !== materialIndex ) {
|
||||
|
||||
materialIndex = face.materialIndex;
|
||||
|
||||
if ( group !== undefined ) {
|
||||
|
||||
group.count = ( i * 3 ) - group.start;
|
||||
groups.push( group );
|
||||
|
||||
}
|
||||
|
||||
group = {
|
||||
start: i * 3,
|
||||
materialIndex: materialIndex
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( group !== undefined ) {
|
||||
|
||||
group.count = ( i * 3 ) - group.start;
|
||||
groups.push( group );
|
||||
|
||||
}
|
||||
|
||||
this.groups = groups;
|
||||
|
||||
},
|
||||
|
||||
fromGeometry: function ( geometry ) {
|
||||
|
||||
var faces = geometry.faces;
|
||||
var vertices = geometry.vertices;
|
||||
var faceVertexUvs = geometry.faceVertexUvs;
|
||||
|
||||
var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
|
||||
var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
|
||||
|
||||
// morphs
|
||||
|
||||
var morphTargets = geometry.morphTargets;
|
||||
var morphTargetsLength = morphTargets.length;
|
||||
|
||||
var morphTargetsPosition;
|
||||
|
||||
if ( morphTargetsLength > 0 ) {
|
||||
|
||||
morphTargetsPosition = [];
|
||||
|
||||
for ( var i = 0; i < morphTargetsLength; i ++ ) {
|
||||
|
||||
morphTargetsPosition[ i ] = [];
|
||||
|
||||
}
|
||||
|
||||
this.morphTargets.position = morphTargetsPosition;
|
||||
|
||||
}
|
||||
|
||||
var morphNormals = geometry.morphNormals;
|
||||
var morphNormalsLength = morphNormals.length;
|
||||
|
||||
var morphTargetsNormal;
|
||||
|
||||
if ( morphNormalsLength > 0 ) {
|
||||
|
||||
morphTargetsNormal = [];
|
||||
|
||||
for ( var i = 0; i < morphNormalsLength; i ++ ) {
|
||||
|
||||
morphTargetsNormal[ i ] = [];
|
||||
|
||||
}
|
||||
|
||||
this.morphTargets.normal = morphTargetsNormal;
|
||||
|
||||
}
|
||||
|
||||
// skins
|
||||
|
||||
var skinIndices = geometry.skinIndices;
|
||||
var skinWeights = geometry.skinWeights;
|
||||
|
||||
var hasSkinIndices = skinIndices.length === vertices.length;
|
||||
var hasSkinWeights = skinWeights.length === vertices.length;
|
||||
|
||||
//
|
||||
|
||||
for ( var i = 0; i < faces.length; i ++ ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
|
||||
this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
|
||||
|
||||
var vertexNormals = face.vertexNormals;
|
||||
|
||||
if ( vertexNormals.length === 3 ) {
|
||||
|
||||
this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
|
||||
|
||||
} else {
|
||||
|
||||
var normal = face.normal;
|
||||
|
||||
this.normals.push( normal, normal, normal );
|
||||
|
||||
}
|
||||
|
||||
var vertexColors = face.vertexColors;
|
||||
|
||||
if ( vertexColors.length === 3 ) {
|
||||
|
||||
this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
|
||||
|
||||
} else {
|
||||
|
||||
var color = face.color;
|
||||
|
||||
this.colors.push( color, color, color );
|
||||
|
||||
}
|
||||
|
||||
if ( hasFaceVertexUv === true ) {
|
||||
|
||||
var vertexUvs = faceVertexUvs[ 0 ][ i ];
|
||||
|
||||
if ( vertexUvs !== undefined ) {
|
||||
|
||||
this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
|
||||
|
||||
} else {
|
||||
|
||||
console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
|
||||
|
||||
this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( hasFaceVertexUv2 === true ) {
|
||||
|
||||
var vertexUvs = faceVertexUvs[ 1 ][ i ];
|
||||
|
||||
if ( vertexUvs !== undefined ) {
|
||||
|
||||
this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
|
||||
|
||||
} else {
|
||||
|
||||
console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
|
||||
|
||||
this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// morphs
|
||||
|
||||
for ( var j = 0; j < morphTargetsLength; j ++ ) {
|
||||
|
||||
var morphTarget = morphTargets[ j ].vertices;
|
||||
|
||||
morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
|
||||
|
||||
}
|
||||
|
||||
for ( var j = 0; j < morphNormalsLength; j ++ ) {
|
||||
|
||||
var morphNormal = morphNormals[ j ].vertexNormals[ i ];
|
||||
|
||||
morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
|
||||
|
||||
}
|
||||
|
||||
// skins
|
||||
|
||||
if ( hasSkinIndices ) {
|
||||
|
||||
this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
|
||||
|
||||
}
|
||||
|
||||
if ( hasSkinWeights ) {
|
||||
|
||||
this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.computeGroups( geometry );
|
||||
|
||||
this.verticesNeedUpdate = geometry.verticesNeedUpdate;
|
||||
this.normalsNeedUpdate = geometry.normalsNeedUpdate;
|
||||
this.colorsNeedUpdate = geometry.colorsNeedUpdate;
|
||||
this.uvsNeedUpdate = geometry.uvsNeedUpdate;
|
||||
this.groupsNeedUpdate = geometry.groupsNeedUpdate;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { DirectGeometry };
|
||||
93
node_modules/three/src/core/EventDispatcher.js
generated
vendored
Normal file
93
node_modules/three/src/core/EventDispatcher.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* https://github.com/mrdoob/eventdispatcher.js/
|
||||
*/
|
||||
|
||||
function EventDispatcher() {}
|
||||
|
||||
EventDispatcher.prototype = {
|
||||
|
||||
addEventListener: function ( type, listener ) {
|
||||
|
||||
if ( this._listeners === undefined ) this._listeners = {};
|
||||
|
||||
var listeners = this._listeners;
|
||||
|
||||
if ( listeners[ type ] === undefined ) {
|
||||
|
||||
listeners[ type ] = [];
|
||||
|
||||
}
|
||||
|
||||
if ( listeners[ type ].indexOf( listener ) === - 1 ) {
|
||||
|
||||
listeners[ type ].push( listener );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
hasEventListener: function ( type, listener ) {
|
||||
|
||||
if ( this._listeners === undefined ) return false;
|
||||
|
||||
var listeners = this._listeners;
|
||||
|
||||
return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
|
||||
|
||||
},
|
||||
|
||||
removeEventListener: function ( type, listener ) {
|
||||
|
||||
if ( this._listeners === undefined ) return;
|
||||
|
||||
var listeners = this._listeners;
|
||||
var listenerArray = listeners[ type ];
|
||||
|
||||
if ( listenerArray !== undefined ) {
|
||||
|
||||
var index = listenerArray.indexOf( listener );
|
||||
|
||||
if ( index !== - 1 ) {
|
||||
|
||||
listenerArray.splice( index, 1 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
dispatchEvent: function ( event ) {
|
||||
|
||||
if ( this._listeners === undefined ) return;
|
||||
|
||||
var listeners = this._listeners;
|
||||
var listenerArray = listeners[ event.type ];
|
||||
|
||||
if ( listenerArray !== undefined ) {
|
||||
|
||||
event.target = this;
|
||||
|
||||
var array = [], i = 0;
|
||||
var length = listenerArray.length;
|
||||
|
||||
for ( i = 0; i < length; i ++ ) {
|
||||
|
||||
array[ i ] = listenerArray[ i ];
|
||||
|
||||
}
|
||||
|
||||
for ( i = 0; i < length; i ++ ) {
|
||||
|
||||
array[ i ].call( this, event );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { EventDispatcher };
|
||||
65
node_modules/three/src/core/Face3.js
generated
vendored
Normal file
65
node_modules/three/src/core/Face3.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
import { Color } from '../math/Color';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
function Face3( a, b, c, normal, color, materialIndex ) {
|
||||
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
|
||||
this.normal = (normal && normal.isVector3) ? normal : new Vector3();
|
||||
this.vertexNormals = Array.isArray( normal ) ? normal : [];
|
||||
|
||||
this.color = (color && color.isColor) ? color : new Color();
|
||||
this.vertexColors = Array.isArray( color ) ? color : [];
|
||||
|
||||
this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
|
||||
|
||||
}
|
||||
|
||||
Face3.prototype = {
|
||||
|
||||
constructor: Face3,
|
||||
|
||||
clone: function () {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
},
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
this.a = source.a;
|
||||
this.b = source.b;
|
||||
this.c = source.c;
|
||||
|
||||
this.normal.copy( source.normal );
|
||||
this.color.copy( source.color );
|
||||
|
||||
this.materialIndex = source.materialIndex;
|
||||
|
||||
for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
|
||||
|
||||
this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
|
||||
|
||||
}
|
||||
|
||||
for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
|
||||
|
||||
this.vertexColors[ i ] = source.vertexColors[ i ].clone();
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { Face3 };
|
||||
1445
node_modules/three/src/core/Geometry.js
generated
vendored
Normal file
1445
node_modules/three/src/core/Geometry.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
31
node_modules/three/src/core/InstancedBufferAttribute.js
generated
vendored
Normal file
31
node_modules/three/src/core/InstancedBufferAttribute.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { BufferAttribute } from './BufferAttribute';
|
||||
|
||||
/**
|
||||
* @author benaadams / https://twitter.com/ben_a_adams
|
||||
*/
|
||||
|
||||
function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
|
||||
|
||||
BufferAttribute.call( this, array, itemSize );
|
||||
|
||||
this.meshPerAttribute = meshPerAttribute || 1;
|
||||
|
||||
}
|
||||
|
||||
InstancedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
|
||||
InstancedBufferAttribute.prototype.constructor = InstancedBufferAttribute;
|
||||
|
||||
InstancedBufferAttribute.prototype.isInstancedBufferAttribute = true;
|
||||
|
||||
InstancedBufferAttribute.prototype.copy = function ( source ) {
|
||||
|
||||
BufferAttribute.prototype.copy.call( this, source );
|
||||
|
||||
this.meshPerAttribute = source.meshPerAttribute;
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { InstancedBufferAttribute };
|
||||
66
node_modules/three/src/core/InstancedBufferGeometry.js
generated
vendored
Normal file
66
node_modules/three/src/core/InstancedBufferGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
import { BufferGeometry } from './BufferGeometry';
|
||||
|
||||
/**
|
||||
* @author benaadams / https://twitter.com/ben_a_adams
|
||||
*/
|
||||
|
||||
function InstancedBufferGeometry() {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'InstancedBufferGeometry';
|
||||
this.maxInstancedCount = undefined;
|
||||
|
||||
}
|
||||
|
||||
InstancedBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
InstancedBufferGeometry.prototype.constructor = InstancedBufferGeometry;
|
||||
|
||||
InstancedBufferGeometry.prototype.isInstancedBufferGeometry = true;
|
||||
|
||||
InstancedBufferGeometry.prototype.addGroup = function ( start, count, materialIndex ) {
|
||||
|
||||
this.groups.push( {
|
||||
|
||||
start: start,
|
||||
count: count,
|
||||
materialIndex: materialIndex
|
||||
|
||||
} );
|
||||
|
||||
};
|
||||
|
||||
InstancedBufferGeometry.prototype.copy = function ( source ) {
|
||||
|
||||
var index = source.index;
|
||||
|
||||
if ( index !== null ) {
|
||||
|
||||
this.setIndex( index.clone() );
|
||||
|
||||
}
|
||||
|
||||
var attributes = source.attributes;
|
||||
|
||||
for ( var name in attributes ) {
|
||||
|
||||
var attribute = attributes[ name ];
|
||||
this.addAttribute( name, attribute.clone() );
|
||||
|
||||
}
|
||||
|
||||
var groups = source.groups;
|
||||
|
||||
for ( var i = 0, l = groups.length; i < l; i ++ ) {
|
||||
|
||||
var group = groups[ i ];
|
||||
this.addGroup( group.start, group.count, group.materialIndex );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { InstancedBufferGeometry };
|
||||
31
node_modules/three/src/core/InstancedInterleavedBuffer.js
generated
vendored
Normal file
31
node_modules/three/src/core/InstancedInterleavedBuffer.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { InterleavedBuffer } from './InterleavedBuffer';
|
||||
|
||||
/**
|
||||
* @author benaadams / https://twitter.com/ben_a_adams
|
||||
*/
|
||||
|
||||
function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
|
||||
|
||||
InterleavedBuffer.call( this, array, stride );
|
||||
|
||||
this.meshPerAttribute = meshPerAttribute || 1;
|
||||
|
||||
}
|
||||
|
||||
InstancedInterleavedBuffer.prototype = Object.create( InterleavedBuffer.prototype );
|
||||
InstancedInterleavedBuffer.prototype.constructor = InstancedInterleavedBuffer;
|
||||
|
||||
InstancedInterleavedBuffer.prototype.isInstancedInterleavedBuffer = true;
|
||||
|
||||
InstancedInterleavedBuffer.prototype.copy = function ( source ) {
|
||||
|
||||
InterleavedBuffer.prototype.copy.call( this, source );
|
||||
|
||||
this.meshPerAttribute = source.meshPerAttribute;
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { InstancedInterleavedBuffer };
|
||||
110
node_modules/three/src/core/InterleavedBuffer.js
generated
vendored
Normal file
110
node_modules/three/src/core/InterleavedBuffer.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
import { _Math } from '../math/Math';
|
||||
|
||||
/**
|
||||
* @author benaadams / https://twitter.com/ben_a_adams
|
||||
*/
|
||||
|
||||
function InterleavedBuffer( array, stride ) {
|
||||
|
||||
this.uuid = _Math.generateUUID();
|
||||
|
||||
this.array = array;
|
||||
this.stride = stride;
|
||||
this.count = array !== undefined ? array.length / stride : 0;
|
||||
|
||||
this.dynamic = false;
|
||||
this.updateRange = { offset: 0, count: - 1 };
|
||||
|
||||
this.onUploadCallback = function () {};
|
||||
|
||||
this.version = 0;
|
||||
|
||||
}
|
||||
|
||||
InterleavedBuffer.prototype = {
|
||||
|
||||
constructor: InterleavedBuffer,
|
||||
|
||||
isInterleavedBuffer: true,
|
||||
|
||||
set needsUpdate( value ) {
|
||||
|
||||
if ( value === true ) this.version ++;
|
||||
|
||||
},
|
||||
|
||||
setArray: function ( array ) {
|
||||
|
||||
if ( Array.isArray( array ) ) {
|
||||
|
||||
throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
|
||||
|
||||
}
|
||||
|
||||
this.count = array !== undefined ? array.length / this.stride : 0;
|
||||
this.array = array;
|
||||
|
||||
},
|
||||
|
||||
setDynamic: function ( value ) {
|
||||
|
||||
this.dynamic = value;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copy: function ( source ) {
|
||||
|
||||
this.array = new source.array.constructor( source.array );
|
||||
this.count = source.count;
|
||||
this.stride = source.stride;
|
||||
this.dynamic = source.dynamic;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
copyAt: function ( index1, attribute, index2 ) {
|
||||
|
||||
index1 *= this.stride;
|
||||
index2 *= attribute.stride;
|
||||
|
||||
for ( var i = 0, l = this.stride; i < l; i ++ ) {
|
||||
|
||||
this.array[ index1 + i ] = attribute.array[ index2 + i ];
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
set: function ( value, offset ) {
|
||||
|
||||
if ( offset === undefined ) offset = 0;
|
||||
|
||||
this.array.set( value, offset );
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
},
|
||||
|
||||
onUpload: function ( callback ) {
|
||||
|
||||
this.onUploadCallback = callback;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { InterleavedBuffer };
|
||||
133
node_modules/three/src/core/InterleavedBufferAttribute.js
generated
vendored
Normal file
133
node_modules/three/src/core/InterleavedBufferAttribute.js
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
import { _Math } from '../math/Math';
|
||||
|
||||
/**
|
||||
* @author benaadams / https://twitter.com/ben_a_adams
|
||||
*/
|
||||
|
||||
function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
|
||||
|
||||
this.uuid = _Math.generateUUID();
|
||||
|
||||
this.data = interleavedBuffer;
|
||||
this.itemSize = itemSize;
|
||||
this.offset = offset;
|
||||
|
||||
this.normalized = normalized === true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
InterleavedBufferAttribute.prototype = {
|
||||
|
||||
constructor: InterleavedBufferAttribute,
|
||||
|
||||
isInterleavedBufferAttribute: true,
|
||||
|
||||
get count() {
|
||||
|
||||
return this.data.count;
|
||||
|
||||
},
|
||||
|
||||
get array() {
|
||||
|
||||
return this.data.array;
|
||||
|
||||
},
|
||||
|
||||
setX: function ( index, x ) {
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset ] = x;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setY: function ( index, y ) {
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setZ: function ( index, z ) {
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setW: function ( index, w ) {
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
getX: function ( index ) {
|
||||
|
||||
return this.data.array[ index * this.data.stride + this.offset ];
|
||||
|
||||
},
|
||||
|
||||
getY: function ( index ) {
|
||||
|
||||
return this.data.array[ index * this.data.stride + this.offset + 1 ];
|
||||
|
||||
},
|
||||
|
||||
getZ: function ( index ) {
|
||||
|
||||
return this.data.array[ index * this.data.stride + this.offset + 2 ];
|
||||
|
||||
},
|
||||
|
||||
getW: function ( index ) {
|
||||
|
||||
return this.data.array[ index * this.data.stride + this.offset + 3 ];
|
||||
|
||||
},
|
||||
|
||||
setXY: function ( index, x, y ) {
|
||||
|
||||
index = index * this.data.stride + this.offset;
|
||||
|
||||
this.data.array[ index + 0 ] = x;
|
||||
this.data.array[ index + 1 ] = y;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setXYZ: function ( index, x, y, z ) {
|
||||
|
||||
index = index * this.data.stride + this.offset;
|
||||
|
||||
this.data.array[ index + 0 ] = x;
|
||||
this.data.array[ index + 1 ] = y;
|
||||
this.data.array[ index + 2 ] = z;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
setXYZW: function ( index, x, y, z, w ) {
|
||||
|
||||
index = index * this.data.stride + this.offset;
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { InterleavedBufferAttribute };
|
||||
48
node_modules/three/src/core/Layers.js
generated
vendored
Normal file
48
node_modules/three/src/core/Layers.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function Layers() {
|
||||
|
||||
this.mask = 1;
|
||||
|
||||
}
|
||||
|
||||
Layers.prototype = {
|
||||
|
||||
constructor: Layers,
|
||||
|
||||
set: function ( channel ) {
|
||||
|
||||
this.mask = 1 << channel;
|
||||
|
||||
},
|
||||
|
||||
enable: function ( channel ) {
|
||||
|
||||
this.mask |= 1 << channel;
|
||||
|
||||
},
|
||||
|
||||
toggle: function ( channel ) {
|
||||
|
||||
this.mask ^= 1 << channel;
|
||||
|
||||
},
|
||||
|
||||
disable: function ( channel ) {
|
||||
|
||||
this.mask &= ~ ( 1 << channel );
|
||||
|
||||
},
|
||||
|
||||
test: function ( layers ) {
|
||||
|
||||
return ( this.mask & layers.mask ) !== 0;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { Layers };
|
||||
737
node_modules/three/src/core/Object3D.js
generated
vendored
Normal file
737
node_modules/three/src/core/Object3D.js
generated
vendored
Normal file
@@ -0,0 +1,737 @@
|
||||
import { Quaternion } from '../math/Quaternion';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Matrix4 } from '../math/Matrix4';
|
||||
import { EventDispatcher } from './EventDispatcher';
|
||||
import { Euler } from '../math/Euler';
|
||||
import { Layers } from './Layers';
|
||||
import { Matrix3 } from '../math/Matrix3';
|
||||
import { _Math } from '../math/Math';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author mikael emtinger / http://gomo.se/
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
* @author elephantatwork / www.elephantatwork.ch
|
||||
*/
|
||||
|
||||
var object3DId = 0;
|
||||
|
||||
function Object3D() {
|
||||
|
||||
Object.defineProperty( this, 'id', { value: object3DId ++ } );
|
||||
|
||||
this.uuid = _Math.generateUUID();
|
||||
|
||||
this.name = '';
|
||||
this.type = 'Object3D';
|
||||
|
||||
this.parent = null;
|
||||
this.children = [];
|
||||
|
||||
this.up = Object3D.DefaultUp.clone();
|
||||
|
||||
var position = new Vector3();
|
||||
var rotation = new Euler();
|
||||
var quaternion = new Quaternion();
|
||||
var scale = new Vector3( 1, 1, 1 );
|
||||
|
||||
function onRotationChange() {
|
||||
|
||||
quaternion.setFromEuler( rotation, false );
|
||||
|
||||
}
|
||||
|
||||
function onQuaternionChange() {
|
||||
|
||||
rotation.setFromQuaternion( quaternion, undefined, false );
|
||||
|
||||
}
|
||||
|
||||
rotation.onChange( onRotationChange );
|
||||
quaternion.onChange( onQuaternionChange );
|
||||
|
||||
Object.defineProperties( this, {
|
||||
position: {
|
||||
enumerable: true,
|
||||
value: position
|
||||
},
|
||||
rotation: {
|
||||
enumerable: true,
|
||||
value: rotation
|
||||
},
|
||||
quaternion: {
|
||||
enumerable: true,
|
||||
value: quaternion
|
||||
},
|
||||
scale: {
|
||||
enumerable: true,
|
||||
value: scale
|
||||
},
|
||||
modelViewMatrix: {
|
||||
value: new Matrix4()
|
||||
},
|
||||
normalMatrix: {
|
||||
value: new Matrix3()
|
||||
}
|
||||
} );
|
||||
|
||||
this.matrix = new Matrix4();
|
||||
this.matrixWorld = new Matrix4();
|
||||
|
||||
this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
|
||||
this.matrixWorldNeedsUpdate = false;
|
||||
|
||||
this.layers = new Layers();
|
||||
this.visible = true;
|
||||
|
||||
this.castShadow = false;
|
||||
this.receiveShadow = false;
|
||||
|
||||
this.frustumCulled = true;
|
||||
this.renderOrder = 0;
|
||||
|
||||
this.userData = {};
|
||||
|
||||
this.onBeforeRender = function () {};
|
||||
this.onAfterRender = function () {};
|
||||
|
||||
}
|
||||
|
||||
Object3D.DefaultUp = new Vector3( 0, 1, 0 );
|
||||
Object3D.DefaultMatrixAutoUpdate = true;
|
||||
|
||||
Object3D.prototype = {
|
||||
|
||||
constructor: Object3D,
|
||||
|
||||
isObject3D: true,
|
||||
|
||||
applyMatrix: function ( matrix ) {
|
||||
|
||||
this.matrix.multiplyMatrices( matrix, this.matrix );
|
||||
|
||||
this.matrix.decompose( this.position, this.quaternion, this.scale );
|
||||
|
||||
},
|
||||
|
||||
setRotationFromAxisAngle: function ( axis, angle ) {
|
||||
|
||||
// assumes axis is normalized
|
||||
|
||||
this.quaternion.setFromAxisAngle( axis, angle );
|
||||
|
||||
},
|
||||
|
||||
setRotationFromEuler: function ( euler ) {
|
||||
|
||||
this.quaternion.setFromEuler( euler, true );
|
||||
|
||||
},
|
||||
|
||||
setRotationFromMatrix: function ( m ) {
|
||||
|
||||
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
||||
|
||||
this.quaternion.setFromRotationMatrix( m );
|
||||
|
||||
},
|
||||
|
||||
setRotationFromQuaternion: function ( q ) {
|
||||
|
||||
// assumes q is normalized
|
||||
|
||||
this.quaternion.copy( q );
|
||||
|
||||
},
|
||||
|
||||
rotateOnAxis: function () {
|
||||
|
||||
// rotate object on axis in object space
|
||||
// axis is assumed to be normalized
|
||||
|
||||
var q1 = new Quaternion();
|
||||
|
||||
return function rotateOnAxis( axis, angle ) {
|
||||
|
||||
q1.setFromAxisAngle( axis, angle );
|
||||
|
||||
this.quaternion.multiply( q1 );
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
rotateX: function () {
|
||||
|
||||
var v1 = new Vector3( 1, 0, 0 );
|
||||
|
||||
return function rotateX( angle ) {
|
||||
|
||||
return this.rotateOnAxis( v1, angle );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
rotateY: function () {
|
||||
|
||||
var v1 = new Vector3( 0, 1, 0 );
|
||||
|
||||
return function rotateY( angle ) {
|
||||
|
||||
return this.rotateOnAxis( v1, angle );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
rotateZ: function () {
|
||||
|
||||
var v1 = new Vector3( 0, 0, 1 );
|
||||
|
||||
return function rotateZ( angle ) {
|
||||
|
||||
return this.rotateOnAxis( v1, angle );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
translateOnAxis: function () {
|
||||
|
||||
// translate object by distance along axis in object space
|
||||
// axis is assumed to be normalized
|
||||
|
||||
var v1 = new Vector3();
|
||||
|
||||
return function translateOnAxis( axis, distance ) {
|
||||
|
||||
v1.copy( axis ).applyQuaternion( this.quaternion );
|
||||
|
||||
this.position.add( v1.multiplyScalar( distance ) );
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
translateX: function () {
|
||||
|
||||
var v1 = new Vector3( 1, 0, 0 );
|
||||
|
||||
return function translateX( distance ) {
|
||||
|
||||
return this.translateOnAxis( v1, distance );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
translateY: function () {
|
||||
|
||||
var v1 = new Vector3( 0, 1, 0 );
|
||||
|
||||
return function translateY( distance ) {
|
||||
|
||||
return this.translateOnAxis( v1, distance );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
translateZ: function () {
|
||||
|
||||
var v1 = new Vector3( 0, 0, 1 );
|
||||
|
||||
return function translateZ( distance ) {
|
||||
|
||||
return this.translateOnAxis( v1, distance );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
localToWorld: function ( vector ) {
|
||||
|
||||
return vector.applyMatrix4( this.matrixWorld );
|
||||
|
||||
},
|
||||
|
||||
worldToLocal: function () {
|
||||
|
||||
var m1 = new Matrix4();
|
||||
|
||||
return function worldToLocal( vector ) {
|
||||
|
||||
return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
lookAt: function () {
|
||||
|
||||
// This routine does not support objects with rotated and/or translated parent(s)
|
||||
|
||||
var m1 = new Matrix4();
|
||||
|
||||
return function lookAt( vector ) {
|
||||
|
||||
m1.lookAt( vector, this.position, this.up );
|
||||
|
||||
this.quaternion.setFromRotationMatrix( m1 );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
add: function ( object ) {
|
||||
|
||||
if ( arguments.length > 1 ) {
|
||||
|
||||
for ( var i = 0; i < arguments.length; i ++ ) {
|
||||
|
||||
this.add( arguments[ i ] );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
if ( object === this ) {
|
||||
|
||||
console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
if ( ( object && object.isObject3D ) ) {
|
||||
|
||||
if ( object.parent !== null ) {
|
||||
|
||||
object.parent.remove( object );
|
||||
|
||||
}
|
||||
|
||||
object.parent = this;
|
||||
object.dispatchEvent( { type: 'added' } );
|
||||
|
||||
this.children.push( object );
|
||||
|
||||
} else {
|
||||
|
||||
console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
remove: function ( object ) {
|
||||
|
||||
if ( arguments.length > 1 ) {
|
||||
|
||||
for ( var i = 0; i < arguments.length; i ++ ) {
|
||||
|
||||
this.remove( arguments[ i ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var index = this.children.indexOf( object );
|
||||
|
||||
if ( index !== - 1 ) {
|
||||
|
||||
object.parent = null;
|
||||
|
||||
object.dispatchEvent( { type: 'removed' } );
|
||||
|
||||
this.children.splice( index, 1 );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getObjectById: function ( id ) {
|
||||
|
||||
return this.getObjectByProperty( 'id', id );
|
||||
|
||||
},
|
||||
|
||||
getObjectByName: function ( name ) {
|
||||
|
||||
return this.getObjectByProperty( 'name', name );
|
||||
|
||||
},
|
||||
|
||||
getObjectByProperty: function ( name, value ) {
|
||||
|
||||
if ( this[ name ] === value ) return this;
|
||||
|
||||
for ( var i = 0, l = this.children.length; i < l; i ++ ) {
|
||||
|
||||
var child = this.children[ i ];
|
||||
var object = child.getObjectByProperty( name, value );
|
||||
|
||||
if ( object !== undefined ) {
|
||||
|
||||
return object;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
||||
},
|
||||
|
||||
getWorldPosition: function ( optionalTarget ) {
|
||||
|
||||
var result = optionalTarget || new Vector3();
|
||||
|
||||
this.updateMatrixWorld( true );
|
||||
|
||||
return result.setFromMatrixPosition( this.matrixWorld );
|
||||
|
||||
},
|
||||
|
||||
getWorldQuaternion: function () {
|
||||
|
||||
var position = new Vector3();
|
||||
var scale = new Vector3();
|
||||
|
||||
return function getWorldQuaternion( optionalTarget ) {
|
||||
|
||||
var result = optionalTarget || new Quaternion();
|
||||
|
||||
this.updateMatrixWorld( true );
|
||||
|
||||
this.matrixWorld.decompose( position, result, scale );
|
||||
|
||||
return result;
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
getWorldRotation: function () {
|
||||
|
||||
var quaternion = new Quaternion();
|
||||
|
||||
return function getWorldRotation( optionalTarget ) {
|
||||
|
||||
var result = optionalTarget || new Euler();
|
||||
|
||||
this.getWorldQuaternion( quaternion );
|
||||
|
||||
return result.setFromQuaternion( quaternion, this.rotation.order, false );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
getWorldScale: function () {
|
||||
|
||||
var position = new Vector3();
|
||||
var quaternion = new Quaternion();
|
||||
|
||||
return function getWorldScale( optionalTarget ) {
|
||||
|
||||
var result = optionalTarget || new Vector3();
|
||||
|
||||
this.updateMatrixWorld( true );
|
||||
|
||||
this.matrixWorld.decompose( position, quaternion, result );
|
||||
|
||||
return result;
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
getWorldDirection: function () {
|
||||
|
||||
var quaternion = new Quaternion();
|
||||
|
||||
return function getWorldDirection( optionalTarget ) {
|
||||
|
||||
var result = optionalTarget || new Vector3();
|
||||
|
||||
this.getWorldQuaternion( quaternion );
|
||||
|
||||
return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
|
||||
|
||||
};
|
||||
|
||||
}(),
|
||||
|
||||
raycast: function () {},
|
||||
|
||||
traverse: function ( callback ) {
|
||||
|
||||
callback( this );
|
||||
|
||||
var children = this.children;
|
||||
|
||||
for ( var i = 0, l = children.length; i < l; i ++ ) {
|
||||
|
||||
children[ i ].traverse( callback );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
traverseVisible: function ( callback ) {
|
||||
|
||||
if ( this.visible === false ) return;
|
||||
|
||||
callback( this );
|
||||
|
||||
var children = this.children;
|
||||
|
||||
for ( var i = 0, l = children.length; i < l; i ++ ) {
|
||||
|
||||
children[ i ].traverseVisible( callback );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
traverseAncestors: function ( callback ) {
|
||||
|
||||
var parent = this.parent;
|
||||
|
||||
if ( parent !== null ) {
|
||||
|
||||
callback( parent );
|
||||
|
||||
parent.traverseAncestors( callback );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
updateMatrix: function () {
|
||||
|
||||
this.matrix.compose( this.position, this.quaternion, this.scale );
|
||||
|
||||
this.matrixWorldNeedsUpdate = true;
|
||||
|
||||
},
|
||||
|
||||
updateMatrixWorld: function ( force ) {
|
||||
|
||||
if ( this.matrixAutoUpdate === true ) this.updateMatrix();
|
||||
|
||||
if ( this.matrixWorldNeedsUpdate === true || force === true ) {
|
||||
|
||||
if ( this.parent === null ) {
|
||||
|
||||
this.matrixWorld.copy( this.matrix );
|
||||
|
||||
} else {
|
||||
|
||||
this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
|
||||
|
||||
}
|
||||
|
||||
this.matrixWorldNeedsUpdate = false;
|
||||
|
||||
force = true;
|
||||
|
||||
}
|
||||
|
||||
// update children
|
||||
|
||||
var children = this.children;
|
||||
|
||||
for ( var i = 0, l = children.length; i < l; i ++ ) {
|
||||
|
||||
children[ i ].updateMatrixWorld( force );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
toJSON: function ( meta ) {
|
||||
|
||||
// meta is '' when called from JSON.stringify
|
||||
var isRootObject = ( meta === undefined || meta === '' );
|
||||
|
||||
var output = {};
|
||||
|
||||
// meta is a hash used to collect geometries, materials.
|
||||
// not providing it implies that this is the root object
|
||||
// being serialized.
|
||||
if ( isRootObject ) {
|
||||
|
||||
// initialize meta obj
|
||||
meta = {
|
||||
geometries: {},
|
||||
materials: {},
|
||||
textures: {},
|
||||
images: {}
|
||||
};
|
||||
|
||||
output.metadata = {
|
||||
version: 4.4,
|
||||
type: 'Object',
|
||||
generator: 'Object3D.toJSON'
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// standard Object3D serialization
|
||||
|
||||
var object = {};
|
||||
|
||||
object.uuid = this.uuid;
|
||||
object.type = this.type;
|
||||
|
||||
if ( this.name !== '' ) object.name = this.name;
|
||||
if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
|
||||
if ( this.castShadow === true ) object.castShadow = true;
|
||||
if ( this.receiveShadow === true ) object.receiveShadow = true;
|
||||
if ( this.visible === false ) object.visible = false;
|
||||
|
||||
object.matrix = this.matrix.toArray();
|
||||
|
||||
//
|
||||
|
||||
if ( this.geometry !== undefined ) {
|
||||
|
||||
if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
|
||||
|
||||
meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
|
||||
|
||||
}
|
||||
|
||||
object.geometry = this.geometry.uuid;
|
||||
|
||||
}
|
||||
|
||||
if ( this.material !== undefined ) {
|
||||
|
||||
if ( meta.materials[ this.material.uuid ] === undefined ) {
|
||||
|
||||
meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
|
||||
|
||||
}
|
||||
|
||||
object.material = this.material.uuid;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
if ( this.children.length > 0 ) {
|
||||
|
||||
object.children = [];
|
||||
|
||||
for ( var i = 0; i < this.children.length; i ++ ) {
|
||||
|
||||
object.children.push( this.children[ i ].toJSON( meta ).object );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( isRootObject ) {
|
||||
|
||||
var geometries = extractFromCache( meta.geometries );
|
||||
var materials = extractFromCache( meta.materials );
|
||||
var textures = extractFromCache( meta.textures );
|
||||
var images = extractFromCache( meta.images );
|
||||
|
||||
if ( geometries.length > 0 ) output.geometries = geometries;
|
||||
if ( materials.length > 0 ) output.materials = materials;
|
||||
if ( textures.length > 0 ) output.textures = textures;
|
||||
if ( images.length > 0 ) output.images = images;
|
||||
|
||||
}
|
||||
|
||||
output.object = object;
|
||||
|
||||
return output;
|
||||
|
||||
// extract data from the cache hash
|
||||
// remove metadata on each item
|
||||
// and return as array
|
||||
function extractFromCache( cache ) {
|
||||
|
||||
var values = [];
|
||||
for ( var key in cache ) {
|
||||
|
||||
var data = cache[ key ];
|
||||
delete data.metadata;
|
||||
values.push( data );
|
||||
|
||||
}
|
||||
return values;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
clone: function ( recursive ) {
|
||||
|
||||
return new this.constructor().copy( this, recursive );
|
||||
|
||||
},
|
||||
|
||||
copy: function ( source, recursive ) {
|
||||
|
||||
if ( recursive === undefined ) recursive = true;
|
||||
|
||||
this.name = source.name;
|
||||
|
||||
this.up.copy( source.up );
|
||||
|
||||
this.position.copy( source.position );
|
||||
this.quaternion.copy( source.quaternion );
|
||||
this.scale.copy( source.scale );
|
||||
|
||||
this.matrix.copy( source.matrix );
|
||||
this.matrixWorld.copy( source.matrixWorld );
|
||||
|
||||
this.matrixAutoUpdate = source.matrixAutoUpdate;
|
||||
this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
|
||||
|
||||
this.layers.mask = source.layers.mask;
|
||||
this.visible = source.visible;
|
||||
|
||||
this.castShadow = source.castShadow;
|
||||
this.receiveShadow = source.receiveShadow;
|
||||
|
||||
this.frustumCulled = source.frustumCulled;
|
||||
this.renderOrder = source.renderOrder;
|
||||
|
||||
this.userData = JSON.parse( JSON.stringify( source.userData ) );
|
||||
|
||||
if ( recursive === true ) {
|
||||
|
||||
for ( var i = 0; i < source.children.length; i ++ ) {
|
||||
|
||||
var child = source.children[ i ];
|
||||
this.add( child.clone() );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.assign( Object3D.prototype, EventDispatcher.prototype );
|
||||
|
||||
export { Object3D };
|
||||
136
node_modules/three/src/core/Raycaster.js
generated
vendored
Normal file
136
node_modules/three/src/core/Raycaster.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
import { Ray } from '../math/Ray';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author bhouston / http://clara.io/
|
||||
* @author stephomi / http://stephaneginier.com/
|
||||
*/
|
||||
|
||||
function Raycaster( origin, direction, near, far ) {
|
||||
|
||||
this.ray = new Ray( origin, direction );
|
||||
// direction is assumed to be normalized (for accurate distance calculations)
|
||||
|
||||
this.near = near || 0;
|
||||
this.far = far || Infinity;
|
||||
|
||||
this.params = {
|
||||
Mesh: {},
|
||||
Line: {},
|
||||
LOD: {},
|
||||
Points: { threshold: 1 },
|
||||
Sprite: {}
|
||||
};
|
||||
|
||||
Object.defineProperties( this.params, {
|
||||
PointCloud: {
|
||||
get: function () {
|
||||
console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
|
||||
return this.Points;
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
function ascSort( a, b ) {
|
||||
|
||||
return a.distance - b.distance;
|
||||
|
||||
}
|
||||
|
||||
function intersectObject( object, raycaster, intersects, recursive ) {
|
||||
|
||||
if ( object.visible === false ) return;
|
||||
|
||||
object.raycast( raycaster, intersects );
|
||||
|
||||
if ( recursive === true ) {
|
||||
|
||||
var children = object.children;
|
||||
|
||||
for ( var i = 0, l = children.length; i < l; i ++ ) {
|
||||
|
||||
intersectObject( children[ i ], raycaster, intersects, true );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Raycaster.prototype = {
|
||||
|
||||
constructor: Raycaster,
|
||||
|
||||
linePrecision: 1,
|
||||
|
||||
set: function ( origin, direction ) {
|
||||
|
||||
// direction is assumed to be normalized (for accurate distance calculations)
|
||||
|
||||
this.ray.set( origin, direction );
|
||||
|
||||
},
|
||||
|
||||
setFromCamera: function ( coords, camera ) {
|
||||
|
||||
if ( (camera && 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();
|
||||
|
||||
} else if ( (camera && 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 );
|
||||
|
||||
} else {
|
||||
|
||||
console.error( 'THREE.Raycaster: Unsupported camera type.' );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
intersectObject: function ( object, recursive ) {
|
||||
|
||||
var intersects = [];
|
||||
|
||||
intersectObject( object, this, intersects, recursive );
|
||||
|
||||
intersects.sort( ascSort );
|
||||
|
||||
return intersects;
|
||||
|
||||
},
|
||||
|
||||
intersectObjects: function ( objects, recursive ) {
|
||||
|
||||
var intersects = [];
|
||||
|
||||
if ( Array.isArray( objects ) === false ) {
|
||||
|
||||
console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
|
||||
return intersects;
|
||||
|
||||
}
|
||||
|
||||
for ( var i = 0, l = objects.length; i < l; i ++ ) {
|
||||
|
||||
intersectObject( objects[ i ], this, intersects, recursive );
|
||||
|
||||
}
|
||||
|
||||
intersects.sort( ascSort );
|
||||
|
||||
return intersects;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { Raycaster };
|
||||
24
node_modules/three/src/core/Uniform.js
generated
vendored
Normal file
24
node_modules/three/src/core/Uniform.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function Uniform( value ) {
|
||||
|
||||
if ( typeof value === 'string' ) {
|
||||
|
||||
console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
|
||||
value = arguments[ 1 ];
|
||||
|
||||
}
|
||||
|
||||
this.value = value;
|
||||
|
||||
}
|
||||
|
||||
Uniform.prototype.clone = function () {
|
||||
|
||||
return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
|
||||
|
||||
};
|
||||
|
||||
export { Uniform };
|
||||
47
node_modules/three/src/extras/SceneUtils.js
generated
vendored
Normal file
47
node_modules/three/src/extras/SceneUtils.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Matrix4 } from '../math/Matrix4';
|
||||
import { Mesh } from '../objects/Mesh';
|
||||
import { Group } from '../objects/Group';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
var SceneUtils = {
|
||||
|
||||
createMultiMaterialObject: function ( geometry, materials ) {
|
||||
|
||||
var group = new Group();
|
||||
|
||||
for ( var i = 0, l = materials.length; i < l; i ++ ) {
|
||||
|
||||
group.add( new Mesh( geometry, materials[ i ] ) );
|
||||
|
||||
}
|
||||
|
||||
return group;
|
||||
|
||||
},
|
||||
|
||||
detach: function ( child, parent, scene ) {
|
||||
|
||||
child.applyMatrix( parent.matrixWorld );
|
||||
parent.remove( child );
|
||||
scene.add( child );
|
||||
|
||||
},
|
||||
|
||||
attach: function ( child, scene, parent ) {
|
||||
|
||||
var matrixWorldInverse = new Matrix4();
|
||||
matrixWorldInverse.getInverse( parent.matrixWorld );
|
||||
child.applyMatrix( matrixWorldInverse );
|
||||
|
||||
scene.remove( child );
|
||||
parent.add( child );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { SceneUtils };
|
||||
695
node_modules/three/src/extras/ShapeUtils.js
generated
vendored
Normal file
695
node_modules/three/src/extras/ShapeUtils.js
generated
vendored
Normal file
@@ -0,0 +1,695 @@
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
*/
|
||||
|
||||
var ShapeUtils = {
|
||||
|
||||
// calculate area of the contour polygon
|
||||
|
||||
area: function ( contour ) {
|
||||
|
||||
var n = contour.length;
|
||||
var a = 0.0;
|
||||
|
||||
for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
|
||||
|
||||
a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
|
||||
|
||||
}
|
||||
|
||||
return a * 0.5;
|
||||
|
||||
},
|
||||
|
||||
triangulate: ( function () {
|
||||
|
||||
/**
|
||||
* This code is a quick port of code written in C++ which was submitted to
|
||||
* flipcode.com by John W. Ratcliff // July 22, 2000
|
||||
* See original code and more information here:
|
||||
* http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
|
||||
*
|
||||
* ported to actionscript by Zevan Rosser
|
||||
* www.actionsnippet.com
|
||||
*
|
||||
* ported to javascript by Joshua Koo
|
||||
* http://www.lab4games.net/zz85/blog
|
||||
*
|
||||
*/
|
||||
|
||||
function snip( contour, u, v, w, n, verts ) {
|
||||
|
||||
var p;
|
||||
var ax, ay, bx, by;
|
||||
var cx, cy, px, py;
|
||||
|
||||
ax = contour[ verts[ u ] ].x;
|
||||
ay = contour[ verts[ u ] ].y;
|
||||
|
||||
bx = contour[ verts[ v ] ].x;
|
||||
by = contour[ verts[ v ] ].y;
|
||||
|
||||
cx = contour[ verts[ w ] ].x;
|
||||
cy = contour[ verts[ w ] ].y;
|
||||
|
||||
if ( ( bx - ax ) * ( cy - ay ) - ( by - ay ) * ( cx - ax ) <= 0 ) return false;
|
||||
|
||||
var aX, aY, bX, bY, cX, cY;
|
||||
var apx, apy, bpx, bpy, cpx, cpy;
|
||||
var cCROSSap, bCROSScp, aCROSSbp;
|
||||
|
||||
aX = cx - bx; aY = cy - by;
|
||||
bX = ax - cx; bY = ay - cy;
|
||||
cX = bx - ax; cY = by - ay;
|
||||
|
||||
for ( p = 0; p < n; p ++ ) {
|
||||
|
||||
px = contour[ verts[ p ] ].x;
|
||||
py = contour[ verts[ p ] ].y;
|
||||
|
||||
if ( ( ( px === ax ) && ( py === ay ) ) ||
|
||||
( ( px === bx ) && ( py === by ) ) ||
|
||||
( ( px === cx ) && ( py === cy ) ) ) continue;
|
||||
|
||||
apx = px - ax; apy = py - ay;
|
||||
bpx = px - bx; bpy = py - by;
|
||||
cpx = px - cx; cpy = py - cy;
|
||||
|
||||
// see if p is inside triangle abc
|
||||
|
||||
aCROSSbp = aX * bpy - aY * bpx;
|
||||
cCROSSap = cX * apy - cY * apx;
|
||||
bCROSScp = bX * cpy - bY * cpx;
|
||||
|
||||
if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// takes in an contour array and returns
|
||||
|
||||
return function triangulate( contour, indices ) {
|
||||
|
||||
var n = contour.length;
|
||||
|
||||
if ( n < 3 ) return null;
|
||||
|
||||
var result = [],
|
||||
verts = [],
|
||||
vertIndices = [];
|
||||
|
||||
/* we want a counter-clockwise polygon in verts */
|
||||
|
||||
var u, v, w;
|
||||
|
||||
if ( ShapeUtils.area( contour ) > 0.0 ) {
|
||||
|
||||
for ( v = 0; v < n; v ++ ) verts[ v ] = v;
|
||||
|
||||
} else {
|
||||
|
||||
for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
|
||||
|
||||
}
|
||||
|
||||
var nv = n;
|
||||
|
||||
/* remove nv - 2 vertices, creating 1 triangle every time */
|
||||
|
||||
var count = 2 * nv; /* error detection */
|
||||
|
||||
for ( v = nv - 1; nv > 2; ) {
|
||||
|
||||
/* if we loop, it is probably a non-simple polygon */
|
||||
|
||||
if ( ( count -- ) <= 0 ) {
|
||||
|
||||
//** Triangulate: ERROR - probable bad polygon!
|
||||
|
||||
//throw ( "Warning, unable to triangulate polygon!" );
|
||||
//return null;
|
||||
// Sometimes warning is fine, especially polygons are triangulated in reverse.
|
||||
console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
|
||||
|
||||
if ( indices ) return vertIndices;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/* three consecutive vertices in current polygon, <u,v,w> */
|
||||
|
||||
u = v; if ( nv <= u ) u = 0; /* previous */
|
||||
v = u + 1; if ( nv <= v ) v = 0; /* new v */
|
||||
w = v + 1; if ( nv <= w ) w = 0; /* next */
|
||||
|
||||
if ( snip( contour, u, v, w, nv, verts ) ) {
|
||||
|
||||
var a, b, c, s, t;
|
||||
|
||||
/* true names of the vertices */
|
||||
|
||||
a = verts[ u ];
|
||||
b = verts[ v ];
|
||||
c = verts[ w ];
|
||||
|
||||
/* output Triangle */
|
||||
|
||||
result.push( [ contour[ a ],
|
||||
contour[ b ],
|
||||
contour[ c ] ] );
|
||||
|
||||
|
||||
vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
|
||||
|
||||
/* remove v from the remaining polygon */
|
||||
|
||||
for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
|
||||
|
||||
verts[ s ] = verts[ t ];
|
||||
|
||||
}
|
||||
|
||||
nv --;
|
||||
|
||||
/* reset error detection counter */
|
||||
|
||||
count = 2 * nv;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( indices ) return vertIndices;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
} )(),
|
||||
|
||||
triangulateShape: function ( contour, holes ) {
|
||||
|
||||
function removeDupEndPts(points) {
|
||||
|
||||
var l = points.length;
|
||||
|
||||
if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
|
||||
|
||||
points.pop();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
removeDupEndPts( contour );
|
||||
holes.forEach( removeDupEndPts );
|
||||
|
||||
function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
|
||||
|
||||
// inOtherPt needs to be collinear to the inSegment
|
||||
if ( inSegPt1.x !== inSegPt2.x ) {
|
||||
|
||||
if ( inSegPt1.x < inSegPt2.x ) {
|
||||
|
||||
return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
|
||||
|
||||
} else {
|
||||
|
||||
return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ( inSegPt1.y < inSegPt2.y ) {
|
||||
|
||||
return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
|
||||
|
||||
} else {
|
||||
|
||||
return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
|
||||
|
||||
var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
|
||||
var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
|
||||
|
||||
var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
|
||||
var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
|
||||
|
||||
var limit = seg1dy * seg2dx - seg1dx * seg2dy;
|
||||
var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
|
||||
|
||||
if ( Math.abs( limit ) > Number.EPSILON ) {
|
||||
|
||||
// not parallel
|
||||
|
||||
var perpSeg2;
|
||||
if ( limit > 0 ) {
|
||||
|
||||
if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
|
||||
perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
|
||||
if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
|
||||
|
||||
} else {
|
||||
|
||||
if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
|
||||
perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
|
||||
if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
|
||||
|
||||
}
|
||||
|
||||
// i.e. to reduce rounding errors
|
||||
// intersection at endpoint of segment#1?
|
||||
if ( perpSeg2 === 0 ) {
|
||||
|
||||
if ( ( inExcludeAdjacentSegs ) &&
|
||||
( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
|
||||
return [ inSeg1Pt1 ];
|
||||
|
||||
}
|
||||
if ( perpSeg2 === limit ) {
|
||||
|
||||
if ( ( inExcludeAdjacentSegs ) &&
|
||||
( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
|
||||
return [ inSeg1Pt2 ];
|
||||
|
||||
}
|
||||
// intersection at endpoint of segment#2?
|
||||
if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
|
||||
if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
|
||||
|
||||
// return real intersection point
|
||||
var factorSeg1 = perpSeg2 / limit;
|
||||
return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
|
||||
y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
|
||||
|
||||
} else {
|
||||
|
||||
// parallel or collinear
|
||||
if ( ( perpSeg1 !== 0 ) ||
|
||||
( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
|
||||
|
||||
// they are collinear or degenerate
|
||||
var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
|
||||
var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
|
||||
// both segments are points
|
||||
if ( seg1Pt && seg2Pt ) {
|
||||
|
||||
if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
|
||||
( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
|
||||
return [ inSeg1Pt1 ]; // they are the same point
|
||||
|
||||
}
|
||||
// segment#1 is a single point
|
||||
if ( seg1Pt ) {
|
||||
|
||||
if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
|
||||
return [ inSeg1Pt1 ];
|
||||
|
||||
}
|
||||
// segment#2 is a single point
|
||||
if ( seg2Pt ) {
|
||||
|
||||
if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
|
||||
return [ inSeg2Pt1 ];
|
||||
|
||||
}
|
||||
|
||||
// they are collinear segments, which might overlap
|
||||
var seg1min, seg1max, seg1minVal, seg1maxVal;
|
||||
var seg2min, seg2max, seg2minVal, seg2maxVal;
|
||||
if ( seg1dx !== 0 ) {
|
||||
|
||||
// the segments are NOT on a vertical line
|
||||
if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
|
||||
|
||||
seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
|
||||
seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
|
||||
|
||||
} else {
|
||||
|
||||
seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
|
||||
seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
|
||||
|
||||
}
|
||||
if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
|
||||
|
||||
seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
|
||||
seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
|
||||
|
||||
} else {
|
||||
|
||||
seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
|
||||
seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// the segments are on a vertical line
|
||||
if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
|
||||
|
||||
seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
|
||||
seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
|
||||
|
||||
} else {
|
||||
|
||||
seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
|
||||
seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
|
||||
|
||||
}
|
||||
if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
|
||||
|
||||
seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
|
||||
seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
|
||||
|
||||
} else {
|
||||
|
||||
seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
|
||||
seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if ( seg1minVal <= seg2minVal ) {
|
||||
|
||||
if ( seg1maxVal < seg2minVal ) return [];
|
||||
if ( seg1maxVal === seg2minVal ) {
|
||||
|
||||
if ( inExcludeAdjacentSegs ) return [];
|
||||
return [ seg2min ];
|
||||
|
||||
}
|
||||
if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
|
||||
return [ seg2min, seg2max ];
|
||||
|
||||
} else {
|
||||
|
||||
if ( seg1minVal > seg2maxVal ) return [];
|
||||
if ( seg1minVal === seg2maxVal ) {
|
||||
|
||||
if ( inExcludeAdjacentSegs ) return [];
|
||||
return [ seg1min ];
|
||||
|
||||
}
|
||||
if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
|
||||
return [ seg1min, seg2max ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
|
||||
|
||||
// The order of legs is important
|
||||
|
||||
// translation of all points, so that Vertex is at (0,0)
|
||||
var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
|
||||
var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
|
||||
var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
|
||||
|
||||
// main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
|
||||
var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
|
||||
var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
|
||||
|
||||
if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
|
||||
|
||||
// angle != 180 deg.
|
||||
|
||||
var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
|
||||
// console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
|
||||
|
||||
if ( from2toAngle > 0 ) {
|
||||
|
||||
// main angle < 180 deg.
|
||||
return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
|
||||
|
||||
} else {
|
||||
|
||||
// main angle > 180 deg.
|
||||
return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// angle == 180 deg.
|
||||
// console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
|
||||
return ( from2otherAngle > 0 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function removeHoles( contour, holes ) {
|
||||
|
||||
var shape = contour.concat(); // work on this shape
|
||||
var hole;
|
||||
|
||||
function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
|
||||
|
||||
// Check if hole point lies within angle around shape point
|
||||
var lastShapeIdx = shape.length - 1;
|
||||
|
||||
var prevShapeIdx = inShapeIdx - 1;
|
||||
if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
|
||||
|
||||
var nextShapeIdx = inShapeIdx + 1;
|
||||
if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
|
||||
|
||||
var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
|
||||
if ( ! insideAngle ) {
|
||||
|
||||
// console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// Check if shape point lies within angle around hole point
|
||||
var lastHoleIdx = hole.length - 1;
|
||||
|
||||
var prevHoleIdx = inHoleIdx - 1;
|
||||
if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
|
||||
|
||||
var nextHoleIdx = inHoleIdx + 1;
|
||||
if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
|
||||
|
||||
insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
|
||||
if ( ! insideAngle ) {
|
||||
|
||||
// console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function intersectsShapeEdge( inShapePt, inHolePt ) {
|
||||
|
||||
// checks for intersections with shape edges
|
||||
var sIdx, nextIdx, intersection;
|
||||
for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
|
||||
|
||||
nextIdx = sIdx + 1; nextIdx %= shape.length;
|
||||
intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
|
||||
if ( intersection.length > 0 ) return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
var indepHoles = [];
|
||||
|
||||
function intersectsHoleEdge( inShapePt, inHolePt ) {
|
||||
|
||||
// checks for intersections with hole edges
|
||||
var ihIdx, chkHole,
|
||||
hIdx, nextIdx, intersection;
|
||||
for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
|
||||
|
||||
chkHole = holes[ indepHoles[ ihIdx ]];
|
||||
for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
|
||||
|
||||
nextIdx = hIdx + 1; nextIdx %= chkHole.length;
|
||||
intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
|
||||
if ( intersection.length > 0 ) return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
var holeIndex, shapeIndex,
|
||||
shapePt, holePt,
|
||||
holeIdx, cutKey, failedCuts = [],
|
||||
tmpShape1, tmpShape2,
|
||||
tmpHole1, tmpHole2;
|
||||
|
||||
for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
indepHoles.push( h );
|
||||
|
||||
}
|
||||
|
||||
var minShapeIndex = 0;
|
||||
var counter = indepHoles.length * 2;
|
||||
while ( indepHoles.length > 0 ) {
|
||||
|
||||
counter --;
|
||||
if ( counter < 0 ) {
|
||||
|
||||
console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// search for shape-vertex and hole-vertex,
|
||||
// which can be connected without intersections
|
||||
for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
|
||||
|
||||
shapePt = shape[ shapeIndex ];
|
||||
holeIndex = - 1;
|
||||
|
||||
// search for hole which can be reached without intersections
|
||||
for ( var h = 0; h < indepHoles.length; h ++ ) {
|
||||
|
||||
holeIdx = indepHoles[ h ];
|
||||
|
||||
// prevent multiple checks
|
||||
cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
|
||||
if ( failedCuts[ cutKey ] !== undefined ) continue;
|
||||
|
||||
hole = holes[ holeIdx ];
|
||||
for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
|
||||
|
||||
holePt = hole[ h2 ];
|
||||
if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
|
||||
if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
|
||||
if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
|
||||
|
||||
holeIndex = h2;
|
||||
indepHoles.splice( h, 1 );
|
||||
|
||||
tmpShape1 = shape.slice( 0, shapeIndex + 1 );
|
||||
tmpShape2 = shape.slice( shapeIndex );
|
||||
tmpHole1 = hole.slice( holeIndex );
|
||||
tmpHole2 = hole.slice( 0, holeIndex + 1 );
|
||||
|
||||
shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
|
||||
|
||||
minShapeIndex = shapeIndex;
|
||||
|
||||
// Debug only, to show the selected cuts
|
||||
// glob_CutLines.push( [ shapePt, holePt ] );
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
if ( holeIndex >= 0 ) break; // hole-vertex found
|
||||
|
||||
failedCuts[ cutKey ] = true; // remember failure
|
||||
|
||||
}
|
||||
if ( holeIndex >= 0 ) break; // hole-vertex found
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return shape; /* shape with no holes */
|
||||
|
||||
}
|
||||
|
||||
|
||||
var i, il, f, face,
|
||||
key, index,
|
||||
allPointsMap = {};
|
||||
|
||||
// To maintain reference to old shape, one must match coordinates, or offset the indices from original arrays. It's probably easier to do the first.
|
||||
|
||||
var allpoints = contour.concat();
|
||||
|
||||
for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
Array.prototype.push.apply( allpoints, holes[ h ] );
|
||||
|
||||
}
|
||||
|
||||
//console.log( "allpoints",allpoints, allpoints.length );
|
||||
|
||||
// prepare all points map
|
||||
|
||||
for ( i = 0, il = allpoints.length; i < il; i ++ ) {
|
||||
|
||||
key = allpoints[ i ].x + ":" + allpoints[ i ].y;
|
||||
|
||||
if ( allPointsMap[ key ] !== undefined ) {
|
||||
|
||||
console.warn( "THREE.ShapeUtils: Duplicate point", key, i );
|
||||
|
||||
}
|
||||
|
||||
allPointsMap[ key ] = i;
|
||||
|
||||
}
|
||||
|
||||
// remove holes by cutting paths to holes and adding them to the shape
|
||||
var shapeWithoutHoles = removeHoles( contour, holes );
|
||||
|
||||
var triangles = ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
|
||||
//console.log( "triangles",triangles, triangles.length );
|
||||
|
||||
// check all face vertices against all points map
|
||||
|
||||
for ( i = 0, il = triangles.length; i < il; i ++ ) {
|
||||
|
||||
face = triangles[ i ];
|
||||
|
||||
for ( f = 0; f < 3; f ++ ) {
|
||||
|
||||
key = face[ f ].x + ":" + face[ f ].y;
|
||||
|
||||
index = allPointsMap[ key ];
|
||||
|
||||
if ( index !== undefined ) {
|
||||
|
||||
face[ f ] = index;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return triangles.concat();
|
||||
|
||||
},
|
||||
|
||||
isClockWise: function ( pts ) {
|
||||
|
||||
return ShapeUtils.area( pts ) < 0;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { ShapeUtils };
|
||||
387
node_modules/three/src/extras/core/Curve.js
generated
vendored
Normal file
387
node_modules/three/src/extras/core/Curve.js
generated
vendored
Normal file
@@ -0,0 +1,387 @@
|
||||
import { _Math } from '../../math/Math';
|
||||
import { Vector3 } from '../../math/Vector3';
|
||||
import { Matrix4 } from '../../math/Matrix4';
|
||||
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
* Extensible curve object
|
||||
*
|
||||
* Some common of Curve methods
|
||||
* .getPoint(t), getTangent(t)
|
||||
* .getPointAt(u), getTangentAt(u)
|
||||
* .getPoints(), .getSpacedPoints()
|
||||
* .getLength()
|
||||
* .updateArcLengths()
|
||||
*
|
||||
* This following classes subclasses THREE.Curve:
|
||||
*
|
||||
* -- 2d classes --
|
||||
* THREE.LineCurve
|
||||
* THREE.QuadraticBezierCurve
|
||||
* THREE.CubicBezierCurve
|
||||
* THREE.SplineCurve
|
||||
* THREE.ArcCurve
|
||||
* THREE.EllipseCurve
|
||||
*
|
||||
* -- 3d classes --
|
||||
* THREE.LineCurve3
|
||||
* THREE.QuadraticBezierCurve3
|
||||
* THREE.CubicBezierCurve3
|
||||
* THREE.CatmullRomCurve3
|
||||
*
|
||||
* A series of curves can be represented as a THREE.CurvePath
|
||||
*
|
||||
**/
|
||||
|
||||
/**************************************************************
|
||||
* Abstract Curve base class
|
||||
**************************************************************/
|
||||
|
||||
function Curve() {}
|
||||
|
||||
Curve.prototype = {
|
||||
|
||||
constructor: Curve,
|
||||
|
||||
// Virtual base class method to overwrite and implement in subclasses
|
||||
// - t [0 .. 1]
|
||||
|
||||
getPoint: function ( t ) {
|
||||
|
||||
console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
|
||||
return null;
|
||||
|
||||
},
|
||||
|
||||
// Get point at relative position in curve according to arc length
|
||||
// - u [0 .. 1]
|
||||
|
||||
getPointAt: function ( u ) {
|
||||
|
||||
var t = this.getUtoTmapping( u );
|
||||
return this.getPoint( t );
|
||||
|
||||
},
|
||||
|
||||
// Get sequence of points using getPoint( t )
|
||||
|
||||
getPoints: function ( divisions ) {
|
||||
|
||||
if ( isNaN( divisions ) ) divisions = 5;
|
||||
|
||||
var points = [];
|
||||
|
||||
for ( var d = 0; d <= divisions; d ++ ) {
|
||||
|
||||
points.push( this.getPoint( d / divisions ) );
|
||||
|
||||
}
|
||||
|
||||
return points;
|
||||
|
||||
},
|
||||
|
||||
// Get sequence of points using getPointAt( u )
|
||||
|
||||
getSpacedPoints: function ( divisions ) {
|
||||
|
||||
if ( isNaN( divisions ) ) divisions = 5;
|
||||
|
||||
var points = [];
|
||||
|
||||
for ( var d = 0; d <= divisions; d ++ ) {
|
||||
|
||||
points.push( this.getPointAt( d / divisions ) );
|
||||
|
||||
}
|
||||
|
||||
return points;
|
||||
|
||||
},
|
||||
|
||||
// Get total curve arc length
|
||||
|
||||
getLength: function () {
|
||||
|
||||
var lengths = this.getLengths();
|
||||
return lengths[ lengths.length - 1 ];
|
||||
|
||||
},
|
||||
|
||||
// Get list of cumulative segment lengths
|
||||
|
||||
getLengths: function ( divisions ) {
|
||||
|
||||
if ( isNaN( divisions ) ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
|
||||
|
||||
if ( this.cacheArcLengths
|
||||
&& ( this.cacheArcLengths.length === divisions + 1 )
|
||||
&& ! this.needsUpdate ) {
|
||||
|
||||
//console.log( "cached", this.cacheArcLengths );
|
||||
return this.cacheArcLengths;
|
||||
|
||||
}
|
||||
|
||||
this.needsUpdate = false;
|
||||
|
||||
var cache = [];
|
||||
var current, last = this.getPoint( 0 );
|
||||
var p, sum = 0;
|
||||
|
||||
cache.push( 0 );
|
||||
|
||||
for ( p = 1; p <= divisions; p ++ ) {
|
||||
|
||||
current = this.getPoint ( p / divisions );
|
||||
sum += current.distanceTo( last );
|
||||
cache.push( sum );
|
||||
last = current;
|
||||
|
||||
}
|
||||
|
||||
this.cacheArcLengths = cache;
|
||||
|
||||
return cache; // { sums: cache, sum:sum }; Sum is in the last element.
|
||||
|
||||
},
|
||||
|
||||
updateArcLengths: function() {
|
||||
|
||||
this.needsUpdate = true;
|
||||
this.getLengths();
|
||||
|
||||
},
|
||||
|
||||
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
|
||||
|
||||
getUtoTmapping: function ( u, distance ) {
|
||||
|
||||
var arcLengths = this.getLengths();
|
||||
|
||||
var i = 0, il = arcLengths.length;
|
||||
|
||||
var targetArcLength; // The targeted u distance value to get
|
||||
|
||||
if ( distance ) {
|
||||
|
||||
targetArcLength = distance;
|
||||
|
||||
} else {
|
||||
|
||||
targetArcLength = u * arcLengths[ il - 1 ];
|
||||
|
||||
}
|
||||
|
||||
//var time = Date.now();
|
||||
|
||||
// binary search for the index with largest value smaller than target u distance
|
||||
|
||||
var low = 0, high = il - 1, comparison;
|
||||
|
||||
while ( low <= high ) {
|
||||
|
||||
i = Math.floor( low + ( high - low ) / 2 ); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
|
||||
|
||||
comparison = arcLengths[ i ] - targetArcLength;
|
||||
|
||||
if ( comparison < 0 ) {
|
||||
|
||||
low = i + 1;
|
||||
|
||||
} else if ( comparison > 0 ) {
|
||||
|
||||
high = i - 1;
|
||||
|
||||
} else {
|
||||
|
||||
high = i;
|
||||
break;
|
||||
|
||||
// DONE
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
i = high;
|
||||
|
||||
//console.log('b' , i, low, high, Date.now()- time);
|
||||
|
||||
if ( arcLengths[ i ] === targetArcLength ) {
|
||||
|
||||
var t = i / ( il - 1 );
|
||||
return t;
|
||||
|
||||
}
|
||||
|
||||
// we could get finer grain at lengths, or use simple interpolation between two points
|
||||
|
||||
var lengthBefore = arcLengths[ i ];
|
||||
var lengthAfter = arcLengths[ i + 1 ];
|
||||
|
||||
var segmentLength = lengthAfter - lengthBefore;
|
||||
|
||||
// determine where we are between the 'before' and 'after' points
|
||||
|
||||
var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
|
||||
|
||||
// add that fractional amount to t
|
||||
|
||||
var t = ( i + segmentFraction ) / ( il - 1 );
|
||||
|
||||
return t;
|
||||
|
||||
},
|
||||
|
||||
// Returns a unit vector tangent at t
|
||||
// In case any sub curve does not implement its tangent derivation,
|
||||
// 2 points a small delta apart will be used to find its gradient
|
||||
// which seems to give a reasonable approximation
|
||||
|
||||
getTangent: function( t ) {
|
||||
|
||||
var delta = 0.0001;
|
||||
var t1 = t - delta;
|
||||
var t2 = t + delta;
|
||||
|
||||
// Capping in case of danger
|
||||
|
||||
if ( t1 < 0 ) t1 = 0;
|
||||
if ( t2 > 1 ) t2 = 1;
|
||||
|
||||
var pt1 = this.getPoint( t1 );
|
||||
var pt2 = this.getPoint( t2 );
|
||||
|
||||
var vec = pt2.clone().sub( pt1 );
|
||||
return vec.normalize();
|
||||
|
||||
},
|
||||
|
||||
getTangentAt: function ( u ) {
|
||||
|
||||
var t = this.getUtoTmapping( u );
|
||||
return this.getTangent( t );
|
||||
|
||||
},
|
||||
|
||||
computeFrenetFrames: function ( segments, closed ) {
|
||||
|
||||
// see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
|
||||
|
||||
var normal = new Vector3();
|
||||
|
||||
var tangents = [];
|
||||
var normals = [];
|
||||
var binormals = [];
|
||||
|
||||
var vec = new Vector3();
|
||||
var mat = new Matrix4();
|
||||
|
||||
var i, u, theta;
|
||||
|
||||
// compute the tangent vectors for each segment on the curve
|
||||
|
||||
for ( i = 0; i <= segments; i ++ ) {
|
||||
|
||||
u = i / segments;
|
||||
|
||||
tangents[ i ] = this.getTangentAt( u );
|
||||
tangents[ i ].normalize();
|
||||
|
||||
}
|
||||
|
||||
// select an initial normal vector perpendicular to the first tangent vector,
|
||||
// and in the direction of the minimum tangent xyz component
|
||||
|
||||
normals[ 0 ] = new Vector3();
|
||||
binormals[ 0 ] = new Vector3();
|
||||
var min = Number.MAX_VALUE;
|
||||
var tx = Math.abs( tangents[ 0 ].x );
|
||||
var ty = Math.abs( tangents[ 0 ].y );
|
||||
var tz = Math.abs( tangents[ 0 ].z );
|
||||
|
||||
if ( tx <= min ) {
|
||||
|
||||
min = tx;
|
||||
normal.set( 1, 0, 0 );
|
||||
|
||||
}
|
||||
|
||||
if ( ty <= min ) {
|
||||
|
||||
min = ty;
|
||||
normal.set( 0, 1, 0 );
|
||||
|
||||
}
|
||||
|
||||
if ( tz <= min ) {
|
||||
|
||||
normal.set( 0, 0, 1 );
|
||||
|
||||
}
|
||||
|
||||
vec.crossVectors( tangents[ 0 ], normal ).normalize();
|
||||
|
||||
normals[ 0 ].crossVectors( tangents[ 0 ], vec );
|
||||
binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
|
||||
|
||||
|
||||
// compute the slowly-varying normal and binormal vectors for each segment on the curve
|
||||
|
||||
for ( i = 1; i <= segments; i ++ ) {
|
||||
|
||||
normals[ i ] = normals[ i - 1 ].clone();
|
||||
|
||||
binormals[ i ] = binormals[ i - 1 ].clone();
|
||||
|
||||
vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
|
||||
|
||||
if ( vec.length() > Number.EPSILON ) {
|
||||
|
||||
vec.normalize();
|
||||
|
||||
theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
|
||||
|
||||
normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
|
||||
|
||||
}
|
||||
|
||||
binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
|
||||
|
||||
}
|
||||
|
||||
// if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
|
||||
|
||||
if ( closed === true ) {
|
||||
|
||||
theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
|
||||
theta /= segments;
|
||||
|
||||
if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
|
||||
|
||||
theta = - theta;
|
||||
|
||||
}
|
||||
|
||||
for ( i = 1; i <= segments; i ++ ) {
|
||||
|
||||
// twist a little...
|
||||
normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
|
||||
binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
tangents: tangents,
|
||||
normals: normals,
|
||||
binormals: binormals
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export { Curve };
|
||||
241
node_modules/three/src/extras/core/CurvePath.js
generated
vendored
Normal file
241
node_modules/three/src/extras/core/CurvePath.js
generated
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
import { Curve } from './Curve';
|
||||
import { Vector3 } from '../../math/Vector3';
|
||||
import { Geometry } from '../../core/Geometry';
|
||||
import { LineCurve } from '../curves/LineCurve';
|
||||
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
*
|
||||
**/
|
||||
|
||||
/**************************************************************
|
||||
* Curved Path - a curve path is simply a array of connected
|
||||
* curves, but retains the api of a curve
|
||||
**************************************************************/
|
||||
|
||||
function CurvePath() {
|
||||
|
||||
this.curves = [];
|
||||
|
||||
this.autoClose = false; // Automatically closes the path
|
||||
|
||||
}
|
||||
|
||||
CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
|
||||
|
||||
constructor: CurvePath,
|
||||
|
||||
add: function ( curve ) {
|
||||
|
||||
this.curves.push( curve );
|
||||
|
||||
},
|
||||
|
||||
closePath: function () {
|
||||
|
||||
// Add a line curve if start and end of lines are not connected
|
||||
var startPoint = this.curves[ 0 ].getPoint( 0 );
|
||||
var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
|
||||
|
||||
if ( ! startPoint.equals( endPoint ) ) {
|
||||
|
||||
this.curves.push( new LineCurve( endPoint, startPoint ) );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// To get accurate point with reference to
|
||||
// entire path distance at time t,
|
||||
// following has to be done:
|
||||
|
||||
// 1. Length of each sub path have to be known
|
||||
// 2. Locate and identify type of curve
|
||||
// 3. Get t for the curve
|
||||
// 4. Return curve.getPointAt(t')
|
||||
|
||||
getPoint: function ( t ) {
|
||||
|
||||
var d = t * this.getLength();
|
||||
var curveLengths = this.getCurveLengths();
|
||||
var i = 0;
|
||||
|
||||
// To think about boundaries points.
|
||||
|
||||
while ( i < curveLengths.length ) {
|
||||
|
||||
if ( curveLengths[ i ] >= d ) {
|
||||
|
||||
var diff = curveLengths[ i ] - d;
|
||||
var curve = this.curves[ i ];
|
||||
|
||||
var segmentLength = curve.getLength();
|
||||
var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
|
||||
|
||||
return curve.getPointAt( u );
|
||||
|
||||
}
|
||||
|
||||
i ++;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
// loop where sum != 0, sum > d , sum+1 <d
|
||||
|
||||
},
|
||||
|
||||
// We cannot use the default THREE.Curve getPoint() with getLength() because in
|
||||
// THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
|
||||
// getPoint() depends on getLength
|
||||
|
||||
getLength: function () {
|
||||
|
||||
var lens = this.getCurveLengths();
|
||||
return lens[ lens.length - 1 ];
|
||||
|
||||
},
|
||||
|
||||
// cacheLengths must be recalculated.
|
||||
updateArcLengths: function () {
|
||||
|
||||
this.needsUpdate = true;
|
||||
this.cacheLengths = null;
|
||||
this.getLengths();
|
||||
|
||||
},
|
||||
|
||||
// Compute lengths and cache them
|
||||
// We cannot overwrite getLengths() because UtoT mapping uses it.
|
||||
|
||||
getCurveLengths: function () {
|
||||
|
||||
// We use cache values if curves and cache array are same length
|
||||
|
||||
if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
|
||||
|
||||
return this.cacheLengths;
|
||||
|
||||
}
|
||||
|
||||
// Get length of sub-curve
|
||||
// Push sums into cached array
|
||||
|
||||
var lengths = [], sums = 0;
|
||||
|
||||
for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
|
||||
|
||||
sums += this.curves[ i ].getLength();
|
||||
lengths.push( sums );
|
||||
|
||||
}
|
||||
|
||||
this.cacheLengths = lengths;
|
||||
|
||||
return lengths;
|
||||
|
||||
},
|
||||
|
||||
getSpacedPoints: function ( divisions ) {
|
||||
|
||||
if ( isNaN( divisions ) ) divisions = 40;
|
||||
|
||||
var points = [];
|
||||
|
||||
for ( var i = 0; i <= divisions; i ++ ) {
|
||||
|
||||
points.push( this.getPoint( i / divisions ) );
|
||||
|
||||
}
|
||||
|
||||
if ( this.autoClose ) {
|
||||
|
||||
points.push( points[ 0 ] );
|
||||
|
||||
}
|
||||
|
||||
return points;
|
||||
|
||||
},
|
||||
|
||||
getPoints: function ( divisions ) {
|
||||
|
||||
divisions = divisions || 12;
|
||||
|
||||
var points = [], last;
|
||||
|
||||
for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
|
||||
|
||||
var curve = curves[ i ];
|
||||
var resolution = (curve && curve.isEllipseCurve) ? divisions * 2
|
||||
: (curve && curve.isLineCurve) ? 1
|
||||
: (curve && curve.isSplineCurve) ? divisions * curve.points.length
|
||||
: divisions;
|
||||
|
||||
var pts = curve.getPoints( resolution );
|
||||
|
||||
for ( var j = 0; j < pts.length; j++ ) {
|
||||
|
||||
var point = pts[ j ];
|
||||
|
||||
if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
|
||||
|
||||
points.push( point );
|
||||
last = point;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( this.autoClose && points.length > 1 && !points[ points.length - 1 ].equals( points[ 0 ] ) ) {
|
||||
|
||||
points.push( points[ 0 ] );
|
||||
|
||||
}
|
||||
|
||||
return points;
|
||||
|
||||
},
|
||||
|
||||
/**************************************************************
|
||||
* Create Geometries Helpers
|
||||
**************************************************************/
|
||||
|
||||
/// Generate geometry from path points (for Line or Points objects)
|
||||
|
||||
createPointsGeometry: function ( divisions ) {
|
||||
|
||||
var pts = this.getPoints( divisions );
|
||||
return this.createGeometry( pts );
|
||||
|
||||
},
|
||||
|
||||
// Generate geometry from equidistant sampling along the path
|
||||
|
||||
createSpacedPointsGeometry: function ( divisions ) {
|
||||
|
||||
var pts = this.getSpacedPoints( divisions );
|
||||
return this.createGeometry( pts );
|
||||
|
||||
},
|
||||
|
||||
createGeometry: function ( points ) {
|
||||
|
||||
var geometry = new Geometry();
|
||||
|
||||
for ( var i = 0, l = points.length; i < l; i ++ ) {
|
||||
|
||||
var point = points[ i ];
|
||||
geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
|
||||
|
||||
}
|
||||
|
||||
return geometry;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { CurvePath };
|
||||
185
node_modules/three/src/extras/core/Font.js
generated
vendored
Normal file
185
node_modules/three/src/extras/core/Font.js
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
import { QuadraticBezier, CubicBezier } from './Interpolations';
|
||||
import { ShapePath } from './ShapePath';
|
||||
|
||||
|
||||
function Font( data ) {
|
||||
|
||||
this.data = data;
|
||||
|
||||
}
|
||||
|
||||
Object.assign( Font.prototype, {
|
||||
|
||||
isFont: true,
|
||||
|
||||
generateShapes: function ( text, size, divisions ) {
|
||||
|
||||
function createPaths( text ) {
|
||||
|
||||
var chars = String( text ).split( '' );
|
||||
var scale = size / data.resolution;
|
||||
var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
|
||||
|
||||
var offsetX = 0, offsetY = 0;
|
||||
|
||||
var paths = [];
|
||||
|
||||
for ( var i = 0; i < chars.length; i ++ ) {
|
||||
|
||||
var char = chars[ i ];
|
||||
|
||||
if ( char === '\n' ) {
|
||||
|
||||
offsetX = 0;
|
||||
offsetY -= line_height;
|
||||
|
||||
} else {
|
||||
|
||||
var ret = createPath( char, scale, offsetX, offsetY );
|
||||
offsetX += ret.offsetX;
|
||||
paths.push( ret.path );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return paths;
|
||||
|
||||
}
|
||||
|
||||
function createPath( c, scale, offsetX, offsetY ) {
|
||||
|
||||
var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
|
||||
|
||||
if ( ! glyph ) return;
|
||||
|
||||
var path = new ShapePath();
|
||||
|
||||
var pts = [];
|
||||
var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
|
||||
|
||||
if ( glyph.o ) {
|
||||
|
||||
var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
|
||||
|
||||
for ( var i = 0, l = outline.length; i < l; ) {
|
||||
|
||||
var action = outline[ i ++ ];
|
||||
|
||||
switch ( action ) {
|
||||
|
||||
case 'm': // moveTo
|
||||
|
||||
x = outline[ i ++ ] * scale + offsetX;
|
||||
y = outline[ i ++ ] * scale + offsetY;
|
||||
|
||||
path.moveTo( x, y );
|
||||
|
||||
break;
|
||||
|
||||
case 'l': // lineTo
|
||||
|
||||
x = outline[ i ++ ] * scale + offsetX;
|
||||
y = outline[ i ++ ] * scale + offsetY;
|
||||
|
||||
path.lineTo( x, y );
|
||||
|
||||
break;
|
||||
|
||||
case 'q': // quadraticCurveTo
|
||||
|
||||
cpx = outline[ i ++ ] * scale + offsetX;
|
||||
cpy = outline[ i ++ ] * scale + offsetY;
|
||||
cpx1 = outline[ i ++ ] * scale + offsetX;
|
||||
cpy1 = outline[ i ++ ] * scale + offsetY;
|
||||
|
||||
path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
|
||||
|
||||
laste = pts[ pts.length - 1 ];
|
||||
|
||||
if ( laste ) {
|
||||
|
||||
cpx0 = laste.x;
|
||||
cpy0 = laste.y;
|
||||
|
||||
for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
|
||||
|
||||
var t = i2 / divisions;
|
||||
QuadraticBezier( t, cpx0, cpx1, cpx );
|
||||
QuadraticBezier( t, cpy0, cpy1, cpy );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'b': // bezierCurveTo
|
||||
|
||||
cpx = outline[ i ++ ] * scale + offsetX;
|
||||
cpy = outline[ i ++ ] * scale + offsetY;
|
||||
cpx1 = outline[ i ++ ] * scale + offsetX;
|
||||
cpy1 = outline[ i ++ ] * scale + offsetY;
|
||||
cpx2 = outline[ i ++ ] * scale + offsetX;
|
||||
cpy2 = outline[ i ++ ] * scale + offsetY;
|
||||
|
||||
path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
|
||||
|
||||
laste = pts[ pts.length - 1 ];
|
||||
|
||||
if ( laste ) {
|
||||
|
||||
cpx0 = laste.x;
|
||||
cpy0 = laste.y;
|
||||
|
||||
for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
|
||||
|
||||
var t = i2 / divisions;
|
||||
CubicBezier( t, cpx0, cpx1, cpx2, cpx );
|
||||
CubicBezier( t, cpy0, cpy1, cpy2, cpy );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return { offsetX: glyph.ha * scale, path: path };
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
if ( size === undefined ) size = 100;
|
||||
if ( divisions === undefined ) divisions = 4;
|
||||
|
||||
var data = this.data;
|
||||
|
||||
var paths = createPaths( text );
|
||||
var shapes = [];
|
||||
|
||||
for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
|
||||
|
||||
Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
|
||||
|
||||
}
|
||||
|
||||
return shapes;
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { Font };
|
||||
81
node_modules/three/src/extras/core/Interpolations.js
generated
vendored
Normal file
81
node_modules/three/src/extras/core/Interpolations.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
*
|
||||
* Bezier Curves formulas obtained from
|
||||
* http://en.wikipedia.org/wiki/Bézier_curve
|
||||
*/
|
||||
|
||||
function CatmullRom( t, p0, p1, p2, p3 ) {
|
||||
|
||||
var v0 = ( p2 - p0 ) * 0.5;
|
||||
var v1 = ( p3 - p1 ) * 0.5;
|
||||
var t2 = t * t;
|
||||
var t3 = t * t2;
|
||||
return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
function QuadraticBezierP0( t, p ) {
|
||||
|
||||
var k = 1 - t;
|
||||
return k * k * p;
|
||||
|
||||
}
|
||||
|
||||
function QuadraticBezierP1( t, p ) {
|
||||
|
||||
return 2 * ( 1 - t ) * t * p;
|
||||
|
||||
}
|
||||
|
||||
function QuadraticBezierP2( t, p ) {
|
||||
|
||||
return t * t * p;
|
||||
|
||||
}
|
||||
|
||||
function QuadraticBezier( t, p0, p1, p2 ) {
|
||||
|
||||
return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
|
||||
QuadraticBezierP2( t, p2 );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
function CubicBezierP0( t, p ) {
|
||||
|
||||
var k = 1 - t;
|
||||
return k * k * k * p;
|
||||
|
||||
}
|
||||
|
||||
function CubicBezierP1( t, p ) {
|
||||
|
||||
var k = 1 - t;
|
||||
return 3 * k * k * t * p;
|
||||
|
||||
}
|
||||
|
||||
function CubicBezierP2( t, p ) {
|
||||
|
||||
return 3 * ( 1 - t ) * t * t * p;
|
||||
|
||||
}
|
||||
|
||||
function CubicBezierP3( t, p ) {
|
||||
|
||||
return t * t * t * p;
|
||||
|
||||
}
|
||||
|
||||
function CubicBezier( t, p0, p1, p2, p3 ) {
|
||||
|
||||
return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
|
||||
CubicBezierP3( t, p3 );
|
||||
|
||||
}
|
||||
|
||||
export { CatmullRom, QuadraticBezier, CubicBezier };
|
||||
27
node_modules/three/src/extras/core/Path.js
generated
vendored
Normal file
27
node_modules/three/src/extras/core/Path.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
* Creates free form 2d path using series of points, lines or curves.
|
||||
**/
|
||||
|
||||
import { PathPrototype } from './PathPrototype';
|
||||
import { Vector2 } from '../../math/Vector2';
|
||||
import { CurvePath } from './CurvePath';
|
||||
|
||||
|
||||
function Path( points ) {
|
||||
|
||||
CurvePath.call( this );
|
||||
this.currentPoint = new Vector2();
|
||||
|
||||
if ( points ) {
|
||||
|
||||
this.fromPoints( points );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Path.prototype = PathPrototype;
|
||||
PathPrototype.constructor = Path;
|
||||
|
||||
export { Path };
|
||||
129
node_modules/three/src/extras/core/PathPrototype.js
generated
vendored
Normal file
129
node_modules/three/src/extras/core/PathPrototype.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
import { CurvePath } from './CurvePath';
|
||||
import { EllipseCurve } from '../curves/EllipseCurve';
|
||||
import { SplineCurve } from '../curves/SplineCurve';
|
||||
import { Vector2 } from '../../math/Vector2';
|
||||
import { CubicBezierCurve } from '../curves/CubicBezierCurve';
|
||||
import { QuadraticBezierCurve } from '../curves/QuadraticBezierCurve';
|
||||
import { LineCurve } from '../curves/LineCurve';
|
||||
|
||||
var PathPrototype = Object.assign( Object.create( CurvePath.prototype ), {
|
||||
|
||||
fromPoints: function ( vectors ) {
|
||||
|
||||
this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
|
||||
|
||||
for ( var i = 1, l = vectors.length; i < l; i ++ ) {
|
||||
|
||||
this.lineTo( vectors[ i ].x, vectors[ i ].y );
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
moveTo: function ( x, y ) {
|
||||
|
||||
this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
|
||||
|
||||
},
|
||||
|
||||
lineTo: function ( x, y ) {
|
||||
|
||||
var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
|
||||
this.curves.push( curve );
|
||||
|
||||
this.currentPoint.set( x, y );
|
||||
|
||||
},
|
||||
|
||||
quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
|
||||
|
||||
var curve = new QuadraticBezierCurve(
|
||||
this.currentPoint.clone(),
|
||||
new Vector2( aCPx, aCPy ),
|
||||
new Vector2( aX, aY )
|
||||
);
|
||||
|
||||
this.curves.push( curve );
|
||||
|
||||
this.currentPoint.set( aX, aY );
|
||||
|
||||
},
|
||||
|
||||
bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
|
||||
|
||||
var curve = new CubicBezierCurve(
|
||||
this.currentPoint.clone(),
|
||||
new Vector2( aCP1x, aCP1y ),
|
||||
new Vector2( aCP2x, aCP2y ),
|
||||
new Vector2( aX, aY )
|
||||
);
|
||||
|
||||
this.curves.push( curve );
|
||||
|
||||
this.currentPoint.set( aX, aY );
|
||||
|
||||
},
|
||||
|
||||
splineThru: function ( pts /*Array of Vector*/ ) {
|
||||
|
||||
var npts = [ this.currentPoint.clone() ].concat( pts );
|
||||
|
||||
var curve = new SplineCurve( npts );
|
||||
this.curves.push( curve );
|
||||
|
||||
this.currentPoint.copy( pts[ pts.length - 1 ] );
|
||||
|
||||
},
|
||||
|
||||
arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
||||
|
||||
var x0 = this.currentPoint.x;
|
||||
var y0 = this.currentPoint.y;
|
||||
|
||||
this.absarc( aX + x0, aY + y0, aRadius,
|
||||
aStartAngle, aEndAngle, aClockwise );
|
||||
|
||||
},
|
||||
|
||||
absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
||||
|
||||
this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
|
||||
|
||||
},
|
||||
|
||||
ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
||||
|
||||
var x0 = this.currentPoint.x;
|
||||
var y0 = this.currentPoint.y;
|
||||
|
||||
this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
|
||||
|
||||
},
|
||||
|
||||
absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
||||
|
||||
var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
|
||||
|
||||
if ( this.curves.length > 0 ) {
|
||||
|
||||
// if a previous curve is present, attempt to join
|
||||
var firstPoint = curve.getPoint( 0 );
|
||||
|
||||
if ( ! firstPoint.equals( this.currentPoint ) ) {
|
||||
|
||||
this.lineTo( firstPoint.x, firstPoint.y );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.curves.push( curve );
|
||||
|
||||
var lastPoint = curve.getPoint( 1 );
|
||||
this.currentPoint.copy( lastPoint );
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
export { PathPrototype };
|
||||
63
node_modules/three/src/extras/core/Shape.js
generated
vendored
Normal file
63
node_modules/three/src/extras/core/Shape.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import { PathPrototype } from './PathPrototype';
|
||||
import { Path } from './Path';
|
||||
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
* Defines a 2d shape plane using paths.
|
||||
**/
|
||||
|
||||
// STEP 1 Create a path.
|
||||
// STEP 2 Turn path into shape.
|
||||
// STEP 3 ExtrudeGeometry takes in Shape/Shapes
|
||||
// STEP 3a - Extract points from each shape, turn to vertices
|
||||
// STEP 3b - Triangulate each shape, add faces.
|
||||
|
||||
function Shape() {
|
||||
|
||||
Path.apply( this, arguments );
|
||||
|
||||
this.holes = [];
|
||||
|
||||
}
|
||||
|
||||
Shape.prototype = Object.assign( Object.create( PathPrototype ), {
|
||||
|
||||
constructor: Shape,
|
||||
|
||||
getPointsHoles: function ( divisions ) {
|
||||
|
||||
var holesPts = [];
|
||||
|
||||
for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
|
||||
|
||||
holesPts[ i ] = this.holes[ i ].getPoints( divisions );
|
||||
|
||||
}
|
||||
|
||||
return holesPts;
|
||||
|
||||
},
|
||||
|
||||
// Get points of shape and holes (keypoints based on segments parameter)
|
||||
|
||||
extractAllPoints: function ( divisions ) {
|
||||
|
||||
return {
|
||||
|
||||
shape: this.getPoints( divisions ),
|
||||
holes: this.getPointsHoles( divisions )
|
||||
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
extractPoints: function ( divisions ) {
|
||||
|
||||
return this.extractAllPoints( divisions );
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
export { Shape };
|
||||
281
node_modules/three/src/extras/core/ShapePath.js
generated
vendored
Normal file
281
node_modules/three/src/extras/core/ShapePath.js
generated
vendored
Normal file
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
* minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
|
||||
**/
|
||||
|
||||
import { Path } from './Path';
|
||||
import { Shape } from './Shape';
|
||||
import { ShapeUtils } from '../ShapeUtils';
|
||||
|
||||
|
||||
function ShapePath() {
|
||||
|
||||
this.subPaths = [];
|
||||
this.currentPath = null;
|
||||
|
||||
}
|
||||
|
||||
ShapePath.prototype = {
|
||||
|
||||
moveTo: function ( x, y ) {
|
||||
|
||||
this.currentPath = new Path();
|
||||
this.subPaths.push( this.currentPath );
|
||||
this.currentPath.moveTo( x, y );
|
||||
|
||||
},
|
||||
|
||||
lineTo: function ( x, y ) {
|
||||
|
||||
this.currentPath.lineTo( x, y );
|
||||
|
||||
},
|
||||
|
||||
quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
|
||||
|
||||
this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
|
||||
|
||||
},
|
||||
|
||||
bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
|
||||
|
||||
this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
|
||||
|
||||
},
|
||||
|
||||
splineThru: function ( pts ) {
|
||||
|
||||
this.currentPath.splineThru( pts );
|
||||
|
||||
},
|
||||
|
||||
toShapes: function ( isCCW, noHoles ) {
|
||||
|
||||
function toShapesNoHoles( inSubpaths ) {
|
||||
|
||||
var shapes = [];
|
||||
|
||||
for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
|
||||
|
||||
var tmpPath = inSubpaths[ i ];
|
||||
|
||||
var tmpShape = new Shape();
|
||||
tmpShape.curves = tmpPath.curves;
|
||||
|
||||
shapes.push( tmpShape );
|
||||
|
||||
}
|
||||
|
||||
return shapes;
|
||||
|
||||
}
|
||||
|
||||
function isPointInsidePolygon( inPt, inPolygon ) {
|
||||
|
||||
var polyLen = inPolygon.length;
|
||||
|
||||
// inPt on polygon contour => immediate success or
|
||||
// toggling of inside/outside at every single! intersection point of an edge
|
||||
// with the horizontal line through inPt, left of inPt
|
||||
// not counting lowerY endpoints of edges and whole edges on that line
|
||||
var inside = false;
|
||||
for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
|
||||
|
||||
var edgeLowPt = inPolygon[ p ];
|
||||
var edgeHighPt = inPolygon[ q ];
|
||||
|
||||
var edgeDx = edgeHighPt.x - edgeLowPt.x;
|
||||
var edgeDy = edgeHighPt.y - edgeLowPt.y;
|
||||
|
||||
if ( Math.abs( edgeDy ) > Number.EPSILON ) {
|
||||
|
||||
// not parallel
|
||||
if ( edgeDy < 0 ) {
|
||||
|
||||
edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
|
||||
edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
|
||||
|
||||
}
|
||||
if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
|
||||
|
||||
if ( inPt.y === edgeLowPt.y ) {
|
||||
|
||||
if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
|
||||
// continue; // no intersection or edgeLowPt => doesn't count !!!
|
||||
|
||||
} else {
|
||||
|
||||
var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
|
||||
if ( perpEdge === 0 ) return true; // inPt is on contour ?
|
||||
if ( perpEdge < 0 ) continue;
|
||||
inside = ! inside; // true intersection left of inPt
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// parallel or collinear
|
||||
if ( inPt.y !== edgeLowPt.y ) continue; // parallel
|
||||
// edge lies on the same horizontal line as inPt
|
||||
if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
|
||||
( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
|
||||
// continue;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return inside;
|
||||
|
||||
}
|
||||
|
||||
var isClockWise = ShapeUtils.isClockWise;
|
||||
|
||||
var subPaths = this.subPaths;
|
||||
if ( subPaths.length === 0 ) return [];
|
||||
|
||||
if ( noHoles === true ) return toShapesNoHoles( subPaths );
|
||||
|
||||
|
||||
var solid, tmpPath, tmpShape, shapes = [];
|
||||
|
||||
if ( subPaths.length === 1 ) {
|
||||
|
||||
tmpPath = subPaths[ 0 ];
|
||||
tmpShape = new Shape();
|
||||
tmpShape.curves = tmpPath.curves;
|
||||
shapes.push( tmpShape );
|
||||
return shapes;
|
||||
|
||||
}
|
||||
|
||||
var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
|
||||
holesFirst = isCCW ? ! holesFirst : holesFirst;
|
||||
|
||||
// console.log("Holes first", holesFirst);
|
||||
|
||||
var betterShapeHoles = [];
|
||||
var newShapes = [];
|
||||
var newShapeHoles = [];
|
||||
var mainIdx = 0;
|
||||
var tmpPoints;
|
||||
|
||||
newShapes[ mainIdx ] = undefined;
|
||||
newShapeHoles[ mainIdx ] = [];
|
||||
|
||||
for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
|
||||
|
||||
tmpPath = subPaths[ i ];
|
||||
tmpPoints = tmpPath.getPoints();
|
||||
solid = isClockWise( tmpPoints );
|
||||
solid = isCCW ? ! solid : solid;
|
||||
|
||||
if ( solid ) {
|
||||
|
||||
if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
|
||||
|
||||
newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
|
||||
newShapes[ mainIdx ].s.curves = tmpPath.curves;
|
||||
|
||||
if ( holesFirst ) mainIdx ++;
|
||||
newShapeHoles[ mainIdx ] = [];
|
||||
|
||||
//console.log('cw', i);
|
||||
|
||||
} else {
|
||||
|
||||
newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
|
||||
|
||||
//console.log('ccw', i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// only Holes? -> probably all Shapes with wrong orientation
|
||||
if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
|
||||
|
||||
|
||||
if ( newShapes.length > 1 ) {
|
||||
|
||||
var ambiguous = false;
|
||||
var toChange = [];
|
||||
|
||||
for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
|
||||
|
||||
betterShapeHoles[ sIdx ] = [];
|
||||
|
||||
}
|
||||
|
||||
for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
|
||||
|
||||
var sho = newShapeHoles[ sIdx ];
|
||||
|
||||
for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
|
||||
|
||||
var ho = sho[ hIdx ];
|
||||
var hole_unassigned = true;
|
||||
|
||||
for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
|
||||
|
||||
if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
|
||||
|
||||
if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
|
||||
if ( hole_unassigned ) {
|
||||
|
||||
hole_unassigned = false;
|
||||
betterShapeHoles[ s2Idx ].push( ho );
|
||||
|
||||
} else {
|
||||
|
||||
ambiguous = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if ( hole_unassigned ) {
|
||||
|
||||
betterShapeHoles[ sIdx ].push( ho );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// console.log("ambiguous: ", ambiguous);
|
||||
if ( toChange.length > 0 ) {
|
||||
|
||||
// console.log("to change: ", toChange);
|
||||
if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var tmpHoles;
|
||||
|
||||
for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
|
||||
|
||||
tmpShape = newShapes[ i ].s;
|
||||
shapes.push( tmpShape );
|
||||
tmpHoles = newShapeHoles[ i ];
|
||||
|
||||
for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
|
||||
|
||||
tmpShape.holes.push( tmpHoles[ j ].h );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//console.log("shape", shapes);
|
||||
|
||||
return shapes;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export { ShapePath };
|
||||
14
node_modules/three/src/extras/curves/ArcCurve.js
generated
vendored
Normal file
14
node_modules/three/src/extras/curves/ArcCurve.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { EllipseCurve } from './EllipseCurve';
|
||||
|
||||
|
||||
function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
||||
|
||||
EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
|
||||
|
||||
}
|
||||
|
||||
ArcCurve.prototype = Object.create( EllipseCurve.prototype );
|
||||
ArcCurve.prototype.constructor = ArcCurve;
|
||||
|
||||
|
||||
export { ArcCurve };
|
||||
178
node_modules/three/src/extras/curves/CatmullRomCurve3.js
generated
vendored
Normal file
178
node_modules/three/src/extras/curves/CatmullRomCurve3.js
generated
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
import { Vector3 } from '../../math/Vector3';
|
||||
import { Curve } from '../core/Curve';
|
||||
|
||||
/**
|
||||
* @author zz85 https://github.com/zz85
|
||||
*
|
||||
* Centripetal CatmullRom Curve - which is useful for avoiding
|
||||
* cusps and self-intersections in non-uniform catmull rom curves.
|
||||
* http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
|
||||
*
|
||||
* curve.type accepts centripetal(default), chordal and catmullrom
|
||||
* curve.tension is used for catmullrom which defaults to 0.5
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Based on an optimized c++ solution in
|
||||
- http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
|
||||
- http://ideone.com/NoEbVM
|
||||
|
||||
This CubicPoly class could be used for reusing some variables and calculations,
|
||||
but for three.js curve use, it could be possible inlined and flatten into a single function call
|
||||
which can be placed in CurveUtils.
|
||||
*/
|
||||
|
||||
function CubicPoly() {
|
||||
|
||||
var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
|
||||
|
||||
/*
|
||||
* Compute coefficients for a cubic polynomial
|
||||
* p(s) = c0 + c1*s + c2*s^2 + c3*s^3
|
||||
* such that
|
||||
* p(0) = x0, p(1) = x1
|
||||
* and
|
||||
* p'(0) = t0, p'(1) = t1.
|
||||
*/
|
||||
function init( x0, x1, t0, t1 ) {
|
||||
|
||||
c0 = x0;
|
||||
c1 = t0;
|
||||
c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
|
||||
c3 = 2 * x0 - 2 * x1 + t0 + t1;
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
initCatmullRom: function ( x0, x1, x2, x3, tension ) {
|
||||
|
||||
init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
|
||||
|
||||
},
|
||||
|
||||
initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
|
||||
|
||||
// compute tangents when parameterized in [t1,t2]
|
||||
var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
|
||||
var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
|
||||
|
||||
// rescale tangents for parametrization in [0,1]
|
||||
t1 *= dt1;
|
||||
t2 *= dt1;
|
||||
|
||||
init( x1, x2, t1, t2 );
|
||||
|
||||
},
|
||||
|
||||
calc: function ( t ) {
|
||||
|
||||
var t2 = t * t;
|
||||
var t3 = t2 * t;
|
||||
return c0 + c1 * t + c2 * t2 + c3 * t3;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var tmp = new Vector3();
|
||||
var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
|
||||
|
||||
function CatmullRomCurve3( p /* array of Vector3 */ ) {
|
||||
|
||||
this.points = p || [];
|
||||
this.closed = false;
|
||||
|
||||
}
|
||||
|
||||
CatmullRomCurve3.prototype = Object.create( Curve.prototype );
|
||||
CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
|
||||
|
||||
CatmullRomCurve3.prototype.getPoint = function ( t ) {
|
||||
|
||||
var points = this.points;
|
||||
var l = points.length;
|
||||
|
||||
if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
|
||||
|
||||
var point = ( l - ( this.closed ? 0 : 1 ) ) * t;
|
||||
var intPoint = Math.floor( point );
|
||||
var weight = point - intPoint;
|
||||
|
||||
if ( this.closed ) {
|
||||
|
||||
intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
|
||||
|
||||
} else if ( weight === 0 && intPoint === l - 1 ) {
|
||||
|
||||
intPoint = l - 2;
|
||||
weight = 1;
|
||||
|
||||
}
|
||||
|
||||
var p0, p1, p2, p3; // 4 points
|
||||
|
||||
if ( this.closed || intPoint > 0 ) {
|
||||
|
||||
p0 = points[ ( intPoint - 1 ) % l ];
|
||||
|
||||
} else {
|
||||
|
||||
// extrapolate first point
|
||||
tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
|
||||
p0 = tmp;
|
||||
|
||||
}
|
||||
|
||||
p1 = points[ intPoint % l ];
|
||||
p2 = points[ ( intPoint + 1 ) % l ];
|
||||
|
||||
if ( this.closed || intPoint + 2 < l ) {
|
||||
|
||||
p3 = points[ ( intPoint + 2 ) % l ];
|
||||
|
||||
} else {
|
||||
|
||||
// extrapolate last point
|
||||
tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
|
||||
p3 = tmp;
|
||||
|
||||
}
|
||||
|
||||
if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
|
||||
|
||||
// init Centripetal / Chordal Catmull-Rom
|
||||
var pow = this.type === 'chordal' ? 0.5 : 0.25;
|
||||
var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
|
||||
var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
|
||||
var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
|
||||
|
||||
// safety check for repeated points
|
||||
if ( dt1 < 1e-4 ) dt1 = 1.0;
|
||||
if ( dt0 < 1e-4 ) dt0 = dt1;
|
||||
if ( dt2 < 1e-4 ) dt2 = dt1;
|
||||
|
||||
px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
|
||||
py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
|
||||
pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
|
||||
|
||||
} else if ( this.type === 'catmullrom' ) {
|
||||
|
||||
var tension = this.tension !== undefined ? this.tension : 0.5;
|
||||
px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
|
||||
py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
|
||||
pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
|
||||
|
||||
}
|
||||
|
||||
return new Vector3( px.calc( weight ), py.calc( weight ), pz.calc( weight ) );
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { CatmullRomCurve3 };
|
||||
30
node_modules/three/src/extras/curves/CubicBezierCurve.js
generated
vendored
Normal file
30
node_modules/three/src/extras/curves/CubicBezierCurve.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Curve } from '../core/Curve';
|
||||
import { CubicBezier } from '../core/Interpolations';
|
||||
import { Vector2 } from '../../math/Vector2';
|
||||
|
||||
|
||||
function CubicBezierCurve( v0, v1, v2, v3 ) {
|
||||
|
||||
this.v0 = v0;
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
this.v3 = v3;
|
||||
|
||||
}
|
||||
|
||||
CubicBezierCurve.prototype = Object.create( Curve.prototype );
|
||||
CubicBezierCurve.prototype.constructor = CubicBezierCurve;
|
||||
|
||||
CubicBezierCurve.prototype.getPoint = function ( t ) {
|
||||
|
||||
var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
|
||||
|
||||
return new Vector2(
|
||||
CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
|
||||
CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { CubicBezierCurve };
|
||||
31
node_modules/three/src/extras/curves/CubicBezierCurve3.js
generated
vendored
Normal file
31
node_modules/three/src/extras/curves/CubicBezierCurve3.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Curve } from '../core/Curve';
|
||||
import { CubicBezier } from '../core/Interpolations';
|
||||
import { Vector3 } from '../../math/Vector3';
|
||||
|
||||
|
||||
function CubicBezierCurve3( v0, v1, v2, v3 ) {
|
||||
|
||||
this.v0 = v0;
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
this.v3 = v3;
|
||||
|
||||
}
|
||||
|
||||
CubicBezierCurve3.prototype = Object.create( Curve.prototype );
|
||||
CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
|
||||
|
||||
CubicBezierCurve3.prototype.getPoint = function ( t ) {
|
||||
|
||||
var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
|
||||
|
||||
return new Vector3(
|
||||
CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
|
||||
CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
|
||||
CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { CubicBezierCurve3 };
|
||||
88
node_modules/three/src/extras/curves/EllipseCurve.js
generated
vendored
Normal file
88
node_modules/three/src/extras/curves/EllipseCurve.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
import { Curve } from '../core/Curve';
|
||||
import { Vector2 } from '../../math/Vector2';
|
||||
|
||||
|
||||
function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
||||
|
||||
this.aX = aX;
|
||||
this.aY = aY;
|
||||
|
||||
this.xRadius = xRadius;
|
||||
this.yRadius = yRadius;
|
||||
|
||||
this.aStartAngle = aStartAngle;
|
||||
this.aEndAngle = aEndAngle;
|
||||
|
||||
this.aClockwise = aClockwise;
|
||||
|
||||
this.aRotation = aRotation || 0;
|
||||
|
||||
}
|
||||
|
||||
EllipseCurve.prototype = Object.create( Curve.prototype );
|
||||
EllipseCurve.prototype.constructor = EllipseCurve;
|
||||
|
||||
EllipseCurve.prototype.isEllipseCurve = true;
|
||||
|
||||
EllipseCurve.prototype.getPoint = function ( t ) {
|
||||
|
||||
var twoPi = Math.PI * 2;
|
||||
var deltaAngle = this.aEndAngle - this.aStartAngle;
|
||||
var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
|
||||
|
||||
// ensures that deltaAngle is 0 .. 2 PI
|
||||
while ( deltaAngle < 0 ) deltaAngle += twoPi;
|
||||
while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
|
||||
|
||||
if ( deltaAngle < Number.EPSILON ) {
|
||||
|
||||
if ( samePoints ) {
|
||||
|
||||
deltaAngle = 0;
|
||||
|
||||
} else {
|
||||
|
||||
deltaAngle = twoPi;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( this.aClockwise === true && ! samePoints ) {
|
||||
|
||||
if ( deltaAngle === twoPi ) {
|
||||
|
||||
deltaAngle = - twoPi;
|
||||
|
||||
} else {
|
||||
|
||||
deltaAngle = deltaAngle - twoPi;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var angle = this.aStartAngle + t * deltaAngle;
|
||||
var x = this.aX + this.xRadius * Math.cos( angle );
|
||||
var y = this.aY + this.yRadius * Math.sin( angle );
|
||||
|
||||
if ( this.aRotation !== 0 ) {
|
||||
|
||||
var cos = Math.cos( this.aRotation );
|
||||
var sin = Math.sin( this.aRotation );
|
||||
|
||||
var tx = x - this.aX;
|
||||
var ty = y - this.aY;
|
||||
|
||||
// Rotate the point about the center of the ellipse.
|
||||
x = tx * cos - ty * sin + this.aX;
|
||||
y = tx * sin + ty * cos + this.aY;
|
||||
|
||||
}
|
||||
|
||||
return new Vector2( x, y );
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { EllipseCurve };
|
||||
48
node_modules/three/src/extras/curves/LineCurve.js
generated
vendored
Normal file
48
node_modules/three/src/extras/curves/LineCurve.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Curve } from '../core/Curve';
|
||||
|
||||
|
||||
function LineCurve( v1, v2 ) {
|
||||
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
|
||||
}
|
||||
|
||||
LineCurve.prototype = Object.create( Curve.prototype );
|
||||
LineCurve.prototype.constructor = LineCurve;
|
||||
|
||||
LineCurve.prototype.isLineCurve = true;
|
||||
|
||||
LineCurve.prototype.getPoint = function ( t ) {
|
||||
|
||||
if ( t === 1 ) {
|
||||
|
||||
return this.v2.clone();
|
||||
|
||||
}
|
||||
|
||||
var point = this.v2.clone().sub( this.v1 );
|
||||
point.multiplyScalar( t ).add( this.v1 );
|
||||
|
||||
return point;
|
||||
|
||||
};
|
||||
|
||||
// Line curve is linear, so we can overwrite default getPointAt
|
||||
|
||||
LineCurve.prototype.getPointAt = function ( u ) {
|
||||
|
||||
return this.getPoint( u );
|
||||
|
||||
};
|
||||
|
||||
LineCurve.prototype.getTangent = function ( t ) {
|
||||
|
||||
var tangent = this.v2.clone().sub( this.v1 );
|
||||
|
||||
return tangent.normalize();
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { LineCurve };
|
||||
34
node_modules/three/src/extras/curves/LineCurve3.js
generated
vendored
Normal file
34
node_modules/three/src/extras/curves/LineCurve3.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Vector3 } from '../../math/Vector3';
|
||||
import { Curve } from '../core/Curve';
|
||||
|
||||
|
||||
function LineCurve3( v1, v2 ) {
|
||||
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
|
||||
}
|
||||
|
||||
LineCurve3.prototype = Object.create( Curve.prototype );
|
||||
LineCurve3.prototype.constructor = LineCurve3;
|
||||
|
||||
LineCurve3.prototype.getPoint = function ( t ) {
|
||||
|
||||
if ( t === 1 ) {
|
||||
|
||||
return this.v2.clone();
|
||||
|
||||
}
|
||||
|
||||
var vector = new Vector3();
|
||||
|
||||
vector.subVectors( this.v2, this.v1 ); // diff
|
||||
vector.multiplyScalar( t );
|
||||
vector.add( this.v1 );
|
||||
|
||||
return vector;
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { LineCurve3 };
|
||||
29
node_modules/three/src/extras/curves/QuadraticBezierCurve.js
generated
vendored
Normal file
29
node_modules/three/src/extras/curves/QuadraticBezierCurve.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Curve } from '../core/Curve';
|
||||
import { QuadraticBezier } from '../core/Interpolations';
|
||||
import { Vector2 } from '../../math/Vector2';
|
||||
|
||||
|
||||
function QuadraticBezierCurve( v0, v1, v2 ) {
|
||||
|
||||
this.v0 = v0;
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
|
||||
}
|
||||
|
||||
QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
|
||||
QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
|
||||
|
||||
QuadraticBezierCurve.prototype.getPoint = function ( t ) {
|
||||
|
||||
var v0 = this.v0, v1 = this.v1, v2 = this.v2;
|
||||
|
||||
return new Vector2(
|
||||
QuadraticBezier( t, v0.x, v1.x, v2.x ),
|
||||
QuadraticBezier( t, v0.y, v1.y, v2.y )
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { QuadraticBezierCurve };
|
||||
30
node_modules/three/src/extras/curves/QuadraticBezierCurve3.js
generated
vendored
Normal file
30
node_modules/three/src/extras/curves/QuadraticBezierCurve3.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Curve } from '../core/Curve';
|
||||
import { QuadraticBezier } from '../core/Interpolations';
|
||||
import { Vector3 } from '../../math/Vector3';
|
||||
|
||||
|
||||
function QuadraticBezierCurve3( v0, v1, v2 ) {
|
||||
|
||||
this.v0 = v0;
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
|
||||
}
|
||||
|
||||
QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
|
||||
QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
|
||||
|
||||
QuadraticBezierCurve3.prototype.getPoint = function ( t ) {
|
||||
|
||||
var v0 = this.v0, v1 = this.v1, v2 = this.v2;
|
||||
|
||||
return new Vector3(
|
||||
QuadraticBezier( t, v0.x, v1.x, v2.x ),
|
||||
QuadraticBezier( t, v0.y, v1.y, v2.y ),
|
||||
QuadraticBezier( t, v0.z, v1.z, v2.z )
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { QuadraticBezierCurve3 };
|
||||
37
node_modules/three/src/extras/curves/SplineCurve.js
generated
vendored
Normal file
37
node_modules/three/src/extras/curves/SplineCurve.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Curve } from '../core/Curve';
|
||||
import { CatmullRom } from '../core/Interpolations';
|
||||
import { Vector2 } from '../../math/Vector2';
|
||||
|
||||
|
||||
function SplineCurve( points /* array of Vector2 */ ) {
|
||||
|
||||
this.points = ( points === undefined ) ? [] : points;
|
||||
|
||||
}
|
||||
|
||||
SplineCurve.prototype = Object.create( Curve.prototype );
|
||||
SplineCurve.prototype.constructor = SplineCurve;
|
||||
|
||||
SplineCurve.prototype.isSplineCurve = true;
|
||||
|
||||
SplineCurve.prototype.getPoint = function ( t ) {
|
||||
|
||||
var points = this.points;
|
||||
var point = ( points.length - 1 ) * t;
|
||||
|
||||
var intPoint = Math.floor( point );
|
||||
var weight = point - intPoint;
|
||||
|
||||
var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
|
||||
var point1 = points[ intPoint ];
|
||||
var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
|
||||
var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
|
||||
|
||||
return new Vector2(
|
||||
CatmullRom( weight, point0.x, point1.x, point2.x, point3.x ),
|
||||
CatmullRom( weight, point0.y, point1.y, point2.y, point3.y )
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
export { SplineCurve };
|
||||
22
node_modules/three/src/extras/objects/ImmediateRenderObject.js
generated
vendored
Normal file
22
node_modules/three/src/extras/objects/ImmediateRenderObject.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Object3D } from '../../core/Object3D';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
function ImmediateRenderObject( material ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.material = material;
|
||||
this.render = function ( renderCallback ) {};
|
||||
|
||||
}
|
||||
|
||||
ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
|
||||
ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
|
||||
|
||||
ImmediateRenderObject.prototype.isImmediateRenderObject = true;
|
||||
|
||||
|
||||
export { ImmediateRenderObject };
|
||||
321
node_modules/three/src/extras/objects/MorphBlendMesh.js
generated
vendored
Normal file
321
node_modules/three/src/extras/objects/MorphBlendMesh.js
generated
vendored
Normal file
@@ -0,0 +1,321 @@
|
||||
import { Mesh } from '../../objects/Mesh';
|
||||
import { _Math } from '../../math/Math';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
|
||||
function MorphBlendMesh( geometry, material ) {
|
||||
|
||||
Mesh.call( this, geometry, material );
|
||||
|
||||
this.animationsMap = {};
|
||||
this.animationsList = [];
|
||||
|
||||
// prepare default animation
|
||||
// (all frames played together in 1 second)
|
||||
|
||||
var numFrames = this.geometry.morphTargets.length;
|
||||
|
||||
var name = "__default";
|
||||
|
||||
var startFrame = 0;
|
||||
var endFrame = numFrames - 1;
|
||||
|
||||
var fps = numFrames / 1;
|
||||
|
||||
this.createAnimation( name, startFrame, endFrame, fps );
|
||||
this.setAnimationWeight( name, 1 );
|
||||
|
||||
}
|
||||
|
||||
MorphBlendMesh.prototype = Object.create( Mesh.prototype );
|
||||
MorphBlendMesh.prototype.constructor = MorphBlendMesh;
|
||||
|
||||
MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
|
||||
|
||||
var animation = {
|
||||
|
||||
start: start,
|
||||
end: end,
|
||||
|
||||
length: end - start + 1,
|
||||
|
||||
fps: fps,
|
||||
duration: ( end - start ) / fps,
|
||||
|
||||
lastFrame: 0,
|
||||
currentFrame: 0,
|
||||
|
||||
active: false,
|
||||
|
||||
time: 0,
|
||||
direction: 1,
|
||||
weight: 1,
|
||||
|
||||
directionBackwards: false,
|
||||
mirroredLoop: false
|
||||
|
||||
};
|
||||
|
||||
this.animationsMap[ name ] = animation;
|
||||
this.animationsList.push( animation );
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
|
||||
|
||||
var pattern = /([a-z]+)_?(\d+)/i;
|
||||
|
||||
var firstAnimation, frameRanges = {};
|
||||
|
||||
var geometry = this.geometry;
|
||||
|
||||
for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
|
||||
|
||||
var morph = geometry.morphTargets[ i ];
|
||||
var chunks = morph.name.match( pattern );
|
||||
|
||||
if ( chunks && chunks.length > 1 ) {
|
||||
|
||||
var name = chunks[ 1 ];
|
||||
|
||||
if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
|
||||
|
||||
var range = frameRanges[ name ];
|
||||
|
||||
if ( i < range.start ) range.start = i;
|
||||
if ( i > range.end ) range.end = i;
|
||||
|
||||
if ( ! firstAnimation ) firstAnimation = name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for ( var name in frameRanges ) {
|
||||
|
||||
var range = frameRanges[ name ];
|
||||
this.createAnimation( name, range.start, range.end, fps );
|
||||
|
||||
}
|
||||
|
||||
this.firstAnimation = firstAnimation;
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
animation.direction = 1;
|
||||
animation.directionBackwards = false;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
animation.direction = - 1;
|
||||
animation.directionBackwards = true;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
animation.fps = fps;
|
||||
animation.duration = ( animation.end - animation.start ) / animation.fps;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
animation.duration = duration;
|
||||
animation.fps = ( animation.end - animation.start ) / animation.duration;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
animation.weight = weight;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
animation.time = time;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
|
||||
|
||||
var time = 0;
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
time = animation.time;
|
||||
|
||||
}
|
||||
|
||||
return time;
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
|
||||
|
||||
var duration = - 1;
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
duration = animation.duration;
|
||||
|
||||
}
|
||||
|
||||
return duration;
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.playAnimation = function ( name ) {
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
animation.time = 0;
|
||||
animation.active = true;
|
||||
|
||||
} else {
|
||||
|
||||
console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.stopAnimation = function ( name ) {
|
||||
|
||||
var animation = this.animationsMap[ name ];
|
||||
|
||||
if ( animation ) {
|
||||
|
||||
animation.active = false;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MorphBlendMesh.prototype.update = function ( delta ) {
|
||||
|
||||
for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
|
||||
|
||||
var animation = this.animationsList[ i ];
|
||||
|
||||
if ( ! animation.active ) continue;
|
||||
|
||||
var frameTime = animation.duration / animation.length;
|
||||
|
||||
animation.time += animation.direction * delta;
|
||||
|
||||
if ( animation.mirroredLoop ) {
|
||||
|
||||
if ( animation.time > animation.duration || animation.time < 0 ) {
|
||||
|
||||
animation.direction *= - 1;
|
||||
|
||||
if ( animation.time > animation.duration ) {
|
||||
|
||||
animation.time = animation.duration;
|
||||
animation.directionBackwards = true;
|
||||
|
||||
}
|
||||
|
||||
if ( animation.time < 0 ) {
|
||||
|
||||
animation.time = 0;
|
||||
animation.directionBackwards = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
animation.time = animation.time % animation.duration;
|
||||
|
||||
if ( animation.time < 0 ) animation.time += animation.duration;
|
||||
|
||||
}
|
||||
|
||||
var keyframe = animation.start + _Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
|
||||
var weight = animation.weight;
|
||||
|
||||
if ( keyframe !== animation.currentFrame ) {
|
||||
|
||||
this.morphTargetInfluences[ animation.lastFrame ] = 0;
|
||||
this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
|
||||
|
||||
this.morphTargetInfluences[ keyframe ] = 0;
|
||||
|
||||
animation.lastFrame = animation.currentFrame;
|
||||
animation.currentFrame = keyframe;
|
||||
|
||||
}
|
||||
|
||||
var mix = ( animation.time % frameTime ) / frameTime;
|
||||
|
||||
if ( animation.directionBackwards ) mix = 1 - mix;
|
||||
|
||||
if ( animation.currentFrame !== animation.lastFrame ) {
|
||||
|
||||
this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
|
||||
this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
|
||||
|
||||
} else {
|
||||
|
||||
this.morphTargetInfluences[ animation.currentFrame ] = weight;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { MorphBlendMesh };
|
||||
199
node_modules/three/src/geometries/BoxGeometry.js
generated
vendored
Normal file
199
node_modules/three/src/geometries/BoxGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'BoxGeometry';
|
||||
|
||||
this.parameters = {
|
||||
width: width,
|
||||
height: height,
|
||||
depth: depth,
|
||||
widthSegments: widthSegments,
|
||||
heightSegments: heightSegments,
|
||||
depthSegments: depthSegments
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
BoxGeometry.prototype = Object.create( Geometry.prototype );
|
||||
BoxGeometry.prototype.constructor = BoxGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
|
||||
function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'BoxBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
width: width,
|
||||
height: height,
|
||||
depth: depth,
|
||||
widthSegments: widthSegments,
|
||||
heightSegments: heightSegments,
|
||||
depthSegments: depthSegments
|
||||
};
|
||||
|
||||
var scope = this;
|
||||
|
||||
// segments
|
||||
|
||||
widthSegments = Math.floor( widthSegments ) || 1;
|
||||
heightSegments = Math.floor( heightSegments ) || 1;
|
||||
depthSegments = Math.floor( depthSegments ) || 1;
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
var numberOfVertices = 0;
|
||||
var groupStart = 0;
|
||||
|
||||
// build each side of the box geometry
|
||||
|
||||
buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
|
||||
buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
|
||||
buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
|
||||
buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
|
||||
buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
|
||||
buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
|
||||
|
||||
var segmentWidth = width / gridX;
|
||||
var segmentHeight = height / gridY;
|
||||
|
||||
var widthHalf = width / 2;
|
||||
var heightHalf = height / 2;
|
||||
var depthHalf = depth / 2;
|
||||
|
||||
var gridX1 = gridX + 1;
|
||||
var gridY1 = gridY + 1;
|
||||
|
||||
var vertexCounter = 0;
|
||||
var groupCount = 0;
|
||||
|
||||
var ix, iy;
|
||||
|
||||
var vector = new Vector3();
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( iy = 0; iy < gridY1; iy ++ ) {
|
||||
|
||||
var y = iy * segmentHeight - heightHalf;
|
||||
|
||||
for ( ix = 0; ix < gridX1; ix ++ ) {
|
||||
|
||||
var x = ix * segmentWidth - widthHalf;
|
||||
|
||||
// set values to correct vector component
|
||||
|
||||
vector[ u ] = x * udir;
|
||||
vector[ v ] = y * vdir;
|
||||
vector[ w ] = depthHalf;
|
||||
|
||||
// now apply vector to vertex buffer
|
||||
|
||||
vertices.push( vector.x, vector.y, vector.z );
|
||||
|
||||
// set values to correct vector component
|
||||
|
||||
vector[ u ] = 0;
|
||||
vector[ v ] = 0;
|
||||
vector[ w ] = depth > 0 ? 1 : - 1;
|
||||
|
||||
// now apply vector to normal buffer
|
||||
|
||||
normals.push( vector.x, vector.y, vector.z );
|
||||
|
||||
// uvs
|
||||
|
||||
uvs.push( ix / gridX );
|
||||
uvs.push( 1 - ( iy / gridY ) );
|
||||
|
||||
// counters
|
||||
|
||||
vertexCounter += 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// indices
|
||||
|
||||
// 1. you need three indices to draw a single face
|
||||
// 2. a single segment consists of two faces
|
||||
// 3. so we need to generate six (2*3) indices per segment
|
||||
|
||||
for ( iy = 0; iy < gridY; iy ++ ) {
|
||||
|
||||
for ( ix = 0; ix < gridX; ix ++ ) {
|
||||
|
||||
var a = numberOfVertices + ix + gridX1 * iy;
|
||||
var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
|
||||
var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
|
||||
var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
// increase counter
|
||||
|
||||
groupCount += 6;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// add a group to the geometry. this will ensure multi material support
|
||||
|
||||
scope.addGroup( groupStart, groupCount, materialIndex );
|
||||
|
||||
// calculate new start value for groups
|
||||
|
||||
groupStart += groupCount;
|
||||
|
||||
// update total number of vertices
|
||||
|
||||
numberOfVertices += vertexCounter;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
|
||||
|
||||
export { BoxGeometry, BoxBufferGeometry };
|
||||
119
node_modules/three/src/geometries/CircleGeometry.js
generated
vendored
Normal file
119
node_modules/three/src/geometries/CircleGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* @author hughes
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'CircleGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
segments: segments,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
|
||||
|
||||
}
|
||||
|
||||
CircleGeometry.prototype = Object.create( Geometry.prototype );
|
||||
CircleGeometry.prototype.constructor = CircleGeometry;
|
||||
|
||||
/**
|
||||
* @author benaadams / https://twitter.com/ben_a_adams
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
|
||||
function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'CircleBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
segments: segments,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
radius = radius || 50;
|
||||
segments = segments !== undefined ? Math.max( 3, segments ) : 8;
|
||||
|
||||
thetaStart = thetaStart !== undefined ? thetaStart : 0;
|
||||
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
var i, s;
|
||||
var vertex = new Vector3();
|
||||
var uv = new Vector2();
|
||||
|
||||
// center point
|
||||
|
||||
vertices.push( 0, 0, 0 );
|
||||
normals.push( 0, 0, 1 );
|
||||
uvs.push( 0.5, 0.5 );
|
||||
|
||||
for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
|
||||
|
||||
var segment = thetaStart + s / segments * thetaLength;
|
||||
|
||||
// vertex
|
||||
|
||||
vertex.x = radius * Math.cos( segment );
|
||||
vertex.y = radius * Math.sin( segment );
|
||||
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
// normal
|
||||
|
||||
normals.push( 0, 0, 1 );
|
||||
|
||||
// uvs
|
||||
|
||||
uv.x = ( vertices[ i ] / radius + 1 ) / 2;
|
||||
uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
|
||||
|
||||
uvs.push( uv.x, uv.y );
|
||||
|
||||
}
|
||||
|
||||
// indices
|
||||
|
||||
for ( i = 1; i <= segments; i ++ ) {
|
||||
|
||||
indices.push( i, i + 1, 0 );
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
|
||||
|
||||
export { CircleGeometry, CircleBufferGeometry };
|
||||
55
node_modules/three/src/geometries/ConeGeometry.js
generated
vendored
Normal file
55
node_modules/three/src/geometries/ConeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @author abelnation / http://github.com/abelnation
|
||||
*/
|
||||
|
||||
import { CylinderGeometry } from './CylinderGeometry';
|
||||
|
||||
function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
|
||||
|
||||
CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
|
||||
|
||||
this.type = 'ConeGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
height: height,
|
||||
radialSegments: radialSegments,
|
||||
heightSegments: heightSegments,
|
||||
openEnded: openEnded,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
|
||||
ConeGeometry.prototype.constructor = ConeGeometry;
|
||||
|
||||
/**
|
||||
* @author: abelnation / http://github.com/abelnation
|
||||
*/
|
||||
|
||||
import { CylinderBufferGeometry } from './CylinderGeometry';
|
||||
|
||||
function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
|
||||
|
||||
CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
|
||||
|
||||
this.type = 'ConeBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
height: height,
|
||||
radialSegments: radialSegments,
|
||||
heightSegments: heightSegments,
|
||||
openEnded: openEnded,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
|
||||
ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
|
||||
|
||||
export { ConeGeometry, ConeBufferGeometry };
|
||||
316
node_modules/three/src/geometries/CylinderGeometry.js
generated
vendored
Normal file
316
node_modules/three/src/geometries/CylinderGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,316 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'CylinderGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radiusTop: radiusTop,
|
||||
radiusBottom: radiusBottom,
|
||||
height: height,
|
||||
radialSegments: radialSegments,
|
||||
heightSegments: heightSegments,
|
||||
openEnded: openEnded,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
CylinderGeometry.prototype = Object.create( Geometry.prototype );
|
||||
CylinderGeometry.prototype.constructor = CylinderGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
|
||||
function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'CylinderBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radiusTop: radiusTop,
|
||||
radiusBottom: radiusBottom,
|
||||
height: height,
|
||||
radialSegments: radialSegments,
|
||||
heightSegments: heightSegments,
|
||||
openEnded: openEnded,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
var scope = this;
|
||||
|
||||
radiusTop = radiusTop !== undefined ? radiusTop : 20;
|
||||
radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
|
||||
height = height !== undefined ? height : 100;
|
||||
|
||||
radialSegments = Math.floor( radialSegments ) || 8;
|
||||
heightSegments = Math.floor( heightSegments ) || 1;
|
||||
|
||||
openEnded = openEnded !== undefined ? openEnded : false;
|
||||
thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
|
||||
thetaLength = thetaLength !== undefined ? thetaLength : 2.0 * Math.PI;
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
var index = 0;
|
||||
var indexOffset = 0;
|
||||
var indexArray = [];
|
||||
var halfHeight = height / 2;
|
||||
var groupStart = 0;
|
||||
|
||||
// generate geometry
|
||||
|
||||
generateTorso();
|
||||
|
||||
if ( openEnded === false ) {
|
||||
|
||||
if ( radiusTop > 0 ) generateCap( true );
|
||||
if ( radiusBottom > 0 ) generateCap( false );
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
function generateTorso() {
|
||||
|
||||
var x, y;
|
||||
var normal = new Vector3();
|
||||
var vertex = new Vector3();
|
||||
|
||||
var groupCount = 0;
|
||||
|
||||
// this will be used to calculate the normal
|
||||
var slope = ( radiusBottom - radiusTop ) / height;
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( y = 0; y <= heightSegments; y ++ ) {
|
||||
|
||||
var indexRow = [];
|
||||
|
||||
var v = y / heightSegments;
|
||||
|
||||
// calculate the radius of the current row
|
||||
|
||||
var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
|
||||
|
||||
for ( x = 0; x <= radialSegments; x ++ ) {
|
||||
|
||||
var u = x / radialSegments;
|
||||
|
||||
var theta = u * thetaLength + thetaStart;
|
||||
|
||||
var sinTheta = Math.sin( theta );
|
||||
var cosTheta = Math.cos( theta );
|
||||
|
||||
// vertex
|
||||
|
||||
vertex.x = radius * sinTheta;
|
||||
vertex.y = - v * height + halfHeight;
|
||||
vertex.z = radius * cosTheta;
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
// normal
|
||||
|
||||
normal.set( sinTheta, slope, cosTheta ).normalize();
|
||||
normals.push( normal.x, normal.y, normal.z );
|
||||
|
||||
// uv
|
||||
|
||||
uvs.push( u, 1 - v );
|
||||
|
||||
// save index of vertex in respective row
|
||||
|
||||
indexRow.push( index ++ );
|
||||
|
||||
}
|
||||
|
||||
// now save vertices of the row in our index array
|
||||
|
||||
indexArray.push( indexRow );
|
||||
|
||||
}
|
||||
|
||||
// generate indices
|
||||
|
||||
for ( x = 0; x < radialSegments; x ++ ) {
|
||||
|
||||
for ( y = 0; y < heightSegments; y ++ ) {
|
||||
|
||||
// we use the index array to access the correct indices
|
||||
|
||||
var a = indexArray[ y ][ x ];
|
||||
var b = indexArray[ y + 1 ][ x ];
|
||||
var c = indexArray[ y + 1 ][ x + 1 ];
|
||||
var d = indexArray[ y ][ x + 1 ];
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
// update group counter
|
||||
|
||||
groupCount += 6;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// add a group to the geometry. this will ensure multi material support
|
||||
|
||||
scope.addGroup( groupStart, groupCount, 0 );
|
||||
|
||||
// calculate new start value for groups
|
||||
|
||||
groupStart += groupCount;
|
||||
|
||||
}
|
||||
|
||||
function generateCap( top ) {
|
||||
|
||||
var x, centerIndexStart, centerIndexEnd;
|
||||
|
||||
var uv = new Vector2();
|
||||
var vertex = new Vector3();
|
||||
|
||||
var groupCount = 0;
|
||||
|
||||
var radius = ( top === true ) ? radiusTop : radiusBottom;
|
||||
var sign = ( top === true ) ? 1 : - 1;
|
||||
|
||||
// save the index of the first center vertex
|
||||
centerIndexStart = index;
|
||||
|
||||
// first we generate the center vertex data of the cap.
|
||||
// because the geometry needs one set of uvs per face,
|
||||
// we must generate a center vertex per face/segment
|
||||
|
||||
for ( x = 1; x <= radialSegments; x ++ ) {
|
||||
|
||||
// vertex
|
||||
|
||||
vertices.push( 0, halfHeight * sign, 0 );
|
||||
|
||||
// normal
|
||||
|
||||
normals.push( 0, sign, 0 );
|
||||
|
||||
// uv
|
||||
|
||||
uvs.push( 0.5, 0.5 );
|
||||
|
||||
// increase index
|
||||
|
||||
index ++;
|
||||
|
||||
}
|
||||
|
||||
// save the index of the last center vertex
|
||||
|
||||
centerIndexEnd = index;
|
||||
|
||||
// now we generate the surrounding vertices, normals and uvs
|
||||
|
||||
for ( x = 0; x <= radialSegments; x ++ ) {
|
||||
|
||||
var u = x / radialSegments;
|
||||
var theta = u * thetaLength + thetaStart;
|
||||
|
||||
var cosTheta = Math.cos( theta );
|
||||
var sinTheta = Math.sin( theta );
|
||||
|
||||
// vertex
|
||||
|
||||
vertex.x = radius * sinTheta;
|
||||
vertex.y = halfHeight * sign;
|
||||
vertex.z = radius * cosTheta;
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
// normal
|
||||
|
||||
normals.push( 0, sign, 0 );
|
||||
|
||||
// uv
|
||||
|
||||
uv.x = ( cosTheta * 0.5 ) + 0.5;
|
||||
uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
|
||||
uvs.push( uv.x, uv.y );
|
||||
|
||||
// increase index
|
||||
|
||||
index ++;
|
||||
|
||||
}
|
||||
|
||||
// generate indices
|
||||
|
||||
for ( x = 0; x < radialSegments; x ++ ) {
|
||||
|
||||
var c = centerIndexStart + x;
|
||||
var i = centerIndexEnd + x;
|
||||
|
||||
if ( top === true ) {
|
||||
|
||||
// face top
|
||||
|
||||
indices.push( i, i + 1, c );
|
||||
|
||||
} else {
|
||||
|
||||
// face bottom
|
||||
|
||||
indices.push( i + 1, i, c );
|
||||
|
||||
}
|
||||
|
||||
groupCount += 3;
|
||||
|
||||
}
|
||||
|
||||
// add a group to the geometry. this will ensure multi material support
|
||||
|
||||
scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
|
||||
|
||||
// calculate new start value for groups
|
||||
|
||||
groupStart += groupCount;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
|
||||
|
||||
export { CylinderGeometry, CylinderBufferGeometry };
|
||||
87
node_modules/three/src/geometries/DodecahedronGeometry.js
generated
vendored
Normal file
87
node_modules/three/src/geometries/DodecahedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* @author Abe Pazos / https://hamoid.com
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function DodecahedronGeometry( radius, detail ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'DodecahedronGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
|
||||
DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { PolyhedronBufferGeometry } from './PolyhedronGeometry';
|
||||
|
||||
function DodecahedronBufferGeometry( radius, detail ) {
|
||||
|
||||
var t = ( 1 + Math.sqrt( 5 ) ) / 2;
|
||||
var r = 1 / t;
|
||||
|
||||
var vertices = [
|
||||
|
||||
// (±1, ±1, ±1)
|
||||
- 1, - 1, - 1, - 1, - 1, 1,
|
||||
- 1, 1, - 1, - 1, 1, 1,
|
||||
1, - 1, - 1, 1, - 1, 1,
|
||||
1, 1, - 1, 1, 1, 1,
|
||||
|
||||
// (0, ±1/φ, ±φ)
|
||||
0, - r, - t, 0, - r, t,
|
||||
0, r, - t, 0, r, t,
|
||||
|
||||
// (±1/φ, ±φ, 0)
|
||||
- r, - t, 0, - r, t, 0,
|
||||
r, - t, 0, r, t, 0,
|
||||
|
||||
// (±φ, 0, ±1/φ)
|
||||
- t, 0, - r, t, 0, - r,
|
||||
- t, 0, r, t, 0, r
|
||||
];
|
||||
|
||||
var indices = [
|
||||
3, 11, 7, 3, 7, 15, 3, 15, 13,
|
||||
7, 19, 17, 7, 17, 6, 7, 6, 15,
|
||||
17, 4, 8, 17, 8, 10, 17, 10, 6,
|
||||
8, 0, 16, 8, 16, 2, 8, 2, 10,
|
||||
0, 12, 1, 0, 1, 18, 0, 18, 16,
|
||||
6, 10, 2, 6, 2, 13, 6, 13, 15,
|
||||
2, 16, 18, 2, 18, 3, 2, 3, 13,
|
||||
18, 1, 9, 18, 9, 11, 18, 11, 3,
|
||||
4, 14, 12, 4, 12, 0, 4, 0, 8,
|
||||
11, 9, 5, 11, 5, 19, 11, 19, 7,
|
||||
19, 5, 14, 19, 14, 4, 19, 4, 17,
|
||||
1, 12, 14, 1, 14, 5, 1, 5, 9
|
||||
];
|
||||
|
||||
PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
|
||||
|
||||
this.type = 'DodecahedronBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
|
||||
DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
|
||||
|
||||
export { DodecahedronGeometry, DodecahedronBufferGeometry };
|
||||
120
node_modules/three/src/geometries/EdgesGeometry.js
generated
vendored
Normal file
120
node_modules/three/src/geometries/EdgesGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { Geometry } from '../core/Geometry';
|
||||
import { _Math } from '../math/Math';
|
||||
|
||||
/**
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
function EdgesGeometry( geometry, thresholdAngle ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'EdgesGeometry';
|
||||
|
||||
this.parameters = {
|
||||
thresholdAngle: thresholdAngle
|
||||
};
|
||||
|
||||
thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
|
||||
|
||||
// buffer
|
||||
|
||||
var vertices = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
|
||||
var edge = [ 0, 0 ], edges = {};
|
||||
var key, keys = [ 'a', 'b', 'c' ];
|
||||
|
||||
// prepare source geometry
|
||||
|
||||
var geometry2;
|
||||
|
||||
if ( geometry.isBufferGeometry ) {
|
||||
|
||||
geometry2 = new Geometry();
|
||||
geometry2.fromBufferGeometry( geometry );
|
||||
|
||||
} else {
|
||||
|
||||
geometry2 = geometry.clone();
|
||||
|
||||
}
|
||||
|
||||
geometry2.mergeVertices();
|
||||
geometry2.computeFaceNormals();
|
||||
|
||||
var sourceVertices = geometry2.vertices;
|
||||
var faces = geometry2.faces;
|
||||
|
||||
// now create a data structure where each entry represents an edge with its adjoining faces
|
||||
|
||||
for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
|
||||
for ( var j = 0; j < 3; j ++ ) {
|
||||
|
||||
edge[ 0 ] = face[ keys[ j ] ];
|
||||
edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
|
||||
edge.sort( sortFunction );
|
||||
|
||||
key = edge.toString();
|
||||
|
||||
if ( edges[ key ] === undefined ) {
|
||||
|
||||
edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
|
||||
|
||||
} else {
|
||||
|
||||
edges[ key ].face2 = i;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// generate vertices
|
||||
|
||||
for ( key in edges ) {
|
||||
|
||||
var e = edges[ key ];
|
||||
|
||||
// an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
|
||||
|
||||
if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
|
||||
|
||||
var vertex = sourceVertices[ e.index1 ];
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
vertex = sourceVertices[ e.index2 ];
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
|
||||
// custom array sort function
|
||||
|
||||
function sortFunction( a, b ) {
|
||||
|
||||
return a - b;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
EdgesGeometry.prototype.constructor = EdgesGeometry;
|
||||
|
||||
|
||||
export { EdgesGeometry };
|
||||
708
node_modules/three/src/geometries/ExtrudeGeometry.js
generated
vendored
Normal file
708
node_modules/three/src/geometries/ExtrudeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,708 @@
|
||||
import { Geometry } from '../core/Geometry';
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
import { Face3 } from '../core/Face3';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { ShapeUtils } from '../extras/ShapeUtils';
|
||||
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
*
|
||||
* Creates extruded geometry from a path shape.
|
||||
*
|
||||
* parameters = {
|
||||
*
|
||||
* curveSegments: <int>, // number of points on the curves
|
||||
* steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
|
||||
* amount: <int>, // Depth to extrude the shape
|
||||
*
|
||||
* bevelEnabled: <bool>, // turn on bevel
|
||||
* bevelThickness: <float>, // how deep into the original shape bevel goes
|
||||
* bevelSize: <float>, // how far from shape outline is bevel
|
||||
* bevelSegments: <int>, // number of bevel layers
|
||||
*
|
||||
* extrudePath: <THREE.Curve> // curve to extrude shape along
|
||||
* frames: <Object> // containing arrays of tangents, normals, binormals
|
||||
*
|
||||
* uvGenerator: <Object> // object that provides UV generator functions
|
||||
*
|
||||
* }
|
||||
**/
|
||||
|
||||
function ExtrudeGeometry( shapes, options ) {
|
||||
|
||||
if ( typeof( shapes ) === "undefined" ) {
|
||||
|
||||
shapes = [];
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'ExtrudeGeometry';
|
||||
|
||||
shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
|
||||
|
||||
this.addShapeList( shapes, options );
|
||||
|
||||
this.computeFaceNormals();
|
||||
|
||||
// can't really use automatic vertex normals
|
||||
// as then front and back sides get smoothed too
|
||||
// should do separate smoothing just for sides
|
||||
|
||||
//this.computeVertexNormals();
|
||||
|
||||
//console.log( "took", ( Date.now() - startTime ) );
|
||||
|
||||
}
|
||||
|
||||
ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
|
||||
ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
|
||||
|
||||
ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
|
||||
|
||||
var sl = shapes.length;
|
||||
|
||||
for ( var s = 0; s < sl; s ++ ) {
|
||||
|
||||
var shape = shapes[ s ];
|
||||
this.addShape( shape, options );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
|
||||
|
||||
var amount = options.amount !== undefined ? options.amount : 100;
|
||||
|
||||
var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
|
||||
var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
|
||||
var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
|
||||
|
||||
var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
|
||||
|
||||
var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
|
||||
|
||||
var steps = options.steps !== undefined ? options.steps : 1;
|
||||
|
||||
var extrudePath = options.extrudePath;
|
||||
var extrudePts, extrudeByPath = false;
|
||||
|
||||
// Use default WorldUVGenerator if no UV generators are specified.
|
||||
var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : ExtrudeGeometry.WorldUVGenerator;
|
||||
|
||||
var splineTube, binormal, normal, position2;
|
||||
if ( extrudePath ) {
|
||||
|
||||
extrudePts = extrudePath.getSpacedPoints( steps );
|
||||
|
||||
extrudeByPath = true;
|
||||
bevelEnabled = false; // bevels not supported for path extrusion
|
||||
|
||||
// SETUP TNB variables
|
||||
|
||||
// TODO1 - have a .isClosed in spline?
|
||||
|
||||
splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames( steps, false );
|
||||
|
||||
// console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
|
||||
|
||||
binormal = new Vector3();
|
||||
normal = new Vector3();
|
||||
position2 = new Vector3();
|
||||
|
||||
}
|
||||
|
||||
// Safeguards if bevels are not enabled
|
||||
|
||||
if ( ! bevelEnabled ) {
|
||||
|
||||
bevelSegments = 0;
|
||||
bevelThickness = 0;
|
||||
bevelSize = 0;
|
||||
|
||||
}
|
||||
|
||||
// Variables initialization
|
||||
|
||||
var ahole, h, hl; // looping of holes
|
||||
var scope = this;
|
||||
|
||||
var shapesOffset = this.vertices.length;
|
||||
|
||||
var shapePoints = shape.extractPoints( curveSegments );
|
||||
|
||||
var vertices = shapePoints.shape;
|
||||
var holes = shapePoints.holes;
|
||||
|
||||
var reverse = ! ShapeUtils.isClockWise( vertices );
|
||||
|
||||
if ( reverse ) {
|
||||
|
||||
vertices = vertices.reverse();
|
||||
|
||||
// Maybe we should also check if holes are in the opposite direction, just to be safe ...
|
||||
|
||||
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
ahole = holes[ h ];
|
||||
|
||||
if ( ShapeUtils.isClockWise( ahole ) ) {
|
||||
|
||||
holes[ h ] = ahole.reverse();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
|
||||
|
||||
}
|
||||
|
||||
|
||||
var faces = ShapeUtils.triangulateShape( vertices, holes );
|
||||
|
||||
/* Vertices */
|
||||
|
||||
var contour = vertices; // vertices has all points but contour has only points of circumference
|
||||
|
||||
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
ahole = holes[ h ];
|
||||
|
||||
vertices = vertices.concat( ahole );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function scalePt2( pt, vec, size ) {
|
||||
|
||||
if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
|
||||
|
||||
return vec.clone().multiplyScalar( size ).add( pt );
|
||||
|
||||
}
|
||||
|
||||
var b, bs, t, z,
|
||||
vert, vlen = vertices.length,
|
||||
face, flen = faces.length;
|
||||
|
||||
|
||||
// Find directions for point movement
|
||||
|
||||
|
||||
function getBevelVec( inPt, inPrev, inNext ) {
|
||||
|
||||
// computes for inPt the corresponding point inPt' on a new contour
|
||||
// shifted by 1 unit (length of normalized vector) to the left
|
||||
// if we walk along contour clockwise, this new contour is outside the old one
|
||||
//
|
||||
// inPt' is the intersection of the two lines parallel to the two
|
||||
// adjacent edges of inPt at a distance of 1 unit on the left side.
|
||||
|
||||
var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
|
||||
|
||||
// good reading for geometry algorithms (here: line-line intersection)
|
||||
// http://geomalgorithms.com/a05-_intersect-1.html
|
||||
|
||||
var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
|
||||
var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
|
||||
|
||||
var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
|
||||
|
||||
// check for collinear edges
|
||||
var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
|
||||
|
||||
if ( Math.abs( collinear0 ) > Number.EPSILON ) {
|
||||
|
||||
// not collinear
|
||||
|
||||
// length of vectors for normalizing
|
||||
|
||||
var v_prev_len = Math.sqrt( v_prev_lensq );
|
||||
var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
|
||||
|
||||
// shift adjacent points by unit vectors to the left
|
||||
|
||||
var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
|
||||
var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
|
||||
|
||||
var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
|
||||
var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
|
||||
|
||||
// scaling factor for v_prev to intersection point
|
||||
|
||||
var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
|
||||
( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
|
||||
( v_prev_x * v_next_y - v_prev_y * v_next_x );
|
||||
|
||||
// vector from inPt to intersection point
|
||||
|
||||
v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
|
||||
v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
|
||||
|
||||
// Don't normalize!, otherwise sharp corners become ugly
|
||||
// but prevent crazy spikes
|
||||
var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
|
||||
if ( v_trans_lensq <= 2 ) {
|
||||
|
||||
return new Vector2( v_trans_x, v_trans_y );
|
||||
|
||||
} else {
|
||||
|
||||
shrink_by = Math.sqrt( v_trans_lensq / 2 );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// handle special case of collinear edges
|
||||
|
||||
var direction_eq = false; // assumes: opposite
|
||||
if ( v_prev_x > Number.EPSILON ) {
|
||||
|
||||
if ( v_next_x > Number.EPSILON ) {
|
||||
|
||||
direction_eq = true;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ( v_prev_x < - Number.EPSILON ) {
|
||||
|
||||
if ( v_next_x < - Number.EPSILON ) {
|
||||
|
||||
direction_eq = true;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
|
||||
|
||||
direction_eq = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( direction_eq ) {
|
||||
|
||||
// console.log("Warning: lines are a straight sequence");
|
||||
v_trans_x = - v_prev_y;
|
||||
v_trans_y = v_prev_x;
|
||||
shrink_by = Math.sqrt( v_prev_lensq );
|
||||
|
||||
} else {
|
||||
|
||||
// console.log("Warning: lines are a straight spike");
|
||||
v_trans_x = v_prev_x;
|
||||
v_trans_y = v_prev_y;
|
||||
shrink_by = Math.sqrt( v_prev_lensq / 2 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
|
||||
|
||||
}
|
||||
|
||||
|
||||
var contourMovements = [];
|
||||
|
||||
for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
|
||||
|
||||
if ( j === il ) j = 0;
|
||||
if ( k === il ) k = 0;
|
||||
|
||||
// (j)---(i)---(k)
|
||||
// console.log('i,j,k', i, j , k)
|
||||
|
||||
contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
|
||||
|
||||
}
|
||||
|
||||
var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
|
||||
|
||||
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
ahole = holes[ h ];
|
||||
|
||||
oneHoleMovements = [];
|
||||
|
||||
for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
|
||||
|
||||
if ( j === il ) j = 0;
|
||||
if ( k === il ) k = 0;
|
||||
|
||||
// (j)---(i)---(k)
|
||||
oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
|
||||
|
||||
}
|
||||
|
||||
holesMovements.push( oneHoleMovements );
|
||||
verticesMovements = verticesMovements.concat( oneHoleMovements );
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Loop bevelSegments, 1 for the front, 1 for the back
|
||||
|
||||
for ( b = 0; b < bevelSegments; b ++ ) {
|
||||
|
||||
//for ( b = bevelSegments; b > 0; b -- ) {
|
||||
|
||||
t = b / bevelSegments;
|
||||
z = bevelThickness * Math.cos( t * Math.PI / 2 );
|
||||
bs = bevelSize * Math.sin( t * Math.PI / 2 );
|
||||
|
||||
// contract shape
|
||||
|
||||
for ( i = 0, il = contour.length; i < il; i ++ ) {
|
||||
|
||||
vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
|
||||
|
||||
v( vert.x, vert.y, - z );
|
||||
|
||||
}
|
||||
|
||||
// expand holes
|
||||
|
||||
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
ahole = holes[ h ];
|
||||
oneHoleMovements = holesMovements[ h ];
|
||||
|
||||
for ( i = 0, il = ahole.length; i < il; i ++ ) {
|
||||
|
||||
vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
|
||||
|
||||
v( vert.x, vert.y, - z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bs = bevelSize;
|
||||
|
||||
// Back facing vertices
|
||||
|
||||
for ( i = 0; i < vlen; i ++ ) {
|
||||
|
||||
vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
|
||||
|
||||
if ( ! extrudeByPath ) {
|
||||
|
||||
v( vert.x, vert.y, 0 );
|
||||
|
||||
} else {
|
||||
|
||||
// v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
|
||||
|
||||
normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
|
||||
binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
|
||||
|
||||
position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
|
||||
|
||||
v( position2.x, position2.y, position2.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Add stepped vertices...
|
||||
// Including front facing vertices
|
||||
|
||||
var s;
|
||||
|
||||
for ( s = 1; s <= steps; s ++ ) {
|
||||
|
||||
for ( i = 0; i < vlen; i ++ ) {
|
||||
|
||||
vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
|
||||
|
||||
if ( ! extrudeByPath ) {
|
||||
|
||||
v( vert.x, vert.y, amount / steps * s );
|
||||
|
||||
} else {
|
||||
|
||||
// v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
|
||||
|
||||
normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
|
||||
binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
|
||||
|
||||
position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
|
||||
|
||||
v( position2.x, position2.y, position2.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Add bevel segments planes
|
||||
|
||||
//for ( b = 1; b <= bevelSegments; b ++ ) {
|
||||
for ( b = bevelSegments - 1; b >= 0; b -- ) {
|
||||
|
||||
t = b / bevelSegments;
|
||||
z = bevelThickness * Math.cos ( t * Math.PI / 2 );
|
||||
bs = bevelSize * Math.sin( t * Math.PI / 2 );
|
||||
|
||||
// contract shape
|
||||
|
||||
for ( i = 0, il = contour.length; i < il; i ++ ) {
|
||||
|
||||
vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
|
||||
v( vert.x, vert.y, amount + z );
|
||||
|
||||
}
|
||||
|
||||
// expand holes
|
||||
|
||||
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
ahole = holes[ h ];
|
||||
oneHoleMovements = holesMovements[ h ];
|
||||
|
||||
for ( i = 0, il = ahole.length; i < il; i ++ ) {
|
||||
|
||||
vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
|
||||
|
||||
if ( ! extrudeByPath ) {
|
||||
|
||||
v( vert.x, vert.y, amount + z );
|
||||
|
||||
} else {
|
||||
|
||||
v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Faces */
|
||||
|
||||
// Top and bottom faces
|
||||
|
||||
buildLidFaces();
|
||||
|
||||
// Sides faces
|
||||
|
||||
buildSideFaces();
|
||||
|
||||
|
||||
///// Internal functions
|
||||
|
||||
function buildLidFaces() {
|
||||
|
||||
if ( bevelEnabled ) {
|
||||
|
||||
var layer = 0; // steps + 1
|
||||
var offset = vlen * layer;
|
||||
|
||||
// Bottom faces
|
||||
|
||||
for ( i = 0; i < flen; i ++ ) {
|
||||
|
||||
face = faces[ i ];
|
||||
f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
|
||||
|
||||
}
|
||||
|
||||
layer = steps + bevelSegments * 2;
|
||||
offset = vlen * layer;
|
||||
|
||||
// Top faces
|
||||
|
||||
for ( i = 0; i < flen; i ++ ) {
|
||||
|
||||
face = faces[ i ];
|
||||
f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Bottom faces
|
||||
|
||||
for ( i = 0; i < flen; i ++ ) {
|
||||
|
||||
face = faces[ i ];
|
||||
f3( face[ 2 ], face[ 1 ], face[ 0 ] );
|
||||
|
||||
}
|
||||
|
||||
// Top faces
|
||||
|
||||
for ( i = 0; i < flen; i ++ ) {
|
||||
|
||||
face = faces[ i ];
|
||||
f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create faces for the z-sides of the shape
|
||||
|
||||
function buildSideFaces() {
|
||||
|
||||
var layeroffset = 0;
|
||||
sidewalls( contour, layeroffset );
|
||||
layeroffset += contour.length;
|
||||
|
||||
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
ahole = holes[ h ];
|
||||
sidewalls( ahole, layeroffset );
|
||||
|
||||
//, true
|
||||
layeroffset += ahole.length;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function sidewalls( contour, layeroffset ) {
|
||||
|
||||
var j, k;
|
||||
i = contour.length;
|
||||
|
||||
while ( -- i >= 0 ) {
|
||||
|
||||
j = i;
|
||||
k = i - 1;
|
||||
if ( k < 0 ) k = contour.length - 1;
|
||||
|
||||
//console.log('b', i,j, i-1, k,vertices.length);
|
||||
|
||||
var s = 0, sl = steps + bevelSegments * 2;
|
||||
|
||||
for ( s = 0; s < sl; s ++ ) {
|
||||
|
||||
var slen1 = vlen * s;
|
||||
var slen2 = vlen * ( s + 1 );
|
||||
|
||||
var a = layeroffset + j + slen1,
|
||||
b = layeroffset + k + slen1,
|
||||
c = layeroffset + k + slen2,
|
||||
d = layeroffset + j + slen2;
|
||||
|
||||
f4( a, b, c, d, contour, s, sl, j, k );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function v( x, y, z ) {
|
||||
|
||||
scope.vertices.push( new Vector3( x, y, z ) );
|
||||
|
||||
}
|
||||
|
||||
function f3( a, b, c ) {
|
||||
|
||||
a += shapesOffset;
|
||||
b += shapesOffset;
|
||||
c += shapesOffset;
|
||||
|
||||
scope.faces.push( new Face3( a, b, c, null, null, 0 ) );
|
||||
|
||||
var uvs = uvgen.generateTopUV( scope, a, b, c );
|
||||
|
||||
scope.faceVertexUvs[ 0 ].push( uvs );
|
||||
|
||||
}
|
||||
|
||||
function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
|
||||
|
||||
a += shapesOffset;
|
||||
b += shapesOffset;
|
||||
c += shapesOffset;
|
||||
d += shapesOffset;
|
||||
|
||||
scope.faces.push( new Face3( a, b, d, null, null, 1 ) );
|
||||
scope.faces.push( new Face3( b, c, d, null, null, 1 ) );
|
||||
|
||||
var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
|
||||
|
||||
scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
|
||||
scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ExtrudeGeometry.WorldUVGenerator = {
|
||||
|
||||
generateTopUV: function ( geometry, indexA, indexB, indexC ) {
|
||||
|
||||
var vertices = geometry.vertices;
|
||||
|
||||
var a = vertices[ indexA ];
|
||||
var b = vertices[ indexB ];
|
||||
var c = vertices[ indexC ];
|
||||
|
||||
return [
|
||||
new Vector2( a.x, a.y ),
|
||||
new Vector2( b.x, b.y ),
|
||||
new Vector2( c.x, c.y )
|
||||
];
|
||||
|
||||
},
|
||||
|
||||
generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
|
||||
|
||||
var vertices = geometry.vertices;
|
||||
|
||||
var a = vertices[ indexA ];
|
||||
var b = vertices[ indexB ];
|
||||
var c = vertices[ indexC ];
|
||||
var d = vertices[ indexD ];
|
||||
|
||||
if ( Math.abs( a.y - b.y ) < 0.01 ) {
|
||||
|
||||
return [
|
||||
new Vector2( a.x, 1 - a.z ),
|
||||
new Vector2( b.x, 1 - b.z ),
|
||||
new Vector2( c.x, 1 - c.z ),
|
||||
new Vector2( d.x, 1 - d.z )
|
||||
];
|
||||
|
||||
} else {
|
||||
|
||||
return [
|
||||
new Vector2( a.y, 1 - a.z ),
|
||||
new Vector2( b.y, 1 - b.z ),
|
||||
new Vector2( c.y, 1 - c.z ),
|
||||
new Vector2( d.y, 1 - d.z )
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export { ExtrudeGeometry };
|
||||
22
node_modules/three/src/geometries/Geometries.js
generated
vendored
Normal file
22
node_modules/three/src/geometries/Geometries.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export { WireframeGeometry } from './WireframeGeometry.js';
|
||||
export { ParametricGeometry, ParametricBufferGeometry } from './ParametricGeometry.js';
|
||||
export { TetrahedronGeometry, TetrahedronBufferGeometry } from './TetrahedronGeometry.js';
|
||||
export { OctahedronGeometry, OctahedronBufferGeometry } from './OctahedronGeometry.js';
|
||||
export { IcosahedronGeometry, IcosahedronBufferGeometry } from './IcosahedronGeometry.js';
|
||||
export { DodecahedronGeometry, DodecahedronBufferGeometry } from './DodecahedronGeometry.js';
|
||||
export { PolyhedronGeometry, PolyhedronBufferGeometry } from './PolyhedronGeometry.js';
|
||||
export { TubeGeometry, TubeBufferGeometry } from './TubeGeometry.js';
|
||||
export { TorusKnotGeometry, TorusKnotBufferGeometry } from './TorusKnotGeometry.js';
|
||||
export { TorusGeometry, TorusBufferGeometry } from './TorusGeometry.js';
|
||||
export { TextGeometry } from './TextGeometry.js';
|
||||
export { SphereGeometry, SphereBufferGeometry } from './SphereGeometry.js';
|
||||
export { RingGeometry, RingBufferGeometry } from './RingGeometry.js';
|
||||
export { PlaneGeometry, PlaneBufferGeometry } from './PlaneGeometry.js';
|
||||
export { LatheGeometry, LatheBufferGeometry } from './LatheGeometry.js';
|
||||
export { ShapeGeometry, ShapeBufferGeometry } from './ShapeGeometry.js';
|
||||
export { ExtrudeGeometry } from './ExtrudeGeometry.js';
|
||||
export { EdgesGeometry } from './EdgesGeometry.js';
|
||||
export { ConeGeometry, ConeBufferGeometry } from './ConeGeometry.js';
|
||||
export { CylinderGeometry, CylinderBufferGeometry } from './CylinderGeometry.js';
|
||||
export { CircleGeometry, CircleBufferGeometry } from './CircleGeometry.js';
|
||||
export { BoxGeometry, BoxBufferGeometry } from './BoxGeometry.js';
|
||||
63
node_modules/three/src/geometries/IcosahedronGeometry.js
generated
vendored
Normal file
63
node_modules/three/src/geometries/IcosahedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* @author timothypratley / https://github.com/timothypratley
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function IcosahedronGeometry( radius, detail ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'IcosahedronGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
|
||||
IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { PolyhedronBufferGeometry } from './PolyhedronGeometry';
|
||||
|
||||
function IcosahedronBufferGeometry( radius, detail ) {
|
||||
|
||||
var t = ( 1 + Math.sqrt( 5 ) ) / 2;
|
||||
|
||||
var vertices = [
|
||||
- 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
|
||||
0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
|
||||
t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
|
||||
];
|
||||
|
||||
var indices = [
|
||||
0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
|
||||
1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
|
||||
3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
|
||||
4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
|
||||
];
|
||||
|
||||
PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
|
||||
|
||||
this.type = 'IcosahedronBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
|
||||
IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
|
||||
|
||||
export { IcosahedronGeometry, IcosahedronBufferGeometry };
|
||||
193
node_modules/three/src/geometries/LatheGeometry.js
generated
vendored
Normal file
193
node_modules/three/src/geometries/LatheGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* @author astrodud / http://astrodud.isgreat.org/
|
||||
* @author zz85 / https://github.com/zz85
|
||||
* @author bhouston / http://clara.io
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
// points - to create a closed torus, one must use a set of points
|
||||
// like so: [ a, b, c, d, a ], see first is the same as last.
|
||||
// segments - the number of circumference segments to create
|
||||
// phiStart - the starting radian
|
||||
// phiLength - the radian (0 to 2PI) range of the lathed section
|
||||
// 2PI is a closed lathe, less than 2PI is a portion.
|
||||
|
||||
function LatheGeometry( points, segments, phiStart, phiLength ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'LatheGeometry';
|
||||
|
||||
this.parameters = {
|
||||
points: points,
|
||||
segments: segments,
|
||||
phiStart: phiStart,
|
||||
phiLength: phiLength
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
LatheGeometry.prototype = Object.create( Geometry.prototype );
|
||||
LatheGeometry.prototype.constructor = LatheGeometry;
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
import { _Math } from '../math/Math';
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'LatheBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
points: points,
|
||||
segments: segments,
|
||||
phiStart: phiStart,
|
||||
phiLength: phiLength
|
||||
};
|
||||
|
||||
segments = Math.floor( segments ) || 12;
|
||||
phiStart = phiStart || 0;
|
||||
phiLength = phiLength || Math.PI * 2;
|
||||
|
||||
// clamp phiLength so it's in range of [ 0, 2PI ]
|
||||
|
||||
phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
|
||||
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
var base;
|
||||
var inverseSegments = 1.0 / segments;
|
||||
var vertex = new Vector3();
|
||||
var uv = new Vector2();
|
||||
var i, j;
|
||||
|
||||
// generate vertices and uvs
|
||||
|
||||
for ( i = 0; i <= segments; i ++ ) {
|
||||
|
||||
var phi = phiStart + i * inverseSegments * phiLength;
|
||||
|
||||
var sin = Math.sin( phi );
|
||||
var cos = Math.cos( phi );
|
||||
|
||||
for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
|
||||
|
||||
// vertex
|
||||
|
||||
vertex.x = points[ j ].x * sin;
|
||||
vertex.y = points[ j ].y;
|
||||
vertex.z = points[ j ].x * cos;
|
||||
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
// uv
|
||||
|
||||
uv.x = i / segments;
|
||||
uv.y = j / ( points.length - 1 );
|
||||
|
||||
uvs.push( uv.x, uv.y );
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// indices
|
||||
|
||||
for ( i = 0; i < segments; i ++ ) {
|
||||
|
||||
for ( j = 0; j < ( points.length - 1 ); j ++ ) {
|
||||
|
||||
base = j + i * points.length;
|
||||
|
||||
var a = base;
|
||||
var b = base + points.length;
|
||||
var c = base + points.length + 1;
|
||||
var d = base + 1;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
// generate normals
|
||||
|
||||
this.computeVertexNormals();
|
||||
|
||||
// if the geometry is closed, we need to average the normals along the seam.
|
||||
// because the corresponding vertices are identical (but still have different UVs).
|
||||
|
||||
if ( phiLength === Math.PI * 2 ) {
|
||||
|
||||
var normals = this.attributes.normal.array;
|
||||
var n1 = new Vector3();
|
||||
var n2 = new Vector3();
|
||||
var n = new Vector3();
|
||||
|
||||
// this is the buffer offset for the last line of vertices
|
||||
|
||||
base = segments * points.length * 3;
|
||||
|
||||
for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
|
||||
|
||||
// select the normal of the vertex in the first line
|
||||
|
||||
n1.x = normals[ j + 0 ];
|
||||
n1.y = normals[ j + 1 ];
|
||||
n1.z = normals[ j + 2 ];
|
||||
|
||||
// select the normal of the vertex in the last line
|
||||
|
||||
n2.x = normals[ base + j + 0 ];
|
||||
n2.y = normals[ base + j + 1 ];
|
||||
n2.z = normals[ base + j + 2 ];
|
||||
|
||||
// average normals
|
||||
|
||||
n.addVectors( n1, n2 ).normalize();
|
||||
|
||||
// assign the new values to both normals
|
||||
|
||||
normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
|
||||
normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
|
||||
normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
|
||||
|
||||
export { LatheGeometry, LatheBufferGeometry };
|
||||
56
node_modules/three/src/geometries/OctahedronGeometry.js
generated
vendored
Normal file
56
node_modules/three/src/geometries/OctahedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @author timothypratley / https://github.com/timothypratley
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function OctahedronGeometry( radius, detail ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'OctahedronGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
OctahedronGeometry.prototype = Object.create( Geometry.prototype );
|
||||
OctahedronGeometry.prototype.constructor = OctahedronGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { PolyhedronBufferGeometry } from './PolyhedronGeometry';
|
||||
|
||||
function OctahedronBufferGeometry( radius, detail ) {
|
||||
|
||||
var vertices = [
|
||||
1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
|
||||
];
|
||||
|
||||
var indices = [
|
||||
0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
|
||||
];
|
||||
|
||||
PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
|
||||
|
||||
this.type = 'OctahedronBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
|
||||
OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
|
||||
|
||||
export { OctahedronGeometry, OctahedronBufferGeometry };
|
||||
116
node_modules/three/src/geometries/ParametricGeometry.js
generated
vendored
Normal file
116
node_modules/three/src/geometries/ParametricGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* @author zz85 / https://github.com/zz85
|
||||
*
|
||||
* Parametric Surfaces Geometry
|
||||
* based on the brilliant article by @prideout http://prideout.net/blog/?p=44
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function ParametricGeometry( func, slices, stacks ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'ParametricGeometry';
|
||||
|
||||
this.parameters = {
|
||||
func: func,
|
||||
slices: slices,
|
||||
stacks: stacks
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
ParametricGeometry.prototype = Object.create( Geometry.prototype );
|
||||
ParametricGeometry.prototype.constructor = ParametricGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*
|
||||
* Parametric Surfaces Geometry
|
||||
* based on the brilliant article by @prideout http://prideout.net/blog/?p=44
|
||||
*/
|
||||
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
|
||||
function ParametricBufferGeometry( func, slices, stacks ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'ParametricBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
func: func,
|
||||
slices: slices,
|
||||
stacks: stacks
|
||||
};
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var uvs = [];
|
||||
|
||||
var i, j;
|
||||
|
||||
// generate vertices and uvs
|
||||
|
||||
var sliceCount = slices + 1;
|
||||
|
||||
for ( i = 0; i <= stacks; i ++ ) {
|
||||
|
||||
var v = i / stacks;
|
||||
|
||||
for ( j = 0; j <= slices; j ++ ) {
|
||||
|
||||
var u = j / slices;
|
||||
|
||||
var p = func( u, v );
|
||||
vertices.push( p.x, p.y, p.z );
|
||||
|
||||
uvs.push( u, v );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// generate indices
|
||||
|
||||
for ( i = 0; i < stacks; i ++ ) {
|
||||
|
||||
for ( j = 0; j < slices; j ++ ) {
|
||||
|
||||
var a = i * sliceCount + j;
|
||||
var b = i * sliceCount + j + 1;
|
||||
var c = ( i + 1 ) * sliceCount + j + 1;
|
||||
var d = ( i + 1 ) * sliceCount + j;
|
||||
|
||||
// faces one and two
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
// generate normals
|
||||
|
||||
this.computeVertexNormals();
|
||||
|
||||
}
|
||||
|
||||
ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
|
||||
|
||||
export { ParametricGeometry, ParametricBufferGeometry };
|
||||
125
node_modules/three/src/geometries/PlaneGeometry.js
generated
vendored
Normal file
125
node_modules/three/src/geometries/PlaneGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function PlaneGeometry( width, height, widthSegments, heightSegments ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'PlaneGeometry';
|
||||
|
||||
this.parameters = {
|
||||
width: width,
|
||||
height: height,
|
||||
widthSegments: widthSegments,
|
||||
heightSegments: heightSegments
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
|
||||
|
||||
}
|
||||
|
||||
PlaneGeometry.prototype = Object.create( Geometry.prototype );
|
||||
PlaneGeometry.prototype.constructor = PlaneGeometry;
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*
|
||||
* based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
|
||||
function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'PlaneBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
width: width,
|
||||
height: height,
|
||||
widthSegments: widthSegments,
|
||||
heightSegments: heightSegments
|
||||
};
|
||||
|
||||
var width_half = width / 2;
|
||||
var height_half = height / 2;
|
||||
|
||||
var gridX = Math.floor( widthSegments ) || 1;
|
||||
var gridY = Math.floor( heightSegments ) || 1;
|
||||
|
||||
var gridX1 = gridX + 1;
|
||||
var gridY1 = gridY + 1;
|
||||
|
||||
var segment_width = width / gridX;
|
||||
var segment_height = height / gridY;
|
||||
|
||||
var ix, iy;
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( iy = 0; iy < gridY1; iy ++ ) {
|
||||
|
||||
var y = iy * segment_height - height_half;
|
||||
|
||||
for ( ix = 0; ix < gridX1; ix ++ ) {
|
||||
|
||||
var x = ix * segment_width - width_half;
|
||||
|
||||
vertices.push( x, - y, 0 );
|
||||
|
||||
normals.push( 0, 0, 1 );
|
||||
|
||||
uvs.push( ix / gridX );
|
||||
uvs.push( 1 - ( iy / gridY ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// indices
|
||||
|
||||
for ( iy = 0; iy < gridY; iy ++ ) {
|
||||
|
||||
for ( ix = 0; ix < gridX; ix ++ ) {
|
||||
|
||||
var a = ix + gridX1 * iy;
|
||||
var b = ix + gridX1 * ( iy + 1 );
|
||||
var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
|
||||
var d = ( ix + 1 ) + gridX1 * iy;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
|
||||
|
||||
export { PlaneGeometry, PlaneBufferGeometry };
|
||||
331
node_modules/three/src/geometries/PolyhedronGeometry.js
generated
vendored
Normal file
331
node_modules/three/src/geometries/PolyhedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,331 @@
|
||||
/**
|
||||
* @author clockworkgeek / https://github.com/clockworkgeek
|
||||
* @author timothypratley / https://github.com/timothypratley
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function PolyhedronGeometry( vertices, indices, radius, detail ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'PolyhedronGeometry';
|
||||
|
||||
this.parameters = {
|
||||
vertices: vertices,
|
||||
indices: indices,
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
|
||||
PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
|
||||
function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'PolyhedronBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
vertices: vertices,
|
||||
indices: indices,
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
radius = radius || 1;
|
||||
detail = detail || 0;
|
||||
|
||||
// default buffer data
|
||||
|
||||
var vertexBuffer = [];
|
||||
var uvBuffer = [];
|
||||
|
||||
// the subdivision creates the vertex buffer data
|
||||
|
||||
subdivide( detail );
|
||||
|
||||
// all vertices should lie on a conceptual sphere with a given radius
|
||||
|
||||
appplyRadius( radius );
|
||||
|
||||
// finally, create the uv data
|
||||
|
||||
generateUVs();
|
||||
|
||||
// build non-indexed geometry
|
||||
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
|
||||
this.normalizeNormals();
|
||||
|
||||
// helper functions
|
||||
|
||||
function subdivide( detail ) {
|
||||
|
||||
var a = new Vector3();
|
||||
var b = new Vector3();
|
||||
var c = new Vector3();
|
||||
|
||||
// iterate over all faces and apply a subdivison with the given detail value
|
||||
|
||||
for ( var i = 0; i < indices.length; i += 3 ) {
|
||||
|
||||
// get the vertices of the face
|
||||
|
||||
getVertexByIndex( indices[ i + 0 ], a );
|
||||
getVertexByIndex( indices[ i + 1 ], b );
|
||||
getVertexByIndex( indices[ i + 2 ], c );
|
||||
|
||||
// perform subdivision
|
||||
|
||||
subdivideFace( a, b, c, detail );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function subdivideFace( a, b, c, detail ) {
|
||||
|
||||
var cols = Math.pow( 2, detail );
|
||||
|
||||
// we use this multidimensional array as a data structure for creating the subdivision
|
||||
|
||||
var v = [];
|
||||
|
||||
var i, j;
|
||||
|
||||
// construct all of the vertices for this subdivision
|
||||
|
||||
for ( i = 0; i <= cols; i ++ ) {
|
||||
|
||||
v[ i ] = [];
|
||||
|
||||
var aj = a.clone().lerp( c, i / cols );
|
||||
var bj = b.clone().lerp( c, i / cols );
|
||||
|
||||
var rows = cols - i;
|
||||
|
||||
for ( j = 0; j <= rows; j ++ ) {
|
||||
|
||||
if ( j === 0 && i === cols ) {
|
||||
|
||||
v[ i ][ j ] = aj;
|
||||
|
||||
} else {
|
||||
|
||||
v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// construct all of the faces
|
||||
|
||||
for ( i = 0; i < cols; i ++ ) {
|
||||
|
||||
for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
|
||||
|
||||
var k = Math.floor( j / 2 );
|
||||
|
||||
if ( j % 2 === 0 ) {
|
||||
|
||||
pushVertex( v[ i ][ k + 1 ] );
|
||||
pushVertex( v[ i + 1 ][ k ] );
|
||||
pushVertex( v[ i ][ k ] );
|
||||
|
||||
} else {
|
||||
|
||||
pushVertex( v[ i ][ k + 1 ] );
|
||||
pushVertex( v[ i + 1 ][ k + 1 ] );
|
||||
pushVertex( v[ i + 1 ][ k ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function appplyRadius( radius ) {
|
||||
|
||||
var vertex = new Vector3();
|
||||
|
||||
// iterate over the entire buffer and apply the radius to each vertex
|
||||
|
||||
for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
|
||||
|
||||
vertex.x = vertexBuffer[ i + 0 ];
|
||||
vertex.y = vertexBuffer[ i + 1 ];
|
||||
vertex.z = vertexBuffer[ i + 2 ];
|
||||
|
||||
vertex.normalize().multiplyScalar( radius );
|
||||
|
||||
vertexBuffer[ i + 0 ] = vertex.x;
|
||||
vertexBuffer[ i + 1 ] = vertex.y;
|
||||
vertexBuffer[ i + 2 ] = vertex.z;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function generateUVs() {
|
||||
|
||||
var vertex = new Vector3();
|
||||
|
||||
for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
|
||||
|
||||
vertex.x = vertexBuffer[ i + 0 ];
|
||||
vertex.y = vertexBuffer[ i + 1 ];
|
||||
vertex.z = vertexBuffer[ i + 2 ];
|
||||
|
||||
var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
|
||||
var v = inclination( vertex ) / Math.PI + 0.5;
|
||||
uvBuffer.push( u, 1 - v );
|
||||
|
||||
}
|
||||
|
||||
correctUVs();
|
||||
|
||||
correctSeam();
|
||||
|
||||
}
|
||||
|
||||
function correctSeam() {
|
||||
|
||||
// handle case when face straddles the seam, see #3269
|
||||
|
||||
for ( var i = 0; i < uvBuffer.length; i += 6 ) {
|
||||
|
||||
// uv data of a single face
|
||||
|
||||
var x0 = uvBuffer[ i + 0 ];
|
||||
var x1 = uvBuffer[ i + 2 ];
|
||||
var x2 = uvBuffer[ i + 4 ];
|
||||
|
||||
var max = Math.max( x0, x1, x2 );
|
||||
var min = Math.min( x0, x1, x2 );
|
||||
|
||||
// 0.9 is somewhat arbitrary
|
||||
|
||||
if ( max > 0.9 && min < 0.1 ) {
|
||||
|
||||
if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
|
||||
if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
|
||||
if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function pushVertex( vertex ) {
|
||||
|
||||
vertexBuffer.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
}
|
||||
|
||||
function getVertexByIndex( index, vertex ) {
|
||||
|
||||
var stride = index * 3;
|
||||
|
||||
vertex.x = vertices[ stride + 0 ];
|
||||
vertex.y = vertices[ stride + 1 ];
|
||||
vertex.z = vertices[ stride + 2 ];
|
||||
|
||||
}
|
||||
|
||||
function correctUVs() {
|
||||
|
||||
var a = new Vector3();
|
||||
var b = new Vector3();
|
||||
var c = new Vector3();
|
||||
|
||||
var centroid = new Vector3();
|
||||
|
||||
var uvA = new Vector2();
|
||||
var uvB = new Vector2();
|
||||
var uvC = new Vector2();
|
||||
|
||||
for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
|
||||
|
||||
a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
|
||||
b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
|
||||
c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
|
||||
|
||||
uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
|
||||
uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
|
||||
uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
|
||||
|
||||
centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
|
||||
|
||||
var azi = azimuth( centroid );
|
||||
|
||||
correctUV( uvA, j + 0, a, azi );
|
||||
correctUV( uvB, j + 2, b, azi );
|
||||
correctUV( uvC, j + 4, c, azi );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function correctUV( uv, stride, vector, azimuth ) {
|
||||
|
||||
if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
|
||||
|
||||
uvBuffer[ stride ] = uv.x - 1;
|
||||
|
||||
}
|
||||
|
||||
if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
|
||||
|
||||
uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Angle around the Y axis, counter-clockwise when looking from above.
|
||||
|
||||
function azimuth( vector ) {
|
||||
|
||||
return Math.atan2( vector.z, - vector.x );
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Angle above the XZ plane.
|
||||
|
||||
function inclination( vector ) {
|
||||
|
||||
return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
|
||||
|
||||
export { PolyhedronGeometry, PolyhedronBufferGeometry };
|
||||
150
node_modules/three/src/geometries/RingGeometry.js
generated
vendored
Normal file
150
node_modules/three/src/geometries/RingGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* @author Kaleb Murphy
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'RingGeometry';
|
||||
|
||||
this.parameters = {
|
||||
innerRadius: innerRadius,
|
||||
outerRadius: outerRadius,
|
||||
thetaSegments: thetaSegments,
|
||||
phiSegments: phiSegments,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
|
||||
|
||||
}
|
||||
|
||||
RingGeometry.prototype = Object.create( Geometry.prototype );
|
||||
RingGeometry.prototype.constructor = RingGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
|
||||
function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'RingBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
innerRadius: innerRadius,
|
||||
outerRadius: outerRadius,
|
||||
thetaSegments: thetaSegments,
|
||||
phiSegments: phiSegments,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
innerRadius = innerRadius || 20;
|
||||
outerRadius = outerRadius || 50;
|
||||
|
||||
thetaStart = thetaStart !== undefined ? thetaStart : 0;
|
||||
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
|
||||
|
||||
thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
|
||||
phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
||||
// some helper variables
|
||||
|
||||
var segment;
|
||||
var radius = innerRadius;
|
||||
var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
|
||||
var vertex = new Vector3();
|
||||
var uv = new Vector2();
|
||||
var j, i;
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( j = 0; j <= phiSegments; j ++ ) {
|
||||
|
||||
for ( i = 0; i <= thetaSegments; i ++ ) {
|
||||
|
||||
// values are generate from the inside of the ring to the outside
|
||||
|
||||
segment = thetaStart + i / thetaSegments * thetaLength;
|
||||
|
||||
// vertex
|
||||
|
||||
vertex.x = radius * Math.cos( segment );
|
||||
vertex.y = radius * Math.sin( segment );
|
||||
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
// normal
|
||||
|
||||
normals.push( 0, 0, 1 );
|
||||
|
||||
// uv
|
||||
|
||||
uv.x = ( vertex.x / outerRadius + 1 ) / 2;
|
||||
uv.y = ( vertex.y / outerRadius + 1 ) / 2;
|
||||
|
||||
uvs.push( uv.x, uv.y );
|
||||
|
||||
}
|
||||
|
||||
// increase the radius for next row of vertices
|
||||
|
||||
radius += radiusStep;
|
||||
|
||||
}
|
||||
|
||||
// indices
|
||||
|
||||
for ( j = 0; j < phiSegments; j ++ ) {
|
||||
|
||||
var thetaSegmentLevel = j * ( thetaSegments + 1 );
|
||||
|
||||
for ( i = 0; i < thetaSegments; i ++ ) {
|
||||
|
||||
segment = i + thetaSegmentLevel;
|
||||
|
||||
var a = segment;
|
||||
var b = segment + thetaSegments + 1;
|
||||
var c = segment + thetaSegments + 2;
|
||||
var d = segment + 1;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
RingBufferGeometry.prototype.constructor = RingBufferGeometry;
|
||||
|
||||
export { RingGeometry, RingBufferGeometry };
|
||||
175
node_modules/three/src/geometries/ShapeGeometry.js
generated
vendored
Normal file
175
node_modules/three/src/geometries/ShapeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* @author jonobr1 / http://jonobr1.com
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function ShapeGeometry( shapes, curveSegments ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'ShapeGeometry';
|
||||
|
||||
if ( typeof curveSegments === 'object' ) {
|
||||
|
||||
console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
|
||||
|
||||
curveSegments = curveSegments.curveSegments;
|
||||
|
||||
}
|
||||
|
||||
this.parameters = {
|
||||
shapes: shapes,
|
||||
curveSegments: curveSegments
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
ShapeGeometry.prototype = Object.create( Geometry.prototype );
|
||||
ShapeGeometry.prototype.constructor = ShapeGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { ShapeUtils } from '../extras/ShapeUtils';
|
||||
|
||||
function ShapeBufferGeometry( shapes, curveSegments ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'ShapeBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
shapes: shapes,
|
||||
curveSegments: curveSegments
|
||||
};
|
||||
|
||||
curveSegments = curveSegments || 12;
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
var groupStart = 0;
|
||||
var groupCount = 0;
|
||||
|
||||
// allow single and array values for "shapes" parameter
|
||||
|
||||
if ( Array.isArray( shapes ) === false ) {
|
||||
|
||||
addShape( shapes );
|
||||
|
||||
} else {
|
||||
|
||||
for ( var i = 0; i < shapes.length; i ++ ) {
|
||||
|
||||
addShape( shapes[ i ] );
|
||||
|
||||
this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
|
||||
|
||||
groupStart += groupCount;
|
||||
groupCount = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
|
||||
// helper functions
|
||||
|
||||
function addShape( shape ) {
|
||||
|
||||
var i, l, shapeHole;
|
||||
|
||||
var indexOffset = vertices.length / 3;
|
||||
var points = shape.extractPoints( curveSegments );
|
||||
|
||||
var shapeVertices = points.shape;
|
||||
var shapeHoles = points.holes;
|
||||
|
||||
// check direction of vertices
|
||||
|
||||
if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
|
||||
|
||||
shapeVertices = shapeVertices.reverse();
|
||||
|
||||
// also check if holes are in the opposite direction
|
||||
|
||||
for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
|
||||
|
||||
shapeHole = shapeHoles[ i ];
|
||||
|
||||
if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
|
||||
|
||||
shapeHoles[ i ] = shapeHole.reverse();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
|
||||
|
||||
// join vertices of inner and outer paths to a single array
|
||||
|
||||
for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
|
||||
|
||||
shapeHole = shapeHoles[ i ];
|
||||
shapeVertices = shapeVertices.concat( shapeHole );
|
||||
|
||||
}
|
||||
|
||||
// vertices, normals, uvs
|
||||
|
||||
for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
|
||||
|
||||
var vertex = shapeVertices[ i ];
|
||||
|
||||
vertices.push( vertex.x, vertex.y, 0 );
|
||||
normals.push( 0, 0, 1 );
|
||||
uvs.push( vertex.x, vertex.y ); // world uvs
|
||||
|
||||
}
|
||||
|
||||
// incides
|
||||
|
||||
for ( i = 0, l = faces.length; i < l; i ++ ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
|
||||
var a = face[ 0 ] + indexOffset;
|
||||
var b = face[ 1 ] + indexOffset;
|
||||
var c = face[ 2 ] + indexOffset;
|
||||
|
||||
indices.push( a, b, c );
|
||||
groupCount += 3;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
|
||||
|
||||
export { ShapeGeometry, ShapeBufferGeometry };
|
||||
150
node_modules/three/src/geometries/SphereGeometry.js
generated
vendored
Normal file
150
node_modules/three/src/geometries/SphereGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'SphereGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
widthSegments: widthSegments,
|
||||
heightSegments: heightSegments,
|
||||
phiStart: phiStart,
|
||||
phiLength: phiLength,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
|
||||
|
||||
}
|
||||
|
||||
SphereGeometry.prototype = Object.create( Geometry.prototype );
|
||||
SphereGeometry.prototype.constructor = SphereGeometry;
|
||||
|
||||
/**
|
||||
* @author benaadams / https://twitter.com/ben_a_adams
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
|
||||
function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'SphereBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
widthSegments: widthSegments,
|
||||
heightSegments: heightSegments,
|
||||
phiStart: phiStart,
|
||||
phiLength: phiLength,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
radius = radius || 50;
|
||||
|
||||
widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
|
||||
heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
|
||||
|
||||
phiStart = phiStart !== undefined ? phiStart : 0;
|
||||
phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
|
||||
|
||||
thetaStart = thetaStart !== undefined ? thetaStart : 0;
|
||||
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
|
||||
|
||||
var thetaEnd = thetaStart + thetaLength;
|
||||
|
||||
var ix, iy;
|
||||
|
||||
var index = 0;
|
||||
var grid = [];
|
||||
|
||||
var vertex = new Vector3();
|
||||
var normal = new Vector3();
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( iy = 0; iy <= heightSegments; iy ++ ) {
|
||||
|
||||
var verticesRow = [];
|
||||
|
||||
var v = iy / heightSegments;
|
||||
|
||||
for ( ix = 0; ix <= widthSegments; ix ++ ) {
|
||||
|
||||
var u = ix / widthSegments;
|
||||
|
||||
// vertex
|
||||
|
||||
vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
|
||||
vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
|
||||
vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
|
||||
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
// normal
|
||||
|
||||
normal.set( vertex.x, vertex.y, vertex.z ).normalize();
|
||||
normals.push( normal.x, normal.y, normal.z );
|
||||
|
||||
// uv
|
||||
|
||||
uvs.push( u, 1 - v );
|
||||
|
||||
verticesRow.push( index ++ );
|
||||
|
||||
}
|
||||
|
||||
grid.push( verticesRow );
|
||||
|
||||
}
|
||||
|
||||
// indices
|
||||
|
||||
for ( iy = 0; iy < heightSegments; iy ++ ) {
|
||||
|
||||
for ( ix = 0; ix < widthSegments; ix ++ ) {
|
||||
|
||||
var a = grid[ iy ][ ix + 1 ];
|
||||
var b = grid[ iy ][ ix ];
|
||||
var c = grid[ iy + 1 ][ ix ];
|
||||
var d = grid[ iy + 1 ][ ix + 1 ];
|
||||
|
||||
if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
|
||||
if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
|
||||
|
||||
export { SphereGeometry, SphereBufferGeometry };
|
||||
56
node_modules/three/src/geometries/TetrahedronGeometry.js
generated
vendored
Normal file
56
node_modules/three/src/geometries/TetrahedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @author timothypratley / https://github.com/timothypratley
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function TetrahedronGeometry( radius, detail ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'TetrahedronGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
|
||||
TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { PolyhedronBufferGeometry } from './PolyhedronGeometry';
|
||||
|
||||
function TetrahedronBufferGeometry( radius, detail ) {
|
||||
|
||||
var vertices = [
|
||||
1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
|
||||
];
|
||||
|
||||
var indices = [
|
||||
2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
|
||||
];
|
||||
|
||||
PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
|
||||
|
||||
this.type = 'TetrahedronBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
|
||||
TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
|
||||
|
||||
export { TetrahedronGeometry, TetrahedronBufferGeometry };
|
||||
58
node_modules/three/src/geometries/TextGeometry.js
generated
vendored
Normal file
58
node_modules/three/src/geometries/TextGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
import { ExtrudeGeometry } from './ExtrudeGeometry';
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
/**
|
||||
* @author zz85 / http://www.lab4games.net/zz85/blog
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*
|
||||
* Text = 3D Text
|
||||
*
|
||||
* parameters = {
|
||||
* font: <THREE.Font>, // font
|
||||
*
|
||||
* size: <float>, // size of the text
|
||||
* height: <float>, // thickness to extrude text
|
||||
* curveSegments: <int>, // number of points on the curves
|
||||
*
|
||||
* bevelEnabled: <bool>, // turn on bevel
|
||||
* bevelThickness: <float>, // how deep into text bevel goes
|
||||
* bevelSize: <float> // how far from text outline is bevel
|
||||
* }
|
||||
*/
|
||||
|
||||
function TextGeometry( text, parameters ) {
|
||||
|
||||
parameters = parameters || {};
|
||||
|
||||
var font = parameters.font;
|
||||
|
||||
if ( ( font && font.isFont ) === false ) {
|
||||
|
||||
console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
|
||||
return new Geometry();
|
||||
|
||||
}
|
||||
|
||||
var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
|
||||
|
||||
// translate parameters to ExtrudeGeometry API
|
||||
|
||||
parameters.amount = parameters.height !== undefined ? parameters.height : 50;
|
||||
|
||||
// defaults
|
||||
|
||||
if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
|
||||
if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
|
||||
if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
|
||||
|
||||
ExtrudeGeometry.call( this, shapes, parameters );
|
||||
|
||||
this.type = 'TextGeometry';
|
||||
|
||||
}
|
||||
|
||||
TextGeometry.prototype = Object.create( ExtrudeGeometry.prototype );
|
||||
TextGeometry.prototype.constructor = TextGeometry;
|
||||
|
||||
|
||||
export { TextGeometry };
|
||||
141
node_modules/three/src/geometries/TorusGeometry.js
generated
vendored
Normal file
141
node_modules/three/src/geometries/TorusGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* @author oosmoxiecode
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'TorusGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
tube: tube,
|
||||
radialSegments: radialSegments,
|
||||
tubularSegments: tubularSegments,
|
||||
arc: arc
|
||||
};
|
||||
|
||||
this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
|
||||
|
||||
}
|
||||
|
||||
TorusGeometry.prototype = Object.create( Geometry.prototype );
|
||||
TorusGeometry.prototype.constructor = TorusGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
|
||||
function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'TorusBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
tube: tube,
|
||||
radialSegments: radialSegments,
|
||||
tubularSegments: tubularSegments,
|
||||
arc: arc
|
||||
};
|
||||
|
||||
radius = radius || 100;
|
||||
tube = tube || 40;
|
||||
radialSegments = Math.floor( radialSegments ) || 8;
|
||||
tubularSegments = Math.floor( tubularSegments ) || 6;
|
||||
arc = arc || Math.PI * 2;
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
var center = new Vector3();
|
||||
var vertex = new Vector3();
|
||||
var normal = new Vector3();
|
||||
|
||||
var j, i;
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( j = 0; j <= radialSegments; j ++ ) {
|
||||
|
||||
for ( i = 0; i <= tubularSegments; i ++ ) {
|
||||
|
||||
var u = i / tubularSegments * arc;
|
||||
var v = j / radialSegments * Math.PI * 2;
|
||||
|
||||
// vertex
|
||||
|
||||
vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
|
||||
vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
|
||||
vertex.z = tube * Math.sin( v );
|
||||
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
// normal
|
||||
|
||||
center.x = radius * Math.cos( u );
|
||||
center.y = radius * Math.sin( u );
|
||||
normal.subVectors( vertex, center ).normalize();
|
||||
|
||||
normals.push( normal.x, normal.y, normal.z );
|
||||
|
||||
// uv
|
||||
|
||||
uvs.push( i / tubularSegments );
|
||||
uvs.push( j / radialSegments );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// generate indices
|
||||
|
||||
for ( j = 1; j <= radialSegments; j ++ ) {
|
||||
|
||||
for ( i = 1; i <= tubularSegments; i ++ ) {
|
||||
|
||||
// indices
|
||||
|
||||
var a = ( tubularSegments + 1 ) * j + i - 1;
|
||||
var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
|
||||
var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
|
||||
var d = ( tubularSegments + 1 ) * j + i;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
|
||||
|
||||
export { TorusGeometry, TorusBufferGeometry };
|
||||
194
node_modules/three/src/geometries/TorusKnotGeometry.js
generated
vendored
Normal file
194
node_modules/three/src/geometries/TorusKnotGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* @author oosmoxiecode
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'TorusKnotGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
tube: tube,
|
||||
tubularSegments: tubularSegments,
|
||||
radialSegments: radialSegments,
|
||||
p: p,
|
||||
q: q
|
||||
};
|
||||
|
||||
if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
|
||||
|
||||
this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
|
||||
TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
* see: http://www.blackpawn.com/texts/pqtorus/
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
|
||||
function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'TorusKnotBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
tube: tube,
|
||||
tubularSegments: tubularSegments,
|
||||
radialSegments: radialSegments,
|
||||
p: p,
|
||||
q: q
|
||||
};
|
||||
|
||||
radius = radius || 100;
|
||||
tube = tube || 40;
|
||||
tubularSegments = Math.floor( tubularSegments ) || 64;
|
||||
radialSegments = Math.floor( radialSegments ) || 8;
|
||||
p = p || 2;
|
||||
q = q || 3;
|
||||
|
||||
// buffers
|
||||
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
var i, j;
|
||||
|
||||
var vertex = new Vector3();
|
||||
var normal = new Vector3();
|
||||
var uv = new Vector2();
|
||||
|
||||
var P1 = new Vector3();
|
||||
var P2 = new Vector3();
|
||||
|
||||
var B = new Vector3();
|
||||
var T = new Vector3();
|
||||
var N = new Vector3();
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( i = 0; i <= tubularSegments; ++ i ) {
|
||||
|
||||
// the radian "u" is used to calculate the position on the torus curve of the current tubular segement
|
||||
|
||||
var u = i / tubularSegments * p * Math.PI * 2;
|
||||
|
||||
// now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
|
||||
// these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
|
||||
|
||||
calculatePositionOnCurve( u, p, q, radius, P1 );
|
||||
calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
|
||||
|
||||
// calculate orthonormal basis
|
||||
|
||||
T.subVectors( P2, P1 );
|
||||
N.addVectors( P2, P1 );
|
||||
B.crossVectors( T, N );
|
||||
N.crossVectors( B, T );
|
||||
|
||||
// normalize B, N. T can be ignored, we don't use it
|
||||
|
||||
B.normalize();
|
||||
N.normalize();
|
||||
|
||||
for ( j = 0; j <= radialSegments; ++ j ) {
|
||||
|
||||
// now calculate the vertices. they are nothing more than an extrusion of the torus curve.
|
||||
// because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
|
||||
|
||||
var v = j / radialSegments * Math.PI * 2;
|
||||
var cx = - tube * Math.cos( v );
|
||||
var cy = tube * Math.sin( v );
|
||||
|
||||
// now calculate the final vertex position.
|
||||
// first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
|
||||
|
||||
vertex.x = P1.x + ( cx * N.x + cy * B.x );
|
||||
vertex.y = P1.y + ( cx * N.y + cy * B.y );
|
||||
vertex.z = P1.z + ( cx * N.z + cy * B.z );
|
||||
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
// normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
|
||||
|
||||
normal.subVectors( vertex, P1 ).normalize();
|
||||
|
||||
normals.push( normal.x, normal.y, normal.z );
|
||||
|
||||
// uv
|
||||
|
||||
uvs.push( i / tubularSegments );
|
||||
uvs.push( j / radialSegments );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// generate indices
|
||||
|
||||
for ( j = 1; j <= tubularSegments; j ++ ) {
|
||||
|
||||
for ( i = 1; i <= radialSegments; i ++ ) {
|
||||
|
||||
// indices
|
||||
|
||||
var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
|
||||
var b = ( radialSegments + 1 ) * j + ( i - 1 );
|
||||
var c = ( radialSegments + 1 ) * j + i;
|
||||
var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
// this function calculates the current position on the torus curve
|
||||
|
||||
function calculatePositionOnCurve( u, p, q, radius, position ) {
|
||||
|
||||
var cu = Math.cos( u );
|
||||
var su = Math.sin( u );
|
||||
var quOverP = q / p * u;
|
||||
var cs = Math.cos( quOverP );
|
||||
|
||||
position.x = radius * ( 2 + cs ) * 0.5 * cu;
|
||||
position.y = radius * ( 2 + cs ) * su * 0.5;
|
||||
position.z = radius * Math.sin( quOverP ) * 0.5;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
|
||||
|
||||
export { TorusKnotGeometry, TorusKnotBufferGeometry };
|
||||
222
node_modules/three/src/geometries/TubeGeometry.js
generated
vendored
Normal file
222
node_modules/three/src/geometries/TubeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
/**
|
||||
* @author oosmoxiecode / https://github.com/oosmoxiecode
|
||||
* @author WestLangley / https://github.com/WestLangley
|
||||
* @author zz85 / https://github.com/zz85
|
||||
* @author miningold / https://github.com/miningold
|
||||
* @author jonobr1 / https://github.com/jonobr1
|
||||
*
|
||||
* Creates a tube which extrudes along a 3d spline.
|
||||
*/
|
||||
|
||||
import { Geometry } from '../core/Geometry';
|
||||
|
||||
function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
|
||||
|
||||
Geometry.call( this );
|
||||
|
||||
this.type = 'TubeGeometry';
|
||||
|
||||
this.parameters = {
|
||||
path: path,
|
||||
tubularSegments: tubularSegments,
|
||||
radius: radius,
|
||||
radialSegments: radialSegments,
|
||||
closed: closed
|
||||
};
|
||||
|
||||
if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
|
||||
|
||||
var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
|
||||
|
||||
// expose internals
|
||||
|
||||
this.tangents = bufferGeometry.tangents;
|
||||
this.normals = bufferGeometry.normals;
|
||||
this.binormals = bufferGeometry.binormals;
|
||||
|
||||
// create geometry
|
||||
|
||||
this.fromBufferGeometry( bufferGeometry );
|
||||
this.mergeVertices();
|
||||
|
||||
}
|
||||
|
||||
TubeGeometry.prototype = Object.create( Geometry.prototype );
|
||||
TubeGeometry.prototype.constructor = TubeGeometry;
|
||||
|
||||
/**
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Vector2 } from '../math/Vector2';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
|
||||
function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'TubeBufferGeometry';
|
||||
|
||||
this.parameters = {
|
||||
path: path,
|
||||
tubularSegments: tubularSegments,
|
||||
radius: radius,
|
||||
radialSegments: radialSegments,
|
||||
closed: closed
|
||||
};
|
||||
|
||||
tubularSegments = tubularSegments || 64;
|
||||
radius = radius || 1;
|
||||
radialSegments = radialSegments || 8;
|
||||
closed = closed || false;
|
||||
|
||||
var frames = path.computeFrenetFrames( tubularSegments, closed );
|
||||
|
||||
// expose internals
|
||||
|
||||
this.tangents = frames.tangents;
|
||||
this.normals = frames.normals;
|
||||
this.binormals = frames.binormals;
|
||||
|
||||
// helper variables
|
||||
|
||||
var vertex = new Vector3();
|
||||
var normal = new Vector3();
|
||||
var uv = new Vector2();
|
||||
|
||||
var i, j;
|
||||
|
||||
// buffer
|
||||
|
||||
var vertices = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
var indices = [];
|
||||
|
||||
// create buffer data
|
||||
|
||||
generateBufferData();
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
// functions
|
||||
|
||||
function generateBufferData() {
|
||||
|
||||
for ( i = 0; i < tubularSegments; i ++ ) {
|
||||
|
||||
generateSegment( i );
|
||||
|
||||
}
|
||||
|
||||
// if the geometry is not closed, generate the last row of vertices and normals
|
||||
// at the regular position on the given path
|
||||
//
|
||||
// if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
|
||||
|
||||
generateSegment( ( closed === false ) ? tubularSegments : 0 );
|
||||
|
||||
// uvs are generated in a separate function.
|
||||
// this makes it easy compute correct values for closed geometries
|
||||
|
||||
generateUVs();
|
||||
|
||||
// finally create faces
|
||||
|
||||
generateIndices();
|
||||
|
||||
}
|
||||
|
||||
function generateSegment( i ) {
|
||||
|
||||
// we use getPointAt to sample evenly distributed points from the given path
|
||||
|
||||
var P = path.getPointAt( i / tubularSegments );
|
||||
|
||||
// retrieve corresponding normal and binormal
|
||||
|
||||
var N = frames.normals[ i ];
|
||||
var B = frames.binormals[ i ];
|
||||
|
||||
// generate normals and vertices for the current segment
|
||||
|
||||
for ( j = 0; j <= radialSegments; j ++ ) {
|
||||
|
||||
var v = j / radialSegments * Math.PI * 2;
|
||||
|
||||
var sin = Math.sin( v );
|
||||
var cos = - Math.cos( v );
|
||||
|
||||
// normal
|
||||
|
||||
normal.x = ( cos * N.x + sin * B.x );
|
||||
normal.y = ( cos * N.y + sin * B.y );
|
||||
normal.z = ( cos * N.z + sin * B.z );
|
||||
normal.normalize();
|
||||
|
||||
normals.push( normal.x, normal.y, normal.z );
|
||||
|
||||
// vertex
|
||||
|
||||
vertex.x = P.x + radius * normal.x;
|
||||
vertex.y = P.y + radius * normal.y;
|
||||
vertex.z = P.z + radius * normal.z;
|
||||
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function generateIndices() {
|
||||
|
||||
for ( j = 1; j <= tubularSegments; j ++ ) {
|
||||
|
||||
for ( i = 1; i <= radialSegments; i ++ ) {
|
||||
|
||||
var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
|
||||
var b = ( radialSegments + 1 ) * j + ( i - 1 );
|
||||
var c = ( radialSegments + 1 ) * j + i;
|
||||
var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function generateUVs() {
|
||||
|
||||
for ( i = 0; i <= tubularSegments; i ++ ) {
|
||||
|
||||
for ( j = 0; j <= radialSegments; j ++ ) {
|
||||
|
||||
uv.x = i / tubularSegments;
|
||||
uv.y = j / radialSegments;
|
||||
|
||||
uvs.push( uv.x, uv.y );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
|
||||
|
||||
export { TubeGeometry, TubeBufferGeometry };
|
||||
185
node_modules/three/src/geometries/WireframeGeometry.js
generated
vendored
Normal file
185
node_modules/three/src/geometries/WireframeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
function WireframeGeometry( geometry ) {
|
||||
|
||||
BufferGeometry.call( this );
|
||||
|
||||
this.type = 'WireframeGeometry';
|
||||
|
||||
// buffer
|
||||
|
||||
var vertices = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
var i, j, l, o, ol;
|
||||
var edge = [ 0, 0 ], edges = {}, e;
|
||||
var key, keys = [ 'a', 'b', 'c' ];
|
||||
var vertex;
|
||||
|
||||
// different logic for Geometry and BufferGeometry
|
||||
|
||||
if ( geometry && geometry.isGeometry ) {
|
||||
|
||||
// create a data structure that contains all edges without duplicates
|
||||
|
||||
var faces = geometry.faces;
|
||||
|
||||
for ( i = 0, l = faces.length; i < l; i ++ ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
|
||||
for ( j = 0; j < 3; j ++ ) {
|
||||
|
||||
edge[ 0 ] = face[ keys[ j ] ];
|
||||
edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
|
||||
edge.sort( sortFunction ); // sorting prevents duplicates
|
||||
|
||||
key = edge.toString();
|
||||
|
||||
if ( edges[ key ] === undefined ) {
|
||||
|
||||
edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// generate vertices
|
||||
|
||||
for ( key in edges ) {
|
||||
|
||||
e = edges[ key ];
|
||||
|
||||
vertex = geometry.vertices[ e.index1 ];
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
vertex = geometry.vertices[ e.index2 ];
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
}
|
||||
|
||||
} else if ( geometry && geometry.isBufferGeometry ) {
|
||||
|
||||
var position, indices, groups;
|
||||
var group, start, count;
|
||||
var index1, index2;
|
||||
|
||||
vertex = new Vector3();
|
||||
|
||||
if ( geometry.index !== null ) {
|
||||
|
||||
// indexed BufferGeometry
|
||||
|
||||
position = geometry.attributes.position;
|
||||
indices = geometry.index;
|
||||
groups = geometry.groups;
|
||||
|
||||
if ( groups.length === 0 ) {
|
||||
|
||||
geometry.addGroup( 0, indices.count );
|
||||
|
||||
}
|
||||
|
||||
// create a data structure that contains all eges without duplicates
|
||||
|
||||
for ( o = 0, ol = groups.length; o < ol; ++ o ) {
|
||||
|
||||
group = groups[ o ];
|
||||
|
||||
start = group.start;
|
||||
count = group.count;
|
||||
|
||||
for ( i = start, l = ( start + count ); i < l; i += 3 ) {
|
||||
|
||||
for ( j = 0; j < 3; j ++ ) {
|
||||
|
||||
edge[ 0 ] = indices.getX( i + j );
|
||||
edge[ 1 ] = indices.getX( i + ( j + 1 ) % 3 );
|
||||
edge.sort( sortFunction ); // sorting prevents duplicates
|
||||
|
||||
key = edge.toString();
|
||||
|
||||
if ( edges[ key ] === undefined ) {
|
||||
|
||||
edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// generate vertices
|
||||
|
||||
for ( key in edges ) {
|
||||
|
||||
e = edges[ key ];
|
||||
|
||||
vertex.fromBufferAttribute( position, e.index1 );
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
vertex.fromBufferAttribute( position, e.index2 );
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// non-indexed BufferGeometry
|
||||
|
||||
position = geometry.attributes.position;
|
||||
|
||||
for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
|
||||
|
||||
for ( j = 0; j < 3; j ++ ) {
|
||||
|
||||
// three edges per triangle, an edge is represented as (index1, index2)
|
||||
// e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
|
||||
|
||||
index1 = 3 * i + j;
|
||||
vertex.fromBufferAttribute( position, index1 );
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
index2 = 3 * i + ( ( j + 1 ) % 3 );
|
||||
vertex.fromBufferAttribute( position, index2 );
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
|
||||
// custom array sort function
|
||||
|
||||
function sortFunction( a, b ) {
|
||||
|
||||
return a - b;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
|
||||
WireframeGeometry.prototype.constructor = WireframeGeometry;
|
||||
|
||||
|
||||
export { WireframeGeometry };
|
||||
121
node_modules/three/src/helpers/ArrowHelper.js
generated
vendored
Normal file
121
node_modules/three/src/helpers/ArrowHelper.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
* @author zz85 / http://github.com/zz85
|
||||
* @author bhouston / http://clara.io
|
||||
*
|
||||
* Creates an arrow for visualizing directions
|
||||
*
|
||||
* Parameters:
|
||||
* dir - Vector3
|
||||
* origin - Vector3
|
||||
* length - Number
|
||||
* color - color in hex value
|
||||
* headLength - Number
|
||||
* headWidth - Number
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Object3D } from '../core/Object3D';
|
||||
import { CylinderBufferGeometry } from '../geometries/CylinderGeometry';
|
||||
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial';
|
||||
import { Mesh } from '../objects/Mesh';
|
||||
import { Line } from '../objects/Line';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
|
||||
var lineGeometry, coneGeometry;
|
||||
|
||||
function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
|
||||
|
||||
// dir is assumed to be normalized
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
if ( color === undefined ) color = 0xffff00;
|
||||
if ( length === undefined ) length = 1;
|
||||
if ( headLength === undefined ) headLength = 0.2 * length;
|
||||
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
|
||||
|
||||
if ( lineGeometry === undefined ) {
|
||||
|
||||
lineGeometry = new BufferGeometry();
|
||||
lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
|
||||
|
||||
coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
|
||||
coneGeometry.translate( 0, - 0.5, 0 );
|
||||
|
||||
}
|
||||
|
||||
this.position.copy( origin );
|
||||
|
||||
this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
|
||||
this.line.matrixAutoUpdate = false;
|
||||
this.add( this.line );
|
||||
|
||||
this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
|
||||
this.cone.matrixAutoUpdate = false;
|
||||
this.add( this.cone );
|
||||
|
||||
this.setDirection( dir );
|
||||
this.setLength( length, headLength, headWidth );
|
||||
|
||||
}
|
||||
|
||||
ArrowHelper.prototype = Object.create( Object3D.prototype );
|
||||
ArrowHelper.prototype.constructor = ArrowHelper;
|
||||
|
||||
ArrowHelper.prototype.setDirection = ( function () {
|
||||
|
||||
var axis = new Vector3();
|
||||
var radians;
|
||||
|
||||
return function setDirection( dir ) {
|
||||
|
||||
// dir is assumed to be normalized
|
||||
|
||||
if ( dir.y > 0.99999 ) {
|
||||
|
||||
this.quaternion.set( 0, 0, 0, 1 );
|
||||
|
||||
} else if ( dir.y < - 0.99999 ) {
|
||||
|
||||
this.quaternion.set( 1, 0, 0, 0 );
|
||||
|
||||
} else {
|
||||
|
||||
axis.set( dir.z, 0, - dir.x ).normalize();
|
||||
|
||||
radians = Math.acos( dir.y );
|
||||
|
||||
this.quaternion.setFromAxisAngle( axis, radians );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
|
||||
|
||||
if ( headLength === undefined ) headLength = 0.2 * length;
|
||||
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
|
||||
|
||||
this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
|
||||
this.line.updateMatrix();
|
||||
|
||||
this.cone.scale.set( headWidth, headLength, headWidth );
|
||||
this.cone.position.y = length;
|
||||
this.cone.updateMatrix();
|
||||
|
||||
};
|
||||
|
||||
ArrowHelper.prototype.setColor = function ( color ) {
|
||||
|
||||
this.line.material.color.copy( color );
|
||||
this.cone.material.color.copy( color );
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { ArrowHelper };
|
||||
42
node_modules/three/src/helpers/AxisHelper.js
generated
vendored
Normal file
42
node_modules/three/src/helpers/AxisHelper.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { LineSegments } from '../objects/LineSegments';
|
||||
import { VertexColors } from '../constants';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
|
||||
/**
|
||||
* @author sroucheray / http://sroucheray.org/
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function AxisHelper( size ) {
|
||||
|
||||
size = size || 1;
|
||||
|
||||
var vertices = [
|
||||
0, 0, 0, size, 0, 0,
|
||||
0, 0, 0, 0, size, 0,
|
||||
0, 0, 0, 0, 0, size
|
||||
];
|
||||
|
||||
var colors = [
|
||||
1, 0, 0, 1, 0.6, 0,
|
||||
0, 1, 0, 0.6, 1, 0,
|
||||
0, 0, 1, 0, 0.6, 1
|
||||
];
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { vertexColors: VertexColors } );
|
||||
|
||||
LineSegments.call( this, geometry, material );
|
||||
|
||||
}
|
||||
|
||||
AxisHelper.prototype = Object.create( LineSegments.prototype );
|
||||
AxisHelper.prototype.constructor = AxisHelper;
|
||||
|
||||
|
||||
export { AxisHelper };
|
||||
93
node_modules/three/src/helpers/BoxHelper.js
generated
vendored
Normal file
93
node_modules/three/src/helpers/BoxHelper.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
import { Box3 } from '../math/Box3';
|
||||
import { LineSegments } from '../objects/LineSegments';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial';
|
||||
import { BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function BoxHelper( object, color ) {
|
||||
|
||||
if ( color === undefined ) color = 0xffff00;
|
||||
|
||||
var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
|
||||
var positions = new Float32Array( 8 * 3 );
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.setIndex( new BufferAttribute( indices, 1 ) );
|
||||
geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
|
||||
|
||||
LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
|
||||
|
||||
if ( object !== undefined ) {
|
||||
|
||||
this.update( object );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BoxHelper.prototype = Object.create( LineSegments.prototype );
|
||||
BoxHelper.prototype.constructor = BoxHelper;
|
||||
|
||||
BoxHelper.prototype.update = ( function () {
|
||||
|
||||
var box = new Box3();
|
||||
|
||||
return function update( object ) {
|
||||
|
||||
if ( object && object.isBox3 ) {
|
||||
|
||||
box.copy( object );
|
||||
|
||||
} else {
|
||||
|
||||
box.setFromObject( object );
|
||||
|
||||
}
|
||||
|
||||
if ( box.isEmpty() ) return;
|
||||
|
||||
var min = box.min;
|
||||
var max = box.max;
|
||||
|
||||
/*
|
||||
5____4
|
||||
1/___0/|
|
||||
| 6__|_7
|
||||
2/___3/
|
||||
|
||||
0: max.x, max.y, max.z
|
||||
1: min.x, max.y, max.z
|
||||
2: min.x, min.y, max.z
|
||||
3: max.x, min.y, max.z
|
||||
4: max.x, max.y, min.z
|
||||
5: min.x, max.y, min.z
|
||||
6: min.x, min.y, min.z
|
||||
7: max.x, min.y, min.z
|
||||
*/
|
||||
|
||||
var position = this.geometry.attributes.position;
|
||||
var array = position.array;
|
||||
|
||||
array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
|
||||
array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
|
||||
array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
|
||||
array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
|
||||
array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
|
||||
array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
|
||||
array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
|
||||
array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
|
||||
|
||||
position.needsUpdate = true;
|
||||
|
||||
this.geometry.computeBoundingSphere();
|
||||
|
||||
};
|
||||
|
||||
} )();
|
||||
|
||||
|
||||
export { BoxHelper };
|
||||
210
node_modules/three/src/helpers/CameraHelper.js
generated
vendored
Normal file
210
node_modules/three/src/helpers/CameraHelper.js
generated
vendored
Normal file
@@ -0,0 +1,210 @@
|
||||
import { Camera } from '../cameras/Camera';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { LineSegments } from '../objects/LineSegments';
|
||||
import { Color } from '../math/Color';
|
||||
import { FaceColors } from '../constants';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*
|
||||
* - shows frustum, line of sight and up of the camera
|
||||
* - suitable for fast updates
|
||||
* - based on frustum visualization in lightgl.js shadowmap example
|
||||
* http://evanw.github.com/lightgl.js/tests/shadowmap.html
|
||||
*/
|
||||
|
||||
function CameraHelper( camera ) {
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
|
||||
|
||||
var vertices = [];
|
||||
var colors = [];
|
||||
|
||||
var pointMap = {};
|
||||
|
||||
// colors
|
||||
|
||||
var colorFrustum = new Color( 0xffaa00 );
|
||||
var colorCone = new Color( 0xff0000 );
|
||||
var colorUp = new Color( 0x00aaff );
|
||||
var colorTarget = new Color( 0xffffff );
|
||||
var colorCross = new Color( 0x333333 );
|
||||
|
||||
// near
|
||||
|
||||
addLine( "n1", "n2", colorFrustum );
|
||||
addLine( "n2", "n4", colorFrustum );
|
||||
addLine( "n4", "n3", colorFrustum );
|
||||
addLine( "n3", "n1", colorFrustum );
|
||||
|
||||
// far
|
||||
|
||||
addLine( "f1", "f2", colorFrustum );
|
||||
addLine( "f2", "f4", colorFrustum );
|
||||
addLine( "f4", "f3", colorFrustum );
|
||||
addLine( "f3", "f1", colorFrustum );
|
||||
|
||||
// sides
|
||||
|
||||
addLine( "n1", "f1", colorFrustum );
|
||||
addLine( "n2", "f2", colorFrustum );
|
||||
addLine( "n3", "f3", colorFrustum );
|
||||
addLine( "n4", "f4", colorFrustum );
|
||||
|
||||
// cone
|
||||
|
||||
addLine( "p", "n1", colorCone );
|
||||
addLine( "p", "n2", colorCone );
|
||||
addLine( "p", "n3", colorCone );
|
||||
addLine( "p", "n4", colorCone );
|
||||
|
||||
// up
|
||||
|
||||
addLine( "u1", "u2", colorUp );
|
||||
addLine( "u2", "u3", colorUp );
|
||||
addLine( "u3", "u1", colorUp );
|
||||
|
||||
// target
|
||||
|
||||
addLine( "c", "t", colorTarget );
|
||||
addLine( "p", "c", colorCross );
|
||||
|
||||
// cross
|
||||
|
||||
addLine( "cn1", "cn2", colorCross );
|
||||
addLine( "cn3", "cn4", colorCross );
|
||||
|
||||
addLine( "cf1", "cf2", colorCross );
|
||||
addLine( "cf3", "cf4", colorCross );
|
||||
|
||||
function addLine( a, b, color ) {
|
||||
|
||||
addPoint( a, color );
|
||||
addPoint( b, color );
|
||||
|
||||
}
|
||||
|
||||
function addPoint( id, color ) {
|
||||
|
||||
vertices.push( 0, 0, 0 );
|
||||
colors.push( color.r, color.g, color.b );
|
||||
|
||||
if ( pointMap[ id ] === undefined ) {
|
||||
|
||||
pointMap[ id ] = [];
|
||||
|
||||
}
|
||||
|
||||
pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
|
||||
|
||||
}
|
||||
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
LineSegments.call( this, geometry, material );
|
||||
|
||||
this.camera = camera;
|
||||
if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
|
||||
|
||||
this.matrix = camera.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.pointMap = pointMap;
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
CameraHelper.prototype = Object.create( LineSegments.prototype );
|
||||
CameraHelper.prototype.constructor = CameraHelper;
|
||||
|
||||
CameraHelper.prototype.update = function () {
|
||||
|
||||
var geometry, pointMap;
|
||||
|
||||
var vector = new Vector3();
|
||||
var camera = new Camera();
|
||||
|
||||
function setPoint( point, x, y, z ) {
|
||||
|
||||
vector.set( x, y, z ).unproject( camera );
|
||||
|
||||
var points = pointMap[ point ];
|
||||
|
||||
if ( points !== undefined ) {
|
||||
|
||||
var position = geometry.getAttribute( 'position' );
|
||||
|
||||
for ( var i = 0, l = points.length; i < l; i ++ ) {
|
||||
|
||||
position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return function update() {
|
||||
|
||||
geometry = this.geometry;
|
||||
pointMap = this.pointMap;
|
||||
|
||||
var w = 1, h = 1;
|
||||
|
||||
// we need just camera projection matrix
|
||||
// world matrix must be identity
|
||||
|
||||
camera.projectionMatrix.copy( this.camera.projectionMatrix );
|
||||
|
||||
// center / target
|
||||
|
||||
setPoint( "c", 0, 0, - 1 );
|
||||
setPoint( "t", 0, 0, 1 );
|
||||
|
||||
// near
|
||||
|
||||
setPoint( "n1", - w, - h, - 1 );
|
||||
setPoint( "n2", w, - h, - 1 );
|
||||
setPoint( "n3", - w, h, - 1 );
|
||||
setPoint( "n4", w, h, - 1 );
|
||||
|
||||
// far
|
||||
|
||||
setPoint( "f1", - w, - h, 1 );
|
||||
setPoint( "f2", w, - h, 1 );
|
||||
setPoint( "f3", - w, h, 1 );
|
||||
setPoint( "f4", w, h, 1 );
|
||||
|
||||
// up
|
||||
|
||||
setPoint( "u1", w * 0.7, h * 1.1, - 1 );
|
||||
setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
|
||||
setPoint( "u3", 0, h * 2, - 1 );
|
||||
|
||||
// cross
|
||||
|
||||
setPoint( "cf1", - w, 0, 1 );
|
||||
setPoint( "cf2", w, 0, 1 );
|
||||
setPoint( "cf3", 0, - h, 1 );
|
||||
setPoint( "cf4", 0, h, 1 );
|
||||
|
||||
setPoint( "cn1", - w, 0, - 1 );
|
||||
setPoint( "cn2", w, 0, - 1 );
|
||||
setPoint( "cn3", 0, - h, - 1 );
|
||||
setPoint( "cn4", 0, h, - 1 );
|
||||
|
||||
geometry.getAttribute( 'position' ).needsUpdate = true;
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
|
||||
export { CameraHelper };
|
||||
89
node_modules/three/src/helpers/DirectionalLightHelper.js
generated
vendored
Normal file
89
node_modules/three/src/helpers/DirectionalLightHelper.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Object3D } from '../core/Object3D';
|
||||
import { Line } from '../objects/Line';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
function DirectionalLightHelper( light, size ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.light = light;
|
||||
this.light.updateMatrixWorld();
|
||||
|
||||
this.matrix = light.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
if ( size === undefined ) size = 1;
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( [
|
||||
- size, size, 0,
|
||||
size, size, 0,
|
||||
size, - size, 0,
|
||||
- size, - size, 0,
|
||||
- size, size, 0
|
||||
], 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { fog: false } );
|
||||
|
||||
this.add( new Line( geometry, material ) );
|
||||
|
||||
geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
|
||||
|
||||
this.add( new Line( geometry, material ));
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
|
||||
DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
|
||||
|
||||
DirectionalLightHelper.prototype.dispose = function () {
|
||||
|
||||
var lightPlane = this.children[ 0 ];
|
||||
var targetLine = this.children[ 1 ];
|
||||
|
||||
lightPlane.geometry.dispose();
|
||||
lightPlane.material.dispose();
|
||||
targetLine.geometry.dispose();
|
||||
targetLine.material.dispose();
|
||||
|
||||
};
|
||||
|
||||
DirectionalLightHelper.prototype.update = function () {
|
||||
|
||||
var v1 = new Vector3();
|
||||
var v2 = new Vector3();
|
||||
var v3 = new Vector3();
|
||||
|
||||
return function update() {
|
||||
|
||||
v1.setFromMatrixPosition( this.light.matrixWorld );
|
||||
v2.setFromMatrixPosition( this.light.target.matrixWorld );
|
||||
v3.subVectors( v2, v1 );
|
||||
|
||||
var lightPlane = this.children[ 0 ];
|
||||
var targetLine = this.children[ 1 ];
|
||||
|
||||
lightPlane.lookAt( v3 );
|
||||
lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
||||
|
||||
targetLine.lookAt( v3 );
|
||||
targetLine.scale.z = v3.length();
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
|
||||
export { DirectionalLightHelper };
|
||||
120
node_modules/three/src/helpers/FaceNormalsHelper.js
generated
vendored
Normal file
120
node_modules/three/src/helpers/FaceNormalsHelper.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
import { Matrix3 } from '../math/Matrix3';
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { LineSegments } from '../objects/LineSegments';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
function FaceNormalsHelper( object, size, hex, linewidth ) {
|
||||
|
||||
// FaceNormalsHelper only supports THREE.Geometry
|
||||
|
||||
this.object = object;
|
||||
|
||||
this.size = ( size !== undefined ) ? size : 1;
|
||||
|
||||
var color = ( hex !== undefined ) ? hex : 0xffff00;
|
||||
|
||||
var width = ( linewidth !== undefined ) ? linewidth : 1;
|
||||
|
||||
//
|
||||
|
||||
var nNormals = 0;
|
||||
|
||||
var objGeometry = this.object.geometry;
|
||||
|
||||
if ( objGeometry && objGeometry.isGeometry ) {
|
||||
|
||||
nNormals = objGeometry.faces.length;
|
||||
|
||||
} else {
|
||||
|
||||
console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
|
||||
var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
|
||||
|
||||
geometry.addAttribute( 'position', positions );
|
||||
|
||||
LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
|
||||
|
||||
//
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
|
||||
FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
|
||||
|
||||
FaceNormalsHelper.prototype.update = ( function () {
|
||||
|
||||
var v1 = new Vector3();
|
||||
var v2 = new Vector3();
|
||||
var normalMatrix = new Matrix3();
|
||||
|
||||
return function update() {
|
||||
|
||||
this.object.updateMatrixWorld( true );
|
||||
|
||||
normalMatrix.getNormalMatrix( this.object.matrixWorld );
|
||||
|
||||
var matrixWorld = this.object.matrixWorld;
|
||||
|
||||
var position = this.geometry.attributes.position;
|
||||
|
||||
//
|
||||
|
||||
var objGeometry = this.object.geometry;
|
||||
|
||||
var vertices = objGeometry.vertices;
|
||||
|
||||
var faces = objGeometry.faces;
|
||||
|
||||
var idx = 0;
|
||||
|
||||
for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
|
||||
var normal = face.normal;
|
||||
|
||||
v1.copy( vertices[ face.a ] )
|
||||
.add( vertices[ face.b ] )
|
||||
.add( vertices[ face.c ] )
|
||||
.divideScalar( 3 )
|
||||
.applyMatrix4( matrixWorld );
|
||||
|
||||
v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
|
||||
|
||||
position.setXYZ( idx, v1.x, v1.y, v1.z );
|
||||
|
||||
idx = idx + 1;
|
||||
|
||||
position.setXYZ( idx, v2.x, v2.y, v2.z );
|
||||
|
||||
idx = idx + 1;
|
||||
|
||||
}
|
||||
|
||||
position.needsUpdate = true;
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
|
||||
export { FaceNormalsHelper };
|
||||
52
node_modules/three/src/helpers/GridHelper.js
generated
vendored
Normal file
52
node_modules/three/src/helpers/GridHelper.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { LineSegments } from '../objects/LineSegments';
|
||||
import { VertexColors } from '../constants';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Color } from '../math/Color';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function GridHelper( size, divisions, color1, color2 ) {
|
||||
|
||||
size = size || 10;
|
||||
divisions = divisions || 10;
|
||||
color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
|
||||
color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
|
||||
|
||||
var center = divisions / 2;
|
||||
var step = size / divisions;
|
||||
var halfSize = size / 2;
|
||||
|
||||
var vertices = [], colors = [];
|
||||
|
||||
for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
|
||||
|
||||
vertices.push( - halfSize, 0, k, halfSize, 0, k );
|
||||
vertices.push( k, 0, - halfSize, k, 0, halfSize );
|
||||
|
||||
var color = i === center ? color1 : color2;
|
||||
|
||||
color.toArray( colors, j ); j += 3;
|
||||
color.toArray( colors, j ); j += 3;
|
||||
color.toArray( colors, j ); j += 3;
|
||||
color.toArray( colors, j ); j += 3;
|
||||
|
||||
}
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { vertexColors: VertexColors } );
|
||||
|
||||
LineSegments.call( this, geometry, material );
|
||||
|
||||
}
|
||||
|
||||
GridHelper.prototype = Object.create( LineSegments.prototype );
|
||||
GridHelper.prototype.constructor = GridHelper;
|
||||
|
||||
export { GridHelper };
|
||||
85
node_modules/three/src/helpers/HemisphereLightHelper.js
generated
vendored
Normal file
85
node_modules/three/src/helpers/HemisphereLightHelper.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
import { Vector3 } from '../math/Vector3';
|
||||
import { Color } from '../math/Color';
|
||||
import { Object3D } from '../core/Object3D';
|
||||
import { Mesh } from '../objects/Mesh';
|
||||
import { VertexColors } from '../constants';
|
||||
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial';
|
||||
import { OctahedronBufferGeometry } from '../geometries/OctahedronGeometry';
|
||||
import { BufferAttribute } from '../core/BufferAttribute';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
function HemisphereLightHelper( light, size ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.light = light;
|
||||
this.light.updateMatrixWorld();
|
||||
|
||||
this.matrix = light.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
var geometry = new OctahedronBufferGeometry( size );
|
||||
geometry.rotateY( Math.PI * 0.5 );
|
||||
|
||||
var material = new MeshBasicMaterial( { vertexColors: VertexColors, wireframe: true } );
|
||||
|
||||
var position = geometry.getAttribute( 'position' );
|
||||
var colors = new Float32Array( position.count * 3 );
|
||||
|
||||
geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
|
||||
|
||||
this.add( new Mesh( geometry, material ) );
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
|
||||
HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
|
||||
|
||||
HemisphereLightHelper.prototype.dispose = function () {
|
||||
|
||||
this.children[ 0 ].geometry.dispose();
|
||||
this.children[ 0 ].material.dispose();
|
||||
|
||||
};
|
||||
|
||||
HemisphereLightHelper.prototype.update = function () {
|
||||
|
||||
var vector = new Vector3();
|
||||
|
||||
var color1 = new Color();
|
||||
var color2 = new Color();
|
||||
|
||||
return function update() {
|
||||
|
||||
var mesh = this.children[ 0 ];
|
||||
|
||||
var colors = mesh.geometry.getAttribute( 'color' );
|
||||
|
||||
color1.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
||||
color2.copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
|
||||
|
||||
for ( var i = 0, l = colors.count; i < l; i ++ ) {
|
||||
|
||||
var color = ( i < ( l / 2 ) ) ? color1 : color2;
|
||||
|
||||
colors.setXYZ( i, color.r, color.g, color.b );
|
||||
|
||||
}
|
||||
|
||||
mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
|
||||
|
||||
colors.needsUpdate = true;
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
|
||||
export { HemisphereLightHelper };
|
||||
80
node_modules/three/src/helpers/PointLightHelper.js
generated
vendored
Normal file
80
node_modules/three/src/helpers/PointLightHelper.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Mesh } from '../objects/Mesh';
|
||||
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial';
|
||||
import { SphereBufferGeometry } from '../geometries/SphereGeometry';
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function PointLightHelper( light, sphereSize ) {
|
||||
|
||||
this.light = light;
|
||||
this.light.updateMatrixWorld();
|
||||
|
||||
var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
|
||||
var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
|
||||
material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
||||
|
||||
Mesh.call( this, geometry, material );
|
||||
|
||||
this.matrix = this.light.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
/*
|
||||
var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
|
||||
var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
|
||||
|
||||
this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
|
||||
this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
|
||||
|
||||
var d = light.distance;
|
||||
|
||||
if ( d === 0.0 ) {
|
||||
|
||||
this.lightDistance.visible = false;
|
||||
|
||||
} else {
|
||||
|
||||
this.lightDistance.scale.set( d, d, d );
|
||||
|
||||
}
|
||||
|
||||
this.add( this.lightDistance );
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
PointLightHelper.prototype = Object.create( Mesh.prototype );
|
||||
PointLightHelper.prototype.constructor = PointLightHelper;
|
||||
|
||||
PointLightHelper.prototype.dispose = function () {
|
||||
|
||||
this.geometry.dispose();
|
||||
this.material.dispose();
|
||||
|
||||
};
|
||||
|
||||
PointLightHelper.prototype.update = function () {
|
||||
|
||||
this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
||||
|
||||
/*
|
||||
var d = this.light.distance;
|
||||
|
||||
if ( d === 0.0 ) {
|
||||
|
||||
this.lightDistance.visible = false;
|
||||
|
||||
} else {
|
||||
|
||||
this.lightDistance.visible = true;
|
||||
this.lightDistance.scale.set( d, d, d );
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { PointLightHelper };
|
||||
95
node_modules/three/src/helpers/PolarGridHelper.js
generated
vendored
Normal file
95
node_modules/three/src/helpers/PolarGridHelper.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import { LineSegments } from '../objects/LineSegments';
|
||||
import { VertexColors } from '../constants';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute';
|
||||
import { BufferGeometry } from '../core/BufferGeometry';
|
||||
import { Color } from '../math/Color';
|
||||
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author Mugen87 / http://github.com/Mugen87
|
||||
* @author Hectate / http://www.github.com/Hectate
|
||||
*/
|
||||
|
||||
function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
|
||||
|
||||
radius = radius || 10;
|
||||
radials = radials || 16;
|
||||
circles = circles || 8;
|
||||
divisions = divisions || 64;
|
||||
color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
|
||||
color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
|
||||
|
||||
var vertices = [];
|
||||
var colors = [];
|
||||
|
||||
var x, z;
|
||||
var v, i, j, r, color;
|
||||
|
||||
// create the radials
|
||||
|
||||
for ( i = 0; i <= radials; i ++ ) {
|
||||
|
||||
v = ( i / radials ) * ( Math.PI * 2 );
|
||||
|
||||
x = Math.sin( v ) * radius;
|
||||
z = Math.cos( v ) * radius;
|
||||
|
||||
vertices.push( 0, 0, 0 );
|
||||
vertices.push( x, 0, z );
|
||||
|
||||
color = ( i & 1 ) ? color1 : color2;
|
||||
|
||||
colors.push( color.r, color.g, color.b );
|
||||
colors.push( color.r, color.g, color.b );
|
||||
|
||||
}
|
||||
|
||||
// create the circles
|
||||
|
||||
for ( i = 0; i <= circles; i ++ ) {
|
||||
|
||||
color = ( i & 1 ) ? color1 : color2;
|
||||
|
||||
r = radius - ( radius / circles * i );
|
||||
|
||||
for ( j = 0; j < divisions; j ++ ) {
|
||||
|
||||
// first vertex
|
||||
|
||||
v = ( j / divisions ) * ( Math.PI * 2 );
|
||||
|
||||
x = Math.sin( v ) * r;
|
||||
z = Math.cos( v ) * r;
|
||||
|
||||
vertices.push( x, 0, z );
|
||||
colors.push( color.r, color.g, color.b );
|
||||
|
||||
// second vertex
|
||||
|
||||
v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
|
||||
|
||||
x = Math.sin( v ) * r;
|
||||
z = Math.cos( v ) * r;
|
||||
|
||||
vertices.push( x, 0, z );
|
||||
colors.push( color.r, color.g, color.b );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { vertexColors: VertexColors } );
|
||||
|
||||
LineSegments.call( this, geometry, material );
|
||||
|
||||
}
|
||||
|
||||
PolarGridHelper.prototype = Object.create( LineSegments.prototype );
|
||||
PolarGridHelper.prototype.constructor = PolarGridHelper;
|
||||
|
||||
export { PolarGridHelper };
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user