first app vibe
This commit is contained in:
182
app/node_modules/three/src/Three.Core.js
generated
vendored
Normal file
182
app/node_modules/three/src/Three.Core.js
generated
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
import { REVISION } from './constants.js';
|
||||
|
||||
export { WebGLArrayRenderTarget } from './renderers/WebGLArrayRenderTarget.js';
|
||||
export { WebGL3DRenderTarget } from './renderers/WebGL3DRenderTarget.js';
|
||||
export { WebGLCubeRenderTarget } from './renderers/WebGLCubeRenderTarget.js';
|
||||
export { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js';
|
||||
export { WebXRController } from './renderers/webxr/WebXRController.js';
|
||||
export { FogExp2 } from './scenes/FogExp2.js';
|
||||
export { Fog } from './scenes/Fog.js';
|
||||
export { Scene } from './scenes/Scene.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 { InstancedMesh } from './objects/InstancedMesh.js';
|
||||
export { BatchedMesh } from './objects/BatchedMesh.js';
|
||||
export { LineSegments } from './objects/LineSegments.js';
|
||||
export { LineLoop } from './objects/LineLoop.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 { VideoFrameTexture } from './textures/VideoFrameTexture.js';
|
||||
export { FramebufferTexture } from './textures/FramebufferTexture.js';
|
||||
export { Source } from './textures/Source.js';
|
||||
export { DataTexture } from './textures/DataTexture.js';
|
||||
export { DataArrayTexture } from './textures/DataArrayTexture.js';
|
||||
export { Data3DTexture } from './textures/Data3DTexture.js';
|
||||
export { CompressedTexture } from './textures/CompressedTexture.js';
|
||||
export { CompressedArrayTexture } from './textures/CompressedArrayTexture.js';
|
||||
export { CompressedCubeTexture } from './textures/CompressedCubeTexture.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 { AnimationLoader } from './loaders/AnimationLoader.js';
|
||||
export { CompressedTextureLoader } from './loaders/CompressedTextureLoader.js';
|
||||
export { CubeTextureLoader } from './loaders/CubeTextureLoader.js';
|
||||
export { DataTextureLoader } from './loaders/DataTextureLoader.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 { ImageLoader } from './loaders/ImageLoader.js';
|
||||
export { ImageBitmapLoader } from './loaders/ImageBitmapLoader.js';
|
||||
export { FileLoader } from './loaders/FileLoader.js';
|
||||
export { Loader } from './loaders/Loader.js';
|
||||
export { LoaderUtils } from './loaders/LoaderUtils.js';
|
||||
export { Cache } from './loaders/Cache.js';
|
||||
export { AudioLoader } from './loaders/AudioLoader.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 { DirectionalLight } from './lights/DirectionalLight.js';
|
||||
export { AmbientLight } from './lights/AmbientLight.js';
|
||||
export { Light } from './lights/Light.js';
|
||||
export { LightProbe } from './lights/LightProbe.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 { ArrayCamera } from './cameras/ArrayCamera.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 { AnimationAction } from './animation/AnimationAction.js';
|
||||
export { RenderTarget } from './core/RenderTarget.js';
|
||||
export { RenderTarget3D } from './core/RenderTarget3D.js';
|
||||
export { Uniform } from './core/Uniform.js';
|
||||
export { UniformsGroup } from './core/UniformsGroup.js';
|
||||
export { InstancedBufferGeometry } from './core/InstancedBufferGeometry.js';
|
||||
export { BufferGeometry } from './core/BufferGeometry.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 { GLBufferAttribute } from './core/GLBufferAttribute.js';
|
||||
export * from './core/BufferAttribute.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 { MathUtils } from './math/MathUtils.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 { FrustumArray } from './math/FrustumArray.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 { Matrix2 } from './math/Matrix2.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 { ColorManagement } from './math/ColorManagement.js';
|
||||
export { SphericalHarmonics3 } from './math/SphericalHarmonics3.js';
|
||||
export { SpotLightHelper } from './helpers/SpotLightHelper.js';
|
||||
export { SkeletonHelper } from './helpers/SkeletonHelper.js';
|
||||
export { PointLightHelper } from './helpers/PointLightHelper.js';
|
||||
export { HemisphereLightHelper } from './helpers/HemisphereLightHelper.js';
|
||||
export { GridHelper } from './helpers/GridHelper.js';
|
||||
export { PolarGridHelper } from './helpers/PolarGridHelper.js';
|
||||
export { DirectionalLightHelper } from './helpers/DirectionalLightHelper.js';
|
||||
export { CameraHelper } from './helpers/CameraHelper.js';
|
||||
export { BoxHelper } from './helpers/BoxHelper.js';
|
||||
export { Box3Helper } from './helpers/Box3Helper.js';
|
||||
export { PlaneHelper } from './helpers/PlaneHelper.js';
|
||||
export { ArrowHelper } from './helpers/ArrowHelper.js';
|
||||
export { AxesHelper } from './helpers/AxesHelper.js';
|
||||
export * from './extras/curves/Curves.js';
|
||||
export { Shape } from './extras/core/Shape.js';
|
||||
export { Path } from './extras/core/Path.js';
|
||||
export { ShapePath } from './extras/core/ShapePath.js';
|
||||
export { CurvePath } from './extras/core/CurvePath.js';
|
||||
export { Curve } from './extras/core/Curve.js';
|
||||
export { Controls } from './extras/Controls.js';
|
||||
export { DataUtils } from './extras/DataUtils.js';
|
||||
export { ImageUtils } from './extras/ImageUtils.js';
|
||||
export { ShapeUtils } from './extras/ShapeUtils.js';
|
||||
export { TextureUtils } from './extras/TextureUtils.js';
|
||||
export { createCanvasElement } from './utils.js';
|
||||
export * from './constants.js';
|
||||
export * from './Three.Legacy.js';
|
||||
|
||||
if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
|
||||
|
||||
__THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
|
||||
revision: REVISION,
|
||||
} } ) );
|
||||
|
||||
}
|
||||
|
||||
if ( typeof window !== 'undefined' ) {
|
||||
|
||||
if ( window.__THREE__ ) {
|
||||
|
||||
console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
|
||||
|
||||
} else {
|
||||
|
||||
window.__THREE__ = REVISION;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
0
app/node_modules/three/src/Three.Legacy.js
generated
vendored
Normal file
0
app/node_modules/three/src/Three.Legacy.js
generated
vendored
Normal file
553
app/node_modules/three/src/Three.TSL.js
generated
vendored
Normal file
553
app/node_modules/three/src/Three.TSL.js
generated
vendored
Normal file
@@ -0,0 +1,553 @@
|
||||
import { TSL } from 'three/webgpu';
|
||||
|
||||
export const BRDF_GGX = TSL.BRDF_GGX;
|
||||
export const BRDF_Lambert = TSL.BRDF_Lambert;
|
||||
export const BasicShadowFilter = TSL.BasicShadowFilter;
|
||||
export const Break = TSL.Break;
|
||||
export const Continue = TSL.Continue;
|
||||
export const DFGApprox = TSL.DFGApprox;
|
||||
export const D_GGX = TSL.D_GGX;
|
||||
export const Discard = TSL.Discard;
|
||||
export const EPSILON = TSL.EPSILON;
|
||||
export const F_Schlick = TSL.F_Schlick;
|
||||
export const Fn = TSL.Fn;
|
||||
export const INFINITY = TSL.INFINITY;
|
||||
export const If = TSL.If;
|
||||
export const Switch = TSL.Switch;
|
||||
export const Loop = TSL.Loop;
|
||||
export const NodeShaderStage = TSL.NodeShaderStage;
|
||||
export const NodeType = TSL.NodeType;
|
||||
export const NodeUpdateType = TSL.NodeUpdateType;
|
||||
export const NodeAccess = TSL.NodeAccess;
|
||||
export const PCFShadowFilter = TSL.PCFShadowFilter;
|
||||
export const PCFSoftShadowFilter = TSL.PCFSoftShadowFilter;
|
||||
export const PI = TSL.PI;
|
||||
export const PI2 = TSL.PI2;
|
||||
export const Return = TSL.Return;
|
||||
export const Schlick_to_F0 = TSL.Schlick_to_F0;
|
||||
export const ScriptableNodeResources = TSL.ScriptableNodeResources;
|
||||
export const ShaderNode = TSL.ShaderNode;
|
||||
export const TBNViewMatrix = TSL.TBNViewMatrix;
|
||||
export const VSMShadowFilter = TSL.VSMShadowFilter;
|
||||
export const V_GGX_SmithCorrelated = TSL.V_GGX_SmithCorrelated;
|
||||
export const abs = TSL.abs;
|
||||
export const acesFilmicToneMapping = TSL.acesFilmicToneMapping;
|
||||
export const acos = TSL.acos;
|
||||
export const add = TSL.add;
|
||||
export const addNodeElement = TSL.addNodeElement;
|
||||
export const agxToneMapping = TSL.agxToneMapping;
|
||||
export const all = TSL.all;
|
||||
export const alphaT = TSL.alphaT;
|
||||
export const and = TSL.and;
|
||||
export const anisotropy = TSL.anisotropy;
|
||||
export const anisotropyB = TSL.anisotropyB;
|
||||
export const anisotropyT = TSL.anisotropyT;
|
||||
export const any = TSL.any;
|
||||
export const append = TSL.append;
|
||||
export const array = TSL.array;
|
||||
export const arrayBuffer = TSL.arrayBuffer;
|
||||
export const asin = TSL.asin;
|
||||
export const assign = TSL.assign;
|
||||
export const atan = TSL.atan;
|
||||
export const atan2 = TSL.atan2;
|
||||
export const atomicAdd = TSL.atomicAdd;
|
||||
export const atomicAnd = TSL.atomicAnd;
|
||||
export const atomicFunc = TSL.atomicFunc;
|
||||
export const atomicMax = TSL.atomicMax;
|
||||
export const atomicMin = TSL.atomicMin;
|
||||
export const atomicOr = TSL.atomicOr;
|
||||
export const atomicStore = TSL.atomicStore;
|
||||
export const atomicSub = TSL.atomicSub;
|
||||
export const atomicXor = TSL.atomicXor;
|
||||
export const atomicLoad = TSL.atomicLoad;
|
||||
export const attenuationColor = TSL.attenuationColor;
|
||||
export const attenuationDistance = TSL.attenuationDistance;
|
||||
export const attribute = TSL.attribute;
|
||||
export const attributeArray = TSL.attributeArray;
|
||||
export const backgroundBlurriness = TSL.backgroundBlurriness;
|
||||
export const backgroundIntensity = TSL.backgroundIntensity;
|
||||
export const backgroundRotation = TSL.backgroundRotation;
|
||||
export const batch = TSL.batch;
|
||||
export const bentNormalView = TSL.bentNormalView;
|
||||
export const billboarding = TSL.billboarding;
|
||||
export const bitAnd = TSL.bitAnd;
|
||||
export const bitNot = TSL.bitNot;
|
||||
export const bitOr = TSL.bitOr;
|
||||
export const bitXor = TSL.bitXor;
|
||||
export const bitangentGeometry = TSL.bitangentGeometry;
|
||||
export const bitangentLocal = TSL.bitangentLocal;
|
||||
export const bitangentView = TSL.bitangentView;
|
||||
export const bitangentWorld = TSL.bitangentWorld;
|
||||
export const bitcast = TSL.bitcast;
|
||||
export const blendBurn = TSL.blendBurn;
|
||||
export const blendColor = TSL.blendColor;
|
||||
export const blendDodge = TSL.blendDodge;
|
||||
export const blendOverlay = TSL.blendOverlay;
|
||||
export const blendScreen = TSL.blendScreen;
|
||||
export const blur = TSL.blur;
|
||||
export const bool = TSL.bool;
|
||||
export const buffer = TSL.buffer;
|
||||
export const bufferAttribute = TSL.bufferAttribute;
|
||||
export const bumpMap = TSL.bumpMap;
|
||||
export const burn = TSL.burn;
|
||||
export const bvec2 = TSL.bvec2;
|
||||
export const bvec3 = TSL.bvec3;
|
||||
export const bvec4 = TSL.bvec4;
|
||||
export const bypass = TSL.bypass;
|
||||
export const cache = TSL.cache;
|
||||
export const call = TSL.call;
|
||||
export const cameraFar = TSL.cameraFar;
|
||||
export const cameraIndex = TSL.cameraIndex;
|
||||
export const cameraNear = TSL.cameraNear;
|
||||
export const cameraNormalMatrix = TSL.cameraNormalMatrix;
|
||||
export const cameraPosition = TSL.cameraPosition;
|
||||
export const cameraProjectionMatrix = TSL.cameraProjectionMatrix;
|
||||
export const cameraProjectionMatrixInverse = TSL.cameraProjectionMatrixInverse;
|
||||
export const cameraViewMatrix = TSL.cameraViewMatrix;
|
||||
export const cameraWorldMatrix = TSL.cameraWorldMatrix;
|
||||
export const cbrt = TSL.cbrt;
|
||||
export const cdl = TSL.cdl;
|
||||
export const ceil = TSL.ceil;
|
||||
export const checker = TSL.checker;
|
||||
export const cineonToneMapping = TSL.cineonToneMapping;
|
||||
export const clamp = TSL.clamp;
|
||||
export const clearcoat = TSL.clearcoat;
|
||||
export const clearcoatRoughness = TSL.clearcoatRoughness;
|
||||
export const code = TSL.code;
|
||||
export const color = TSL.color;
|
||||
export const colorSpaceToWorking = TSL.colorSpaceToWorking;
|
||||
export const colorToDirection = TSL.colorToDirection;
|
||||
export const compute = TSL.compute;
|
||||
export const computeSkinning = TSL.computeSkinning;
|
||||
export const cond = TSL.cond;
|
||||
export const Const = TSL.Const;
|
||||
export const context = TSL.context;
|
||||
export const convert = TSL.convert;
|
||||
export const convertColorSpace = TSL.convertColorSpace;
|
||||
export const convertToTexture = TSL.convertToTexture;
|
||||
export const cos = TSL.cos;
|
||||
export const cross = TSL.cross;
|
||||
export const cubeTexture = TSL.cubeTexture;
|
||||
export const dFdx = TSL.dFdx;
|
||||
export const dFdy = TSL.dFdy;
|
||||
export const dashSize = TSL.dashSize;
|
||||
export const debug = TSL.debug;
|
||||
export const decrement = TSL.decrement;
|
||||
export const decrementBefore = TSL.decrementBefore;
|
||||
export const defaultBuildStages = TSL.defaultBuildStages;
|
||||
export const defaultShaderStages = TSL.defaultShaderStages;
|
||||
export const defined = TSL.defined;
|
||||
export const degrees = TSL.degrees;
|
||||
export const deltaTime = TSL.deltaTime;
|
||||
export const densityFog = TSL.densityFog;
|
||||
export const densityFogFactor = TSL.densityFogFactor;
|
||||
export const depth = TSL.depth;
|
||||
export const depthPass = TSL.depthPass;
|
||||
export const difference = TSL.difference;
|
||||
export const diffuseColor = TSL.diffuseColor;
|
||||
export const directPointLight = TSL.directPointLight;
|
||||
export const directionToColor = TSL.directionToColor;
|
||||
export const dispersion = TSL.dispersion;
|
||||
export const distance = TSL.distance;
|
||||
export const div = TSL.div;
|
||||
export const dodge = TSL.dodge;
|
||||
export const dot = TSL.dot;
|
||||
export const drawIndex = TSL.drawIndex;
|
||||
export const dynamicBufferAttribute = TSL.dynamicBufferAttribute;
|
||||
export const element = TSL.element;
|
||||
export const emissive = TSL.emissive;
|
||||
export const equal = TSL.equal;
|
||||
export const equals = TSL.equals;
|
||||
export const equirectUV = TSL.equirectUV;
|
||||
export const exp = TSL.exp;
|
||||
export const exp2 = TSL.exp2;
|
||||
export const expression = TSL.expression;
|
||||
export const faceDirection = TSL.faceDirection;
|
||||
export const faceForward = TSL.faceForward;
|
||||
export const faceforward = TSL.faceforward;
|
||||
export const float = TSL.float;
|
||||
export const floor = TSL.floor;
|
||||
export const fog = TSL.fog;
|
||||
export const fract = TSL.fract;
|
||||
export const frameGroup = TSL.frameGroup;
|
||||
export const frameId = TSL.frameId;
|
||||
export const frontFacing = TSL.frontFacing;
|
||||
export const fwidth = TSL.fwidth;
|
||||
export const gain = TSL.gain;
|
||||
export const gapSize = TSL.gapSize;
|
||||
export const getConstNodeType = TSL.getConstNodeType;
|
||||
export const getCurrentStack = TSL.getCurrentStack;
|
||||
export const getDirection = TSL.getDirection;
|
||||
export const getDistanceAttenuation = TSL.getDistanceAttenuation;
|
||||
export const getGeometryRoughness = TSL.getGeometryRoughness;
|
||||
export const getNormalFromDepth = TSL.getNormalFromDepth;
|
||||
export const getParallaxCorrectNormal = TSL.getParallaxCorrectNormal;
|
||||
export const getRoughness = TSL.getRoughness;
|
||||
export const getScreenPosition = TSL.getScreenPosition;
|
||||
export const getShIrradianceAt = TSL.getShIrradianceAt;
|
||||
export const getTextureIndex = TSL.getTextureIndex;
|
||||
export const getViewPosition = TSL.getViewPosition;
|
||||
export const getShadowMaterial = TSL.getShadowMaterial;
|
||||
export const getShadowRenderObjectFunction = TSL.getShadowRenderObjectFunction;
|
||||
export const glsl = TSL.glsl;
|
||||
export const glslFn = TSL.glslFn;
|
||||
export const grayscale = TSL.grayscale;
|
||||
export const greaterThan = TSL.greaterThan;
|
||||
export const greaterThanEqual = TSL.greaterThanEqual;
|
||||
export const hash = TSL.hash;
|
||||
export const highpModelNormalViewMatrix = TSL.highpModelNormalViewMatrix;
|
||||
export const highpModelViewMatrix = TSL.highpModelViewMatrix;
|
||||
export const hue = TSL.hue;
|
||||
export const increment = TSL.increment;
|
||||
export const incrementBefore = TSL.incrementBefore;
|
||||
export const instance = TSL.instance;
|
||||
export const instanceIndex = TSL.instanceIndex;
|
||||
export const instancedArray = TSL.instancedArray;
|
||||
export const instancedBufferAttribute = TSL.instancedBufferAttribute;
|
||||
export const instancedDynamicBufferAttribute = TSL.instancedDynamicBufferAttribute;
|
||||
export const instancedMesh = TSL.instancedMesh;
|
||||
export const int = TSL.int;
|
||||
export const inverseSqrt = TSL.inverseSqrt;
|
||||
export const inversesqrt = TSL.inversesqrt;
|
||||
export const invocationLocalIndex = TSL.invocationLocalIndex;
|
||||
export const invocationSubgroupIndex = TSL.invocationSubgroupIndex;
|
||||
export const ior = TSL.ior;
|
||||
export const iridescence = TSL.iridescence;
|
||||
export const iridescenceIOR = TSL.iridescenceIOR;
|
||||
export const iridescenceThickness = TSL.iridescenceThickness;
|
||||
export const ivec2 = TSL.ivec2;
|
||||
export const ivec3 = TSL.ivec3;
|
||||
export const ivec4 = TSL.ivec4;
|
||||
export const js = TSL.js;
|
||||
export const label = TSL.label;
|
||||
export const length = TSL.length;
|
||||
export const lengthSq = TSL.lengthSq;
|
||||
export const lessThan = TSL.lessThan;
|
||||
export const lessThanEqual = TSL.lessThanEqual;
|
||||
export const lightPosition = TSL.lightPosition;
|
||||
export const lightShadowMatrix = TSL.lightShadowMatrix;
|
||||
export const lightTargetDirection = TSL.lightTargetDirection;
|
||||
export const lightTargetPosition = TSL.lightTargetPosition;
|
||||
export const lightViewPosition = TSL.lightViewPosition;
|
||||
export const lightingContext = TSL.lightingContext;
|
||||
export const lights = TSL.lights;
|
||||
export const linearDepth = TSL.linearDepth;
|
||||
export const linearToneMapping = TSL.linearToneMapping;
|
||||
export const localId = TSL.localId;
|
||||
export const globalId = TSL.globalId;
|
||||
export const log = TSL.log;
|
||||
export const log2 = TSL.log2;
|
||||
export const logarithmicDepthToViewZ = TSL.logarithmicDepthToViewZ;
|
||||
export const loop = TSL.loop;
|
||||
export const luminance = TSL.luminance;
|
||||
export const mediumpModelViewMatrix = TSL.mediumpModelViewMatrix;
|
||||
export const mat2 = TSL.mat2;
|
||||
export const mat3 = TSL.mat3;
|
||||
export const mat4 = TSL.mat4;
|
||||
export const matcapUV = TSL.matcapUV;
|
||||
export const materialAO = TSL.materialAO;
|
||||
export const materialAlphaTest = TSL.materialAlphaTest;
|
||||
export const materialAnisotropy = TSL.materialAnisotropy;
|
||||
export const materialAnisotropyVector = TSL.materialAnisotropyVector;
|
||||
export const materialAttenuationColor = TSL.materialAttenuationColor;
|
||||
export const materialAttenuationDistance = TSL.materialAttenuationDistance;
|
||||
export const materialClearcoat = TSL.materialClearcoat;
|
||||
export const materialClearcoatNormal = TSL.materialClearcoatNormal;
|
||||
export const materialClearcoatRoughness = TSL.materialClearcoatRoughness;
|
||||
export const materialColor = TSL.materialColor;
|
||||
export const materialDispersion = TSL.materialDispersion;
|
||||
export const materialEmissive = TSL.materialEmissive;
|
||||
export const materialIOR = TSL.materialIOR;
|
||||
export const materialIridescence = TSL.materialIridescence;
|
||||
export const materialIridescenceIOR = TSL.materialIridescenceIOR;
|
||||
export const materialIridescenceThickness = TSL.materialIridescenceThickness;
|
||||
export const materialLightMap = TSL.materialLightMap;
|
||||
export const materialLineDashOffset = TSL.materialLineDashOffset;
|
||||
export const materialLineDashSize = TSL.materialLineDashSize;
|
||||
export const materialLineGapSize = TSL.materialLineGapSize;
|
||||
export const materialLineScale = TSL.materialLineScale;
|
||||
export const materialLineWidth = TSL.materialLineWidth;
|
||||
export const materialMetalness = TSL.materialMetalness;
|
||||
export const materialNormal = TSL.materialNormal;
|
||||
export const materialOpacity = TSL.materialOpacity;
|
||||
export const materialPointSize = TSL.materialPointSize;
|
||||
export const materialReference = TSL.materialReference;
|
||||
export const materialReflectivity = TSL.materialReflectivity;
|
||||
export const materialRefractionRatio = TSL.materialRefractionRatio;
|
||||
export const materialRotation = TSL.materialRotation;
|
||||
export const materialRoughness = TSL.materialRoughness;
|
||||
export const materialSheen = TSL.materialSheen;
|
||||
export const materialSheenRoughness = TSL.materialSheenRoughness;
|
||||
export const materialShininess = TSL.materialShininess;
|
||||
export const materialSpecular = TSL.materialSpecular;
|
||||
export const materialSpecularColor = TSL.materialSpecularColor;
|
||||
export const materialSpecularIntensity = TSL.materialSpecularIntensity;
|
||||
export const materialSpecularStrength = TSL.materialSpecularStrength;
|
||||
export const materialThickness = TSL.materialThickness;
|
||||
export const materialTransmission = TSL.materialTransmission;
|
||||
export const max = TSL.max;
|
||||
export const maxMipLevel = TSL.maxMipLevel;
|
||||
export const metalness = TSL.metalness;
|
||||
export const min = TSL.min;
|
||||
export const mix = TSL.mix;
|
||||
export const mixElement = TSL.mixElement;
|
||||
export const mod = TSL.mod;
|
||||
export const modInt = TSL.modInt;
|
||||
export const modelDirection = TSL.modelDirection;
|
||||
export const modelNormalMatrix = TSL.modelNormalMatrix;
|
||||
export const modelPosition = TSL.modelPosition;
|
||||
export const modelRadius = TSL.modelRadius;
|
||||
export const modelScale = TSL.modelScale;
|
||||
export const modelViewMatrix = TSL.modelViewMatrix;
|
||||
export const modelViewPosition = TSL.modelViewPosition;
|
||||
export const modelViewProjection = TSL.modelViewProjection;
|
||||
export const modelWorldMatrix = TSL.modelWorldMatrix;
|
||||
export const modelWorldMatrixInverse = TSL.modelWorldMatrixInverse;
|
||||
export const morphReference = TSL.morphReference;
|
||||
export const mrt = TSL.mrt;
|
||||
export const mul = TSL.mul;
|
||||
export const mx_aastep = TSL.mx_aastep;
|
||||
export const mx_cell_noise_float = TSL.mx_cell_noise_float;
|
||||
export const mx_contrast = TSL.mx_contrast;
|
||||
export const mx_fractal_noise_float = TSL.mx_fractal_noise_float;
|
||||
export const mx_fractal_noise_vec2 = TSL.mx_fractal_noise_vec2;
|
||||
export const mx_fractal_noise_vec3 = TSL.mx_fractal_noise_vec3;
|
||||
export const mx_fractal_noise_vec4 = TSL.mx_fractal_noise_vec4;
|
||||
export const mx_hsvtorgb = TSL.mx_hsvtorgb;
|
||||
export const mx_noise_float = TSL.mx_noise_float;
|
||||
export const mx_noise_vec3 = TSL.mx_noise_vec3;
|
||||
export const mx_noise_vec4 = TSL.mx_noise_vec4;
|
||||
export const mx_ramplr = TSL.mx_ramplr;
|
||||
export const mx_ramptb = TSL.mx_ramptb;
|
||||
export const mx_rgbtohsv = TSL.mx_rgbtohsv;
|
||||
export const mx_safepower = TSL.mx_safepower;
|
||||
export const mx_splitlr = TSL.mx_splitlr;
|
||||
export const mx_splittb = TSL.mx_splittb;
|
||||
export const mx_srgb_texture_to_lin_rec709 = TSL.mx_srgb_texture_to_lin_rec709;
|
||||
export const mx_transform_uv = TSL.mx_transform_uv;
|
||||
export const mx_worley_noise_float = TSL.mx_worley_noise_float;
|
||||
export const mx_worley_noise_vec2 = TSL.mx_worley_noise_vec2;
|
||||
export const mx_worley_noise_vec3 = TSL.mx_worley_noise_vec3;
|
||||
export const negate = TSL.negate;
|
||||
export const neutralToneMapping = TSL.neutralToneMapping;
|
||||
export const nodeArray = TSL.nodeArray;
|
||||
export const nodeImmutable = TSL.nodeImmutable;
|
||||
export const nodeObject = TSL.nodeObject;
|
||||
export const nodeObjects = TSL.nodeObjects;
|
||||
export const nodeProxy = TSL.nodeProxy;
|
||||
export const normalFlat = TSL.normalFlat;
|
||||
export const normalGeometry = TSL.normalGeometry;
|
||||
export const normalLocal = TSL.normalLocal;
|
||||
export const normalMap = TSL.normalMap;
|
||||
export const normalView = TSL.normalView;
|
||||
export const normalViewGeometry = TSL.normalViewGeometry;
|
||||
export const normalWorld = TSL.normalWorld;
|
||||
export const normalWorldGeometry = TSL.normalWorldGeometry;
|
||||
export const normalize = TSL.normalize;
|
||||
export const not = TSL.not;
|
||||
export const notEqual = TSL.notEqual;
|
||||
export const numWorkgroups = TSL.numWorkgroups;
|
||||
export const objectDirection = TSL.objectDirection;
|
||||
export const objectGroup = TSL.objectGroup;
|
||||
export const objectPosition = TSL.objectPosition;
|
||||
export const objectRadius = TSL.objectRadius;
|
||||
export const objectScale = TSL.objectScale;
|
||||
export const objectViewPosition = TSL.objectViewPosition;
|
||||
export const objectWorldMatrix = TSL.objectWorldMatrix;
|
||||
export const oneMinus = TSL.oneMinus;
|
||||
export const or = TSL.or;
|
||||
export const orthographicDepthToViewZ = TSL.orthographicDepthToViewZ;
|
||||
export const oscSawtooth = TSL.oscSawtooth;
|
||||
export const oscSine = TSL.oscSine;
|
||||
export const oscSquare = TSL.oscSquare;
|
||||
export const oscTriangle = TSL.oscTriangle;
|
||||
export const output = TSL.output;
|
||||
export const outputStruct = TSL.outputStruct;
|
||||
export const overlay = TSL.overlay;
|
||||
export const overloadingFn = TSL.overloadingFn;
|
||||
export const parabola = TSL.parabola;
|
||||
export const parallaxDirection = TSL.parallaxDirection;
|
||||
export const parallaxUV = TSL.parallaxUV;
|
||||
export const parameter = TSL.parameter;
|
||||
export const pass = TSL.pass;
|
||||
export const passTexture = TSL.passTexture;
|
||||
export const pcurve = TSL.pcurve;
|
||||
export const perspectiveDepthToViewZ = TSL.perspectiveDepthToViewZ;
|
||||
export const pmremTexture = TSL.pmremTexture;
|
||||
export const pointUV = TSL.pointUV;
|
||||
export const pointWidth = TSL.pointWidth;
|
||||
export const positionGeometry = TSL.positionGeometry;
|
||||
export const positionLocal = TSL.positionLocal;
|
||||
export const positionPrevious = TSL.positionPrevious;
|
||||
export const positionView = TSL.positionView;
|
||||
export const positionViewDirection = TSL.positionViewDirection;
|
||||
export const positionWorld = TSL.positionWorld;
|
||||
export const positionWorldDirection = TSL.positionWorldDirection;
|
||||
export const posterize = TSL.posterize;
|
||||
export const pow = TSL.pow;
|
||||
export const pow2 = TSL.pow2;
|
||||
export const pow3 = TSL.pow3;
|
||||
export const pow4 = TSL.pow4;
|
||||
export const premultiplyAlpha = TSL.premultiplyAlpha;
|
||||
export const property = TSL.property;
|
||||
export const radians = TSL.radians;
|
||||
export const rand = TSL.rand;
|
||||
export const range = TSL.range;
|
||||
export const rangeFog = TSL.rangeFog;
|
||||
export const rangeFogFactor = TSL.rangeFogFactor;
|
||||
export const reciprocal = TSL.reciprocal;
|
||||
export const lightProjectionUV = TSL.lightProjectionUV;
|
||||
export const reference = TSL.reference;
|
||||
export const referenceBuffer = TSL.referenceBuffer;
|
||||
export const reflect = TSL.reflect;
|
||||
export const reflectVector = TSL.reflectVector;
|
||||
export const reflectView = TSL.reflectView;
|
||||
export const reflector = TSL.reflector;
|
||||
export const refract = TSL.refract;
|
||||
export const refractVector = TSL.refractVector;
|
||||
export const refractView = TSL.refractView;
|
||||
export const reinhardToneMapping = TSL.reinhardToneMapping;
|
||||
export const remainder = TSL.remainder;
|
||||
export const remap = TSL.remap;
|
||||
export const remapClamp = TSL.remapClamp;
|
||||
export const renderGroup = TSL.renderGroup;
|
||||
export const renderOutput = TSL.renderOutput;
|
||||
export const rendererReference = TSL.rendererReference;
|
||||
export const rotate = TSL.rotate;
|
||||
export const rotateUV = TSL.rotateUV;
|
||||
export const roughness = TSL.roughness;
|
||||
export const round = TSL.round;
|
||||
export const rtt = TSL.rtt;
|
||||
export const sRGBTransferEOTF = TSL.sRGBTransferEOTF;
|
||||
export const sRGBTransferOETF = TSL.sRGBTransferOETF;
|
||||
export const sample = TSL.sample;
|
||||
export const sampler = TSL.sampler;
|
||||
export const samplerComparison = TSL.samplerComparison;
|
||||
export const saturate = TSL.saturate;
|
||||
export const saturation = TSL.saturation;
|
||||
export const screen = TSL.screen;
|
||||
export const screenCoordinate = TSL.screenCoordinate;
|
||||
export const screenSize = TSL.screenSize;
|
||||
export const screenUV = TSL.screenUV;
|
||||
export const scriptable = TSL.scriptable;
|
||||
export const scriptableValue = TSL.scriptableValue;
|
||||
export const select = TSL.select;
|
||||
export const setCurrentStack = TSL.setCurrentStack;
|
||||
export const shaderStages = TSL.shaderStages;
|
||||
export const shadow = TSL.shadow;
|
||||
export const pointShadow = TSL.pointShadow;
|
||||
export const shadowPositionWorld = TSL.shadowPositionWorld;
|
||||
export const sharedUniformGroup = TSL.sharedUniformGroup;
|
||||
export const shapeCircle = TSL.shapeCircle;
|
||||
export const sheen = TSL.sheen;
|
||||
export const sheenRoughness = TSL.sheenRoughness;
|
||||
export const shiftLeft = TSL.shiftLeft;
|
||||
export const shiftRight = TSL.shiftRight;
|
||||
export const shininess = TSL.shininess;
|
||||
export const sign = TSL.sign;
|
||||
export const sin = TSL.sin;
|
||||
export const sinc = TSL.sinc;
|
||||
export const skinning = TSL.skinning;
|
||||
export const smoothstep = TSL.smoothstep;
|
||||
export const smoothstepElement = TSL.smoothstepElement;
|
||||
export const specularColor = TSL.specularColor;
|
||||
export const specularF90 = TSL.specularF90;
|
||||
export const spherizeUV = TSL.spherizeUV;
|
||||
export const split = TSL.split;
|
||||
export const spritesheetUV = TSL.spritesheetUV;
|
||||
export const sqrt = TSL.sqrt;
|
||||
export const stack = TSL.stack;
|
||||
export const step = TSL.step;
|
||||
export const storage = TSL.storage;
|
||||
export const storageBarrier = TSL.storageBarrier;
|
||||
export const storageObject = TSL.storageObject;
|
||||
export const storageTexture = TSL.storageTexture;
|
||||
export const string = TSL.string;
|
||||
export const struct = TSL.struct;
|
||||
export const sub = TSL.sub;
|
||||
export const subBuild = TSL.subBuild;
|
||||
export const subgroupIndex = TSL.subgroupIndex;
|
||||
export const subgroupSize = TSL.subgroupSize;
|
||||
export const tan = TSL.tan;
|
||||
export const tangentGeometry = TSL.tangentGeometry;
|
||||
export const tangentLocal = TSL.tangentLocal;
|
||||
export const tangentView = TSL.tangentView;
|
||||
export const tangentWorld = TSL.tangentWorld;
|
||||
export const temp = TSL.temp;
|
||||
export const texture = TSL.texture;
|
||||
export const texture3D = TSL.texture3D;
|
||||
export const textureBarrier = TSL.textureBarrier;
|
||||
export const textureBicubic = TSL.textureBicubic;
|
||||
export const textureBicubicLevel = TSL.textureBicubicLevel;
|
||||
export const textureCubeUV = TSL.textureCubeUV;
|
||||
export const textureLoad = TSL.textureLoad;
|
||||
export const textureSize = TSL.textureSize;
|
||||
export const textureStore = TSL.textureStore;
|
||||
export const thickness = TSL.thickness;
|
||||
export const time = TSL.time;
|
||||
export const timerDelta = TSL.timerDelta;
|
||||
export const timerGlobal = TSL.timerGlobal;
|
||||
export const timerLocal = TSL.timerLocal;
|
||||
export const toneMapping = TSL.toneMapping;
|
||||
export const toneMappingExposure = TSL.toneMappingExposure;
|
||||
export const toonOutlinePass = TSL.toonOutlinePass;
|
||||
export const transformDirection = TSL.transformDirection;
|
||||
export const transformNormal = TSL.transformNormal;
|
||||
export const transformNormalToView = TSL.transformNormalToView;
|
||||
export const transformedClearcoatNormalView = TSL.transformedClearcoatNormalView;
|
||||
export const transformedNormalView = TSL.transformedNormalView;
|
||||
export const transformedNormalWorld = TSL.transformedNormalWorld;
|
||||
export const transmission = TSL.transmission;
|
||||
export const transpose = TSL.transpose;
|
||||
export const triNoise3D = TSL.triNoise3D;
|
||||
export const triplanarTexture = TSL.triplanarTexture;
|
||||
export const triplanarTextures = TSL.triplanarTextures;
|
||||
export const trunc = TSL.trunc;
|
||||
export const tslFn = TSL.tslFn;
|
||||
export const uint = TSL.uint;
|
||||
export const uniform = TSL.uniform;
|
||||
export const uniformCubeTexture = TSL.uniformCubeTexture;
|
||||
export const uniformArray = TSL.uniformArray;
|
||||
export const uniformGroup = TSL.uniformGroup;
|
||||
export const uniformTexture = TSL.uniformTexture;
|
||||
export const uniforms = TSL.uniforms;
|
||||
export const unpremultiplyAlpha = TSL.unpremultiplyAlpha;
|
||||
export const userData = TSL.userData;
|
||||
export const uv = TSL.uv;
|
||||
export const uvec2 = TSL.uvec2;
|
||||
export const uvec3 = TSL.uvec3;
|
||||
export const uvec4 = TSL.uvec4;
|
||||
export const Var = TSL.Var;
|
||||
export const varying = TSL.varying;
|
||||
export const varyingProperty = TSL.varyingProperty;
|
||||
export const vec2 = TSL.vec2;
|
||||
export const vec3 = TSL.vec3;
|
||||
export const vec4 = TSL.vec4;
|
||||
export const vectorComponents = TSL.vectorComponents;
|
||||
export const velocity = TSL.velocity;
|
||||
export const vertexColor = TSL.vertexColor;
|
||||
export const vertexIndex = TSL.vertexIndex;
|
||||
export const vibrance = TSL.vibrance;
|
||||
export const viewZToLogarithmicDepth = TSL.viewZToLogarithmicDepth;
|
||||
export const viewZToOrthographicDepth = TSL.viewZToOrthographicDepth;
|
||||
export const viewZToPerspectiveDepth = TSL.viewZToPerspectiveDepth;
|
||||
export const viewport = TSL.viewport;
|
||||
export const viewportBottomLeft = TSL.viewportBottomLeft;
|
||||
export const viewportCoordinate = TSL.viewportCoordinate;
|
||||
export const viewportDepthTexture = TSL.viewportDepthTexture;
|
||||
export const viewportLinearDepth = TSL.viewportLinearDepth;
|
||||
export const viewportMipTexture = TSL.viewportMipTexture;
|
||||
export const viewportResolution = TSL.viewportResolution;
|
||||
export const viewportSafeUV = TSL.viewportSafeUV;
|
||||
export const viewportSharedTexture = TSL.viewportSharedTexture;
|
||||
export const viewportSize = TSL.viewportSize;
|
||||
export const viewportTexture = TSL.viewportTexture;
|
||||
export const viewportTopLeft = TSL.viewportTopLeft;
|
||||
export const viewportUV = TSL.viewportUV;
|
||||
export const wgsl = TSL.wgsl;
|
||||
export const wgslFn = TSL.wgslFn;
|
||||
export const workgroupArray = TSL.workgroupArray;
|
||||
export const workgroupBarrier = TSL.workgroupBarrier;
|
||||
export const workgroupId = TSL.workgroupId;
|
||||
export const workingToColorSpace = TSL.workingToColorSpace;
|
||||
export const xor = TSL.xor;
|
||||
24
app/node_modules/three/src/Three.WebGPU.Nodes.js
generated
vendored
Normal file
24
app/node_modules/three/src/Three.WebGPU.Nodes.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
export * from './Three.Core.js';
|
||||
|
||||
export * from './materials/nodes/NodeMaterials.js';
|
||||
export { default as WebGPURenderer } from './renderers/webgpu/WebGPURenderer.Nodes.js';
|
||||
export { default as Lighting } from './renderers/common/Lighting.js';
|
||||
export { default as BundleGroup } from './renderers/common/BundleGroup.js';
|
||||
export { default as QuadMesh } from './renderers/common/QuadMesh.js';
|
||||
export { default as PMREMGenerator } from './renderers/common/extras/PMREMGenerator.js';
|
||||
export { default as PostProcessing } from './renderers/common/PostProcessing.js';
|
||||
import * as RendererUtils from './renderers/common/RendererUtils.js';
|
||||
export { RendererUtils };
|
||||
export { default as StorageTexture } from './renderers/common/StorageTexture.js';
|
||||
export { default as StorageBufferAttribute } from './renderers/common/StorageBufferAttribute.js';
|
||||
export { default as StorageInstancedBufferAttribute } from './renderers/common/StorageInstancedBufferAttribute.js';
|
||||
export { default as IndirectStorageBufferAttribute } from './renderers/common/IndirectStorageBufferAttribute.js';
|
||||
export { default as IESSpotLight } from './lights/webgpu/IESSpotLight.js';
|
||||
export { default as ProjectorLight } from './lights/webgpu/ProjectorLight.js';
|
||||
export { default as NodeLoader } from './loaders/nodes/NodeLoader.js';
|
||||
export { default as NodeObjectLoader } from './loaders/nodes/NodeObjectLoader.js';
|
||||
export { default as NodeMaterialLoader } from './loaders/nodes/NodeMaterialLoader.js';
|
||||
export { ClippingGroup } from './objects/ClippingGroup.js';
|
||||
export * from './nodes/Nodes.js';
|
||||
import * as TSL from './nodes/TSL.js';
|
||||
export { TSL };
|
||||
26
app/node_modules/three/src/Three.WebGPU.js
generated
vendored
Normal file
26
app/node_modules/three/src/Three.WebGPU.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
export * from './Three.Core.js';
|
||||
|
||||
export * from './materials/nodes/NodeMaterials.js';
|
||||
export { default as WebGPURenderer } from './renderers/webgpu/WebGPURenderer.js';
|
||||
export { default as Lighting } from './renderers/common/Lighting.js';
|
||||
export { default as BundleGroup } from './renderers/common/BundleGroup.js';
|
||||
export { default as QuadMesh } from './renderers/common/QuadMesh.js';
|
||||
export { default as PMREMGenerator } from './renderers/common/extras/PMREMGenerator.js';
|
||||
export { default as PostProcessing } from './renderers/common/PostProcessing.js';
|
||||
import * as RendererUtils from './renderers/common/RendererUtils.js';
|
||||
export { RendererUtils };
|
||||
export { default as StorageTexture } from './renderers/common/StorageTexture.js';
|
||||
export { default as Storage3DTexture } from './renderers/common/Storage3DTexture.js';
|
||||
export { default as StorageArrayTexture } from './renderers/common/StorageArrayTexture.js';
|
||||
export { default as StorageBufferAttribute } from './renderers/common/StorageBufferAttribute.js';
|
||||
export { default as StorageInstancedBufferAttribute } from './renderers/common/StorageInstancedBufferAttribute.js';
|
||||
export { default as IndirectStorageBufferAttribute } from './renderers/common/IndirectStorageBufferAttribute.js';
|
||||
export { default as IESSpotLight } from './lights/webgpu/IESSpotLight.js';
|
||||
export { default as ProjectorLight } from './lights/webgpu/ProjectorLight.js';
|
||||
export { default as NodeLoader } from './loaders/nodes/NodeLoader.js';
|
||||
export { default as NodeObjectLoader } from './loaders/nodes/NodeObjectLoader.js';
|
||||
export { default as NodeMaterialLoader } from './loaders/nodes/NodeMaterialLoader.js';
|
||||
export { ClippingGroup } from './objects/ClippingGroup.js';
|
||||
export * from './nodes/Nodes.js';
|
||||
import * as TSL from './nodes/TSL.js';
|
||||
export { TSL };
|
||||
9
app/node_modules/three/src/Three.js
generated
vendored
Normal file
9
app/node_modules/three/src/Three.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export * from './Three.Core.js';
|
||||
|
||||
export { WebGLRenderer } from './renderers/WebGLRenderer.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 { PMREMGenerator } from './extras/PMREMGenerator.js';
|
||||
export { WebGLUtils } from './renderers/webgl/WebGLUtils.js';
|
||||
932
app/node_modules/three/src/animation/AnimationAction.js
generated
vendored
Normal file
932
app/node_modules/three/src/animation/AnimationAction.js
generated
vendored
Normal file
@@ -0,0 +1,932 @@
|
||||
import { WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, LoopPingPong, LoopOnce, LoopRepeat, NormalAnimationBlendMode, AdditiveAnimationBlendMode } from '../constants.js';
|
||||
|
||||
/**
|
||||
* An instance of `AnimationAction` schedules the playback of an animation which is
|
||||
* stored in {@link AnimationClip}.
|
||||
*/
|
||||
class AnimationAction {
|
||||
|
||||
/**
|
||||
* Constructs a new animation action.
|
||||
*
|
||||
* @param {AnimationMixer} mixer - The mixer that is controlled by this action.
|
||||
* @param {AnimationClip} clip - The animation clip that holds the actual keyframes.
|
||||
* @param {?Object3D} [localRoot=null] - The root object on which this action is performed.
|
||||
* @param {(NormalAnimationBlendMode|AdditiveAnimationBlendMode)} [blendMode] - The blend mode.
|
||||
*/
|
||||
constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
|
||||
|
||||
this._mixer = mixer;
|
||||
this._clip = clip;
|
||||
this._localRoot = localRoot;
|
||||
|
||||
/**
|
||||
* Defines how the animation is blended/combined when two or more animations
|
||||
* are simultaneously played.
|
||||
*
|
||||
* @type {(NormalAnimationBlendMode|AdditiveAnimationBlendMode)}
|
||||
*/
|
||||
this.blendMode = blendMode;
|
||||
|
||||
const tracks = clip.tracks,
|
||||
nTracks = tracks.length,
|
||||
interpolants = new Array( nTracks );
|
||||
|
||||
const interpolantSettings = {
|
||||
endingStart: ZeroCurvatureEnding,
|
||||
endingEnd: ZeroCurvatureEnding
|
||||
};
|
||||
|
||||
for ( let i = 0; i !== nTracks; ++ i ) {
|
||||
|
||||
const 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;
|
||||
|
||||
/**
|
||||
* The loop mode, set via {@link AnimationAction#setLoop}.
|
||||
*
|
||||
* @type {(LoopRepeat|LoopOnce|LoopPingPong)}
|
||||
* @default LoopRepeat
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* The local time of this action (in seconds, starting with `0`).
|
||||
*
|
||||
* The value gets clamped or wrapped to `[0,clip.duration]` (according to the
|
||||
* loop state).
|
||||
*
|
||||
* @type {number}
|
||||
* @default Infinity
|
||||
*/
|
||||
this.time = 0;
|
||||
|
||||
/**
|
||||
* Scaling factor for the {@link AnimationAction#time}. A value of `0` causes the
|
||||
* animation to pause. Negative values cause the animation to play backwards.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.timeScale = 1;
|
||||
this._effectiveTimeScale = 1;
|
||||
|
||||
/**
|
||||
* The degree of influence of this action (in the interval `[0, 1]`). Values
|
||||
* between `0` (no impact) and `1` (full impact) can be used to blend between
|
||||
* several actions.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.weight = 1;
|
||||
this._effectiveWeight = 1;
|
||||
|
||||
/**
|
||||
* The number of repetitions of the performed clip over the course of this action.
|
||||
* Can be set via {@link AnimationAction#setLoop}.
|
||||
*
|
||||
* Setting this number has no effect if {@link AnimationAction#loop} is set to
|
||||
* `THREE:LoopOnce`.
|
||||
*
|
||||
* @type {number}
|
||||
* @default Infinity
|
||||
*/
|
||||
this.repetitions = Infinity;
|
||||
|
||||
/**
|
||||
* If set to `true`, the playback of the action is paused.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.paused = false;
|
||||
|
||||
/**
|
||||
* If set to `false`, the action is disabled so it has no impact.
|
||||
*
|
||||
* When the action is re-enabled, the animation continues from its current
|
||||
* time (setting `enabled` to `false` doesn't reset the action).
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.enabled = true;
|
||||
|
||||
/**
|
||||
* If set to true the animation will automatically be paused on its last frame.
|
||||
*
|
||||
* If set to false, {@link AnimationAction#enabled} will automatically be switched
|
||||
* to `false` when the last loop of the action has finished, so that this action has
|
||||
* no further impact.
|
||||
*
|
||||
* Note: This member has no impact if the action is interrupted (it
|
||||
* has only an effect if its last loop has really finished).
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.clampWhenFinished = false;
|
||||
|
||||
/**
|
||||
* Enables smooth interpolation without separate clips for start, loop and end.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.zeroSlopeAtStart = true;
|
||||
|
||||
/**
|
||||
* Enables smooth interpolation without separate clips for start, loop and end.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.zeroSlopeAtEnd = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the playback of the animation.
|
||||
*
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
play() {
|
||||
|
||||
this._mixer._activateAction( this );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the playback of the animation.
|
||||
*
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
stop() {
|
||||
|
||||
this._mixer._deactivateAction( this );
|
||||
|
||||
return this.reset();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the playback of the animation.
|
||||
*
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
reset() {
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the animation is running.
|
||||
*
|
||||
* @return {boolean} Whether the animation is running or not.
|
||||
*/
|
||||
isRunning() {
|
||||
|
||||
return this.enabled && ! this.paused && this.timeScale !== 0 &&
|
||||
this._startTime === null && this._mixer._isActiveAction( this );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` when {@link AnimationAction#play} has been called.
|
||||
*
|
||||
* @return {boolean} Whether the animation is scheduled or not.
|
||||
*/
|
||||
isScheduled() {
|
||||
|
||||
return this._mixer._isActiveAction( this );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the time when the animation should start.
|
||||
*
|
||||
* @param {number} time - The start time in seconds.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
startAt( time ) {
|
||||
|
||||
this._startTime = time;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the loop settings for this action.
|
||||
*
|
||||
* @param {(LoopRepeat|LoopOnce|LoopPingPong)} mode - The loop mode.
|
||||
* @param {number} repetitions - The number of repetitions.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
setLoop( mode, repetitions ) {
|
||||
|
||||
this.loop = mode;
|
||||
this.repetitions = repetitions;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the effective weight of this action.
|
||||
*
|
||||
* An action has no effect and thus an effective weight of zero when the
|
||||
* action is disabled.
|
||||
*
|
||||
* @param {number} weight - The weight to set.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
setEffectiveWeight( weight ) {
|
||||
|
||||
this.weight = weight;
|
||||
|
||||
// note: same logic as when updated at runtime
|
||||
this._effectiveWeight = this.enabled ? weight : 0;
|
||||
|
||||
return this.stopFading();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective weight of this action.
|
||||
*
|
||||
* @return {number} The effective weight.
|
||||
*/
|
||||
getEffectiveWeight() {
|
||||
|
||||
return this._effectiveWeight;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fades the animation in by increasing its weight gradually from `0` to `1`,
|
||||
* within the passed time interval.
|
||||
*
|
||||
* @param {number} duration - The duration of the fade.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
fadeIn( duration ) {
|
||||
|
||||
return this._scheduleFading( duration, 0, 1 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fades the animation out by decreasing its weight gradually from `1` to `0`,
|
||||
* within the passed time interval.
|
||||
*
|
||||
* @param {number} duration - The duration of the fade.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
fadeOut( duration ) {
|
||||
|
||||
return this._scheduleFading( duration, 1, 0 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes this action to fade in and the given action to fade out,
|
||||
* within the passed time interval.
|
||||
*
|
||||
* @param {AnimationAction} fadeOutAction - The animation action to fade out.
|
||||
* @param {number} duration - The duration of the fade.
|
||||
* @param {boolean} [warp=false] - Whether warping should be used or not.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
crossFadeFrom( fadeOutAction, duration, warp = false ) {
|
||||
|
||||
fadeOutAction.fadeOut( duration );
|
||||
this.fadeIn( duration );
|
||||
|
||||
if ( warp === true ) {
|
||||
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes this action to fade out and the given action to fade in,
|
||||
* within the passed time interval.
|
||||
*
|
||||
* @param {AnimationAction} fadeInAction - The animation action to fade in.
|
||||
* @param {number} duration - The duration of the fade.
|
||||
* @param {boolean} [warp=false] - Whether warping should be used or not.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
crossFadeTo( fadeInAction, duration, warp = false ) {
|
||||
|
||||
return fadeInAction.crossFadeFrom( this, duration, warp );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops any fading which is applied to this action.
|
||||
*
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
stopFading() {
|
||||
|
||||
const weightInterpolant = this._weightInterpolant;
|
||||
|
||||
if ( weightInterpolant !== null ) {
|
||||
|
||||
this._weightInterpolant = null;
|
||||
this._mixer._takeBackControlInterpolant( weightInterpolant );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the effective time scale of this action.
|
||||
*
|
||||
* An action has no effect and thus an effective time scale of zero when the
|
||||
* action is paused.
|
||||
*
|
||||
* @param {number} timeScale - The time scale to set.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
setEffectiveTimeScale( timeScale ) {
|
||||
|
||||
this.timeScale = timeScale;
|
||||
this._effectiveTimeScale = this.paused ? 0 : timeScale;
|
||||
|
||||
return this.stopWarping();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective time scale of this action.
|
||||
*
|
||||
* @return {number} The effective time scale.
|
||||
*/
|
||||
getEffectiveTimeScale() {
|
||||
|
||||
return this._effectiveTimeScale;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the duration for a single loop of this action.
|
||||
*
|
||||
* @param {number} duration - The duration to set.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
setDuration( duration ) {
|
||||
|
||||
this.timeScale = this._clip.duration / duration;
|
||||
|
||||
return this.stopWarping();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizes this action with the passed other action.
|
||||
*
|
||||
* @param {AnimationAction} action - The action to sync with.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
syncWith( action ) {
|
||||
|
||||
this.time = action.time;
|
||||
this.timeScale = action.timeScale;
|
||||
|
||||
return this.stopWarping();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Decelerates this animation's speed to `0` within the passed time interval.
|
||||
*
|
||||
* @param {number} duration - The duration.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
halt( duration ) {
|
||||
|
||||
return this.warp( this._effectiveTimeScale, 0, duration );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the playback speed, within the passed time interval, by modifying
|
||||
* {@link AnimationAction#timeScale} gradually from `startTimeScale` to
|
||||
* `endTimeScale`.
|
||||
*
|
||||
* @param {number} startTimeScale - The start time scale.
|
||||
* @param {number} endTimeScale - The end time scale.
|
||||
* @param {number} duration - The duration.
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
warp( startTimeScale, endTimeScale, duration ) {
|
||||
|
||||
const mixer = this._mixer,
|
||||
now = mixer.time,
|
||||
timeScale = this.timeScale;
|
||||
|
||||
let interpolant = this._timeScaleInterpolant;
|
||||
|
||||
if ( interpolant === null ) {
|
||||
|
||||
interpolant = mixer._lendControlInterpolant();
|
||||
this._timeScaleInterpolant = interpolant;
|
||||
|
||||
}
|
||||
|
||||
const times = interpolant.parameterPositions,
|
||||
values = interpolant.sampleValues;
|
||||
|
||||
times[ 0 ] = now;
|
||||
times[ 1 ] = now + duration;
|
||||
|
||||
values[ 0 ] = startTimeScale / timeScale;
|
||||
values[ 1 ] = endTimeScale / timeScale;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops any scheduled warping which is applied to this action.
|
||||
*
|
||||
* @return {AnimationAction} A reference to this animation action.
|
||||
*/
|
||||
stopWarping() {
|
||||
|
||||
const timeScaleInterpolant = this._timeScaleInterpolant;
|
||||
|
||||
if ( timeScaleInterpolant !== null ) {
|
||||
|
||||
this._timeScaleInterpolant = null;
|
||||
this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the animation mixer of this animation action.
|
||||
*
|
||||
* @return {AnimationMixer} The animation mixer.
|
||||
*/
|
||||
getMixer() {
|
||||
|
||||
return this._mixer;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the animation clip of this animation action.
|
||||
*
|
||||
* @return {AnimationClip} The animation clip.
|
||||
*/
|
||||
getClip() {
|
||||
|
||||
return this._clip;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root object of this animation action.
|
||||
*
|
||||
* @return {Object3D} The root object.
|
||||
*/
|
||||
getRoot() {
|
||||
|
||||
return this._localRoot || this._mixer._root;
|
||||
|
||||
}
|
||||
|
||||
// Interna
|
||||
|
||||
_update( time, deltaTime, timeDirection, accuIndex ) {
|
||||
|
||||
// called by the mixer
|
||||
|
||||
if ( ! this.enabled ) {
|
||||
|
||||
// call ._updateWeight() to update ._effectiveWeight
|
||||
|
||||
this._updateWeight( time );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
const startTime = this._startTime;
|
||||
|
||||
if ( startTime !== null ) {
|
||||
|
||||
// check for scheduled start of action
|
||||
|
||||
const timeRunning = ( time - startTime ) * timeDirection;
|
||||
if ( timeRunning < 0 || timeDirection === 0 ) {
|
||||
|
||||
deltaTime = 0;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
this._startTime = null; // unschedule
|
||||
deltaTime = timeDirection * timeRunning;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// apply time scale and advance time
|
||||
|
||||
deltaTime *= this._updateTimeScale( time );
|
||||
const clipTime = this._updateTime( deltaTime );
|
||||
|
||||
// note: _updateTime may disable the action resulting in
|
||||
// an effective weight of 0
|
||||
|
||||
const weight = this._updateWeight( time );
|
||||
|
||||
if ( weight > 0 ) {
|
||||
|
||||
const interpolants = this._interpolants;
|
||||
const propertyMixers = this._propertyBindings;
|
||||
|
||||
switch ( this.blendMode ) {
|
||||
|
||||
case AdditiveAnimationBlendMode:
|
||||
|
||||
for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
|
||||
|
||||
interpolants[ j ].evaluate( clipTime );
|
||||
propertyMixers[ j ].accumulateAdditive( weight );
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case NormalAnimationBlendMode:
|
||||
default:
|
||||
|
||||
for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
|
||||
|
||||
interpolants[ j ].evaluate( clipTime );
|
||||
propertyMixers[ j ].accumulate( accuIndex, weight );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_updateWeight( time ) {
|
||||
|
||||
let weight = 0;
|
||||
|
||||
if ( this.enabled ) {
|
||||
|
||||
weight = this.weight;
|
||||
const interpolant = this._weightInterpolant;
|
||||
|
||||
if ( interpolant !== null ) {
|
||||
|
||||
const 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( time ) {
|
||||
|
||||
let timeScale = 0;
|
||||
|
||||
if ( ! this.paused ) {
|
||||
|
||||
timeScale = this.timeScale;
|
||||
|
||||
const interpolant = this._timeScaleInterpolant;
|
||||
|
||||
if ( interpolant !== null ) {
|
||||
|
||||
const 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( deltaTime ) {
|
||||
|
||||
const duration = this._clip.duration;
|
||||
const loop = this.loop;
|
||||
|
||||
let time = this.time + deltaTime;
|
||||
let loopCount = this._loopCount;
|
||||
|
||||
const pingPong = ( loop === LoopPingPong );
|
||||
|
||||
if ( deltaTime === 0 ) {
|
||||
|
||||
if ( loopCount === - 1 ) return time;
|
||||
|
||||
return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
|
||||
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
this.time = time;
|
||||
|
||||
break handle_stop;
|
||||
|
||||
}
|
||||
|
||||
if ( this.clampWhenFinished ) this.paused = true;
|
||||
else this.enabled = false;
|
||||
|
||||
this.time = time;
|
||||
|
||||
this._mixer.dispatchEvent( {
|
||||
type: 'finished', action: this,
|
||||
direction: deltaTime < 0 ? - 1 : 1
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
} else { // repetitive Repeat or PingPong
|
||||
|
||||
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
|
||||
|
||||
const loopDelta = Math.floor( time / duration ); // signed
|
||||
time -= duration * loopDelta;
|
||||
|
||||
loopCount += Math.abs( loopDelta );
|
||||
|
||||
const 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.time = time;
|
||||
|
||||
this._mixer.dispatchEvent( {
|
||||
type: 'finished', action: this,
|
||||
direction: deltaTime > 0 ? 1 : - 1
|
||||
} );
|
||||
|
||||
} else {
|
||||
|
||||
// keep running
|
||||
|
||||
if ( pending === 1 ) {
|
||||
|
||||
// entering the last round
|
||||
|
||||
const atStart = deltaTime < 0;
|
||||
this._setEndings( atStart, ! atStart, pingPong );
|
||||
|
||||
} else {
|
||||
|
||||
this._setEndings( false, false, pingPong );
|
||||
|
||||
}
|
||||
|
||||
this._loopCount = loopCount;
|
||||
|
||||
this.time = time;
|
||||
|
||||
this._mixer.dispatchEvent( {
|
||||
type: 'loop', action: this, loopDelta: loopDelta
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
this.time = time;
|
||||
|
||||
}
|
||||
|
||||
if ( pingPong && ( loopCount & 1 ) === 1 ) {
|
||||
|
||||
// invert time for the "pong round"
|
||||
|
||||
return duration - time;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return time;
|
||||
|
||||
}
|
||||
|
||||
_setEndings( atStart, atEnd, pingPong ) {
|
||||
|
||||
const 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( duration, weightNow, weightThen ) {
|
||||
|
||||
const mixer = this._mixer, now = mixer.time;
|
||||
let interpolant = this._weightInterpolant;
|
||||
|
||||
if ( interpolant === null ) {
|
||||
|
||||
interpolant = mixer._lendControlInterpolant();
|
||||
this._weightInterpolant = interpolant;
|
||||
|
||||
}
|
||||
|
||||
const times = interpolant.parameterPositions,
|
||||
values = interpolant.sampleValues;
|
||||
|
||||
times[ 0 ] = now;
|
||||
values[ 0 ] = weightNow;
|
||||
times[ 1 ] = now + duration;
|
||||
values[ 1 ] = weightThen;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { AnimationAction };
|
||||
612
app/node_modules/three/src/animation/AnimationClip.js
generated
vendored
Normal file
612
app/node_modules/three/src/animation/AnimationClip.js
generated
vendored
Normal file
@@ -0,0 +1,612 @@
|
||||
import * as AnimationUtils from './AnimationUtils.js';
|
||||
import { KeyframeTrack } from './KeyframeTrack.js';
|
||||
import { BooleanKeyframeTrack } from './tracks/BooleanKeyframeTrack.js';
|
||||
import { ColorKeyframeTrack } from './tracks/ColorKeyframeTrack.js';
|
||||
import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack.js';
|
||||
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack.js';
|
||||
import { StringKeyframeTrack } from './tracks/StringKeyframeTrack.js';
|
||||
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack.js';
|
||||
import { generateUUID } from '../math/MathUtils.js';
|
||||
import { NormalAnimationBlendMode } from '../constants.js';
|
||||
|
||||
/**
|
||||
* A reusable set of keyframe tracks which represent an animation.
|
||||
*/
|
||||
class AnimationClip {
|
||||
|
||||
/**
|
||||
* Constructs a new animation clip.
|
||||
*
|
||||
* Note: Instead of instantiating an AnimationClip directly with the constructor, you can
|
||||
* use the static interface of this class for creating clips. In most cases though, animation clips
|
||||
* will automatically be created by loaders when importing animated 3D assets.
|
||||
*
|
||||
* @param {string} [name=''] - The clip's name.
|
||||
* @param {number} [duration=-1] - The clip's duration in seconds. If a negative value is passed,
|
||||
* the duration will be calculated from the passed keyframes.
|
||||
* @param {Array<KeyframeTrack>} tracks - An array of keyframe tracks.
|
||||
* @param {(NormalAnimationBlendMode|AdditiveAnimationBlendMode)} [blendMode=NormalAnimationBlendMode] - Defines how the animation
|
||||
* is blended/combined when two or more animations are simultaneously played.
|
||||
*/
|
||||
constructor( name = '', duration = - 1, tracks = [], blendMode = NormalAnimationBlendMode ) {
|
||||
|
||||
/**
|
||||
* The clip's name.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* An array of keyframe tracks.
|
||||
*
|
||||
* @type {Array<KeyframeTrack>}
|
||||
*/
|
||||
this.tracks = tracks;
|
||||
|
||||
/**
|
||||
* The clip's duration in seconds.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.duration = duration;
|
||||
|
||||
/**
|
||||
* Defines how the animation is blended/combined when two or more animations
|
||||
* are simultaneously played.
|
||||
*
|
||||
* @type {(NormalAnimationBlendMode|AdditiveAnimationBlendMode)}
|
||||
*/
|
||||
this.blendMode = blendMode;
|
||||
|
||||
/**
|
||||
* The UUID of the animation clip.
|
||||
*
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.uuid = generateUUID();
|
||||
|
||||
// this means it should figure out its duration by scanning the tracks
|
||||
if ( this.duration < 0 ) {
|
||||
|
||||
this.resetDuration();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an animation clip from the given JSON.
|
||||
*
|
||||
* @static
|
||||
* @param {Object} json - The serialized animation clip.
|
||||
* @return {AnimationClip} The new animation clip.
|
||||
*/
|
||||
static parse( json ) {
|
||||
|
||||
const tracks = [],
|
||||
jsonTracks = json.tracks,
|
||||
frameTime = 1.0 / ( json.fps || 1.0 );
|
||||
|
||||
for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
|
||||
|
||||
tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
|
||||
|
||||
}
|
||||
|
||||
const clip = new this( json.name, json.duration, tracks, json.blendMode );
|
||||
clip.uuid = json.uuid;
|
||||
|
||||
return clip;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the given animation clip into JSON.
|
||||
*
|
||||
* @static
|
||||
* @param {AnimationClip} clip - The animation clip to serialize.
|
||||
* @return {Object} The JSON object.
|
||||
*/
|
||||
static toJSON( clip ) {
|
||||
|
||||
const tracks = [],
|
||||
clipTracks = clip.tracks;
|
||||
|
||||
const json = {
|
||||
|
||||
'name': clip.name,
|
||||
'duration': clip.duration,
|
||||
'tracks': tracks,
|
||||
'uuid': clip.uuid,
|
||||
'blendMode': clip.blendMode
|
||||
|
||||
};
|
||||
|
||||
for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
|
||||
|
||||
tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
|
||||
|
||||
}
|
||||
|
||||
return json;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new animation clip from the passed morph targets array of a
|
||||
* geometry, taking a name and the number of frames per second.
|
||||
*
|
||||
* Note: The fps parameter is required, but the animation speed can be
|
||||
* overridden via {@link AnimationAction#setDuration}.
|
||||
*
|
||||
* @static
|
||||
* @param {string} name - The name of the animation clip.
|
||||
* @param {Array<Object>} morphTargetSequence - A sequence of morph targets.
|
||||
* @param {number} fps - The Frames-Per-Second value.
|
||||
* @param {boolean} noLoop - Whether the clip should be no loop or not.
|
||||
* @return {AnimationClip} The new animation clip.
|
||||
*/
|
||||
static CreateFromMorphTargetSequence( name, morphTargetSequence, fps, noLoop ) {
|
||||
|
||||
const numMorphTargets = morphTargetSequence.length;
|
||||
const tracks = [];
|
||||
|
||||
for ( let i = 0; i < numMorphTargets; i ++ ) {
|
||||
|
||||
let times = [];
|
||||
let values = [];
|
||||
|
||||
times.push(
|
||||
( i + numMorphTargets - 1 ) % numMorphTargets,
|
||||
i,
|
||||
( i + 1 ) % numMorphTargets );
|
||||
|
||||
values.push( 0, 1, 0 );
|
||||
|
||||
const 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 this( name, - 1, tracks );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for an animation clip by name, taking as its first parameter
|
||||
* either an array of clips, or a mesh or geometry that contains an
|
||||
* array named "animations" property.
|
||||
*
|
||||
* @static
|
||||
* @param {(Array<AnimationClip>|Object3D)} objectOrClipArray - The array or object to search through.
|
||||
* @param {string} name - The name to search for.
|
||||
* @return {?AnimationClip} The found animation clip. Returns `null` if no clip has been found.
|
||||
*/
|
||||
static findByName( objectOrClipArray, name ) {
|
||||
|
||||
let clipArray = objectOrClipArray;
|
||||
|
||||
if ( ! Array.isArray( objectOrClipArray ) ) {
|
||||
|
||||
const o = objectOrClipArray;
|
||||
clipArray = o.geometry && o.geometry.animations || o.animations;
|
||||
|
||||
}
|
||||
|
||||
for ( let i = 0; i < clipArray.length; i ++ ) {
|
||||
|
||||
if ( clipArray[ i ].name === name ) {
|
||||
|
||||
return clipArray[ i ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of new AnimationClips created from the morph target
|
||||
* sequences of a geometry, trying to sort morph target names into
|
||||
* animation-group-based patterns like "Walk_001, Walk_002, Run_001, Run_002...".
|
||||
*
|
||||
* See {@link MD2Loader#parse} as an example for how the method should be used.
|
||||
*
|
||||
* @static
|
||||
* @param {Array<Object>} morphTargets - A sequence of morph targets.
|
||||
* @param {number} fps - The Frames-Per-Second value.
|
||||
* @param {boolean} noLoop - Whether the clip should be no loop or not.
|
||||
* @return {Array<AnimationClip>} An array of new animation clips.
|
||||
*/
|
||||
static CreateClipsFromMorphTargetSequences( morphTargets, fps, noLoop ) {
|
||||
|
||||
const animationToMorphTargets = {};
|
||||
|
||||
// tested with https://regex101.com/ on trick sequences
|
||||
// such flamingo_flyA_003, flamingo_run1_003, crdeath0059
|
||||
const pattern = /^([\w-]*?)([\d]+)$/;
|
||||
|
||||
// sort morph target names into animation groups based
|
||||
// patterns like Walk_001, Walk_002, Run_001, Run_002
|
||||
for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
|
||||
|
||||
const morphTarget = morphTargets[ i ];
|
||||
const parts = morphTarget.name.match( pattern );
|
||||
|
||||
if ( parts && parts.length > 1 ) {
|
||||
|
||||
const name = parts[ 1 ];
|
||||
|
||||
let animationMorphTargets = animationToMorphTargets[ name ];
|
||||
|
||||
if ( ! animationMorphTargets ) {
|
||||
|
||||
animationToMorphTargets[ name ] = animationMorphTargets = [];
|
||||
|
||||
}
|
||||
|
||||
animationMorphTargets.push( morphTarget );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const clips = [];
|
||||
|
||||
for ( const name in animationToMorphTargets ) {
|
||||
|
||||
clips.push( this.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
|
||||
|
||||
}
|
||||
|
||||
return clips;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the `animation.hierarchy` format and returns a new animation clip.
|
||||
*
|
||||
* @static
|
||||
* @deprecated since r175.
|
||||
* @param {Object} animation - A serialized animation clip as JSON.
|
||||
* @param {Array<Bones>} bones - An array of bones.
|
||||
* @return {?AnimationClip} The new animation clip.
|
||||
*/
|
||||
static parseAnimation( animation, bones ) {
|
||||
|
||||
console.warn( 'THREE.AnimationClip: parseAnimation() is deprecated and will be removed with r185' );
|
||||
|
||||
if ( ! animation ) {
|
||||
|
||||
console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
|
||||
|
||||
// only return track if there are actually keys.
|
||||
if ( animationKeys.length !== 0 ) {
|
||||
|
||||
const times = [];
|
||||
const 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 ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const tracks = [];
|
||||
|
||||
const clipName = animation.name || 'default';
|
||||
const fps = animation.fps || 30;
|
||||
const blendMode = animation.blendMode;
|
||||
|
||||
// automatic length determination in AnimationClip.
|
||||
let duration = animation.length || - 1;
|
||||
|
||||
const hierarchyTracks = animation.hierarchy || [];
|
||||
|
||||
for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
|
||||
|
||||
const animationKeys = hierarchyTracks[ h ].keys;
|
||||
|
||||
// skip empty tracks
|
||||
if ( ! animationKeys || animationKeys.length === 0 ) continue;
|
||||
|
||||
// process morph targets
|
||||
if ( animationKeys[ 0 ].morphTargets ) {
|
||||
|
||||
// figure out all morph targets used in this track
|
||||
const morphTargetNames = {};
|
||||
|
||||
let k;
|
||||
|
||||
for ( k = 0; k < animationKeys.length; k ++ ) {
|
||||
|
||||
if ( animationKeys[ k ].morphTargets ) {
|
||||
|
||||
for ( let 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 ( const morphTargetName in morphTargetNames ) {
|
||||
|
||||
const times = [];
|
||||
const values = [];
|
||||
|
||||
for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
|
||||
|
||||
const 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;
|
||||
|
||||
} else {
|
||||
|
||||
// ...assume skeletal animation
|
||||
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
const clip = new this( clipName, duration, tracks, blendMode );
|
||||
|
||||
return clip;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the duration of this clip to the duration of its longest keyframe track.
|
||||
*
|
||||
* @return {AnimationClip} A reference to this animation clip.
|
||||
*/
|
||||
resetDuration() {
|
||||
|
||||
const tracks = this.tracks;
|
||||
let duration = 0;
|
||||
|
||||
for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
|
||||
|
||||
const track = this.tracks[ i ];
|
||||
|
||||
duration = Math.max( duration, track.times[ track.times.length - 1 ] );
|
||||
|
||||
}
|
||||
|
||||
this.duration = duration;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims all tracks to the clip's duration.
|
||||
*
|
||||
* @return {AnimationClip} A reference to this animation clip.
|
||||
*/
|
||||
trim() {
|
||||
|
||||
for ( let i = 0; i < this.tracks.length; i ++ ) {
|
||||
|
||||
this.tracks[ i ].trim( 0, this.duration );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs minimal validation on each track in the clip. Returns `true` if all
|
||||
* tracks are valid.
|
||||
*
|
||||
* @return {boolean} Whether the clip's keyframes are valid or not.
|
||||
*/
|
||||
validate() {
|
||||
|
||||
let valid = true;
|
||||
|
||||
for ( let i = 0; i < this.tracks.length; i ++ ) {
|
||||
|
||||
valid = valid && this.tracks[ i ].validate();
|
||||
|
||||
}
|
||||
|
||||
return valid;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimizes each track by removing equivalent sequential keys (which are
|
||||
* common in morph target sequences).
|
||||
*
|
||||
* @return {AnimationClip} A reference to this animation clip.
|
||||
*/
|
||||
optimize() {
|
||||
|
||||
for ( let i = 0; i < this.tracks.length; i ++ ) {
|
||||
|
||||
this.tracks[ i ].optimize();
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new animation clip with copied values from this instance.
|
||||
*
|
||||
* @return {AnimationClip} A clone of this instance.
|
||||
*/
|
||||
clone() {
|
||||
|
||||
const tracks = [];
|
||||
|
||||
for ( let i = 0; i < this.tracks.length; i ++ ) {
|
||||
|
||||
tracks.push( this.tracks[ i ].clone() );
|
||||
|
||||
}
|
||||
|
||||
return new this.constructor( this.name, this.duration, tracks, this.blendMode );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes this animation clip into JSON.
|
||||
*
|
||||
* @return {Object} The JSON object.
|
||||
*/
|
||||
toJSON() {
|
||||
|
||||
return this.constructor.toJSON( this );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getTrackTypeForValueTypeName( 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( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
|
||||
|
||||
}
|
||||
|
||||
function parseKeyframeTrack( json ) {
|
||||
|
||||
if ( json.type === undefined ) {
|
||||
|
||||
throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
|
||||
|
||||
}
|
||||
|
||||
const trackType = getTrackTypeForValueTypeName( json.type );
|
||||
|
||||
if ( json.times === undefined ) {
|
||||
|
||||
const 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 assume a constructor compatible with the base
|
||||
return new trackType( json.name, json.times, json.values, json.interpolation );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { AnimationClip };
|
||||
854
app/node_modules/three/src/animation/AnimationMixer.js
generated
vendored
Normal file
854
app/node_modules/three/src/animation/AnimationMixer.js
generated
vendored
Normal file
@@ -0,0 +1,854 @@
|
||||
import { AnimationAction } from './AnimationAction.js';
|
||||
import { EventDispatcher } from '../core/EventDispatcher.js';
|
||||
import { LinearInterpolant } from '../math/interpolants/LinearInterpolant.js';
|
||||
import { PropertyBinding } from './PropertyBinding.js';
|
||||
import { PropertyMixer } from './PropertyMixer.js';
|
||||
import { AnimationClip } from './AnimationClip.js';
|
||||
import { NormalAnimationBlendMode } from '../constants.js';
|
||||
|
||||
const _controlInterpolantsResultBuffer = new Float32Array( 1 );
|
||||
|
||||
/**
|
||||
* `AnimationMixer` is a player for animations on a particular object in
|
||||
* the scene. When multiple objects in the scene are animated independently,
|
||||
* one `AnimationMixer` may be used for each object.
|
||||
*/
|
||||
class AnimationMixer extends EventDispatcher {
|
||||
|
||||
/**
|
||||
* Constructs a new animation mixer.
|
||||
*
|
||||
* @param {Object3D} root - The object whose animations shall be played by this mixer.
|
||||
*/
|
||||
constructor( root ) {
|
||||
|
||||
super();
|
||||
|
||||
this._root = root;
|
||||
this._initMemoryManager();
|
||||
this._accuIndex = 0;
|
||||
|
||||
/**
|
||||
* The global mixer time (in seconds; starting with `0` on the mixer's creation).
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.time = 0;
|
||||
|
||||
/**
|
||||
* A scaling factor for the global time.
|
||||
*
|
||||
* Note: Setting this member to `0` and later back to `1` is a
|
||||
* possibility to pause/unpause all actions that are controlled by this
|
||||
* mixer.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.timeScale = 1.0;
|
||||
|
||||
}
|
||||
|
||||
_bindAction( action, prototypeAction ) {
|
||||
|
||||
const root = action._localRoot || this._root,
|
||||
tracks = action._clip.tracks,
|
||||
nTracks = tracks.length,
|
||||
bindings = action._propertyBindings,
|
||||
interpolants = action._interpolants,
|
||||
rootUuid = root.uuid,
|
||||
bindingsByRoot = this._bindingsByRootAndName;
|
||||
|
||||
let bindingsByName = bindingsByRoot[ rootUuid ];
|
||||
|
||||
if ( bindingsByName === undefined ) {
|
||||
|
||||
bindingsByName = {};
|
||||
bindingsByRoot[ rootUuid ] = bindingsByName;
|
||||
|
||||
}
|
||||
|
||||
for ( let i = 0; i !== nTracks; ++ i ) {
|
||||
|
||||
const track = tracks[ i ],
|
||||
trackName = track.name;
|
||||
|
||||
let binding = bindingsByName[ trackName ];
|
||||
|
||||
if ( binding !== undefined ) {
|
||||
|
||||
++ binding.referenceCount;
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
const 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( 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
|
||||
|
||||
const 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 );
|
||||
|
||||
}
|
||||
|
||||
const bindings = action._propertyBindings;
|
||||
|
||||
// increment reference counts / sort out state
|
||||
for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
const binding = bindings[ i ];
|
||||
|
||||
if ( binding.useCount ++ === 0 ) {
|
||||
|
||||
this._lendBinding( binding );
|
||||
binding.saveOriginalState();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this._lendAction( action );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_deactivateAction( action ) {
|
||||
|
||||
if ( this._isActiveAction( action ) ) {
|
||||
|
||||
const bindings = action._propertyBindings;
|
||||
|
||||
// decrement reference counts / sort out state
|
||||
for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
const binding = bindings[ i ];
|
||||
|
||||
if ( -- binding.useCount === 0 ) {
|
||||
|
||||
binding.restoreOriginalState();
|
||||
this._takeBackBinding( binding );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this._takeBackAction( action );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Memory manager
|
||||
|
||||
_initMemoryManager() {
|
||||
|
||||
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;
|
||||
|
||||
const 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( action ) {
|
||||
|
||||
const index = action._cacheIndex;
|
||||
return index !== null && index < this._nActiveActions;
|
||||
|
||||
}
|
||||
|
||||
_addInactiveAction( action, clipUuid, rootUuid ) {
|
||||
|
||||
const actions = this._actions,
|
||||
actionsByClip = this._actionsByClip;
|
||||
|
||||
let actionsForClip = actionsByClip[ clipUuid ];
|
||||
|
||||
if ( actionsForClip === undefined ) {
|
||||
|
||||
actionsForClip = {
|
||||
|
||||
knownActions: [ action ],
|
||||
actionByRoot: {}
|
||||
|
||||
};
|
||||
|
||||
action._byClipCacheIndex = 0;
|
||||
|
||||
actionsByClip[ clipUuid ] = actionsForClip;
|
||||
|
||||
} else {
|
||||
|
||||
const knownActions = actionsForClip.knownActions;
|
||||
|
||||
action._byClipCacheIndex = knownActions.length;
|
||||
knownActions.push( action );
|
||||
|
||||
}
|
||||
|
||||
action._cacheIndex = actions.length;
|
||||
actions.push( action );
|
||||
|
||||
actionsForClip.actionByRoot[ rootUuid ] = action;
|
||||
|
||||
}
|
||||
|
||||
_removeInactiveAction( action ) {
|
||||
|
||||
const actions = this._actions,
|
||||
lastInactiveAction = actions[ actions.length - 1 ],
|
||||
cacheIndex = action._cacheIndex;
|
||||
|
||||
lastInactiveAction._cacheIndex = cacheIndex;
|
||||
actions[ cacheIndex ] = lastInactiveAction;
|
||||
actions.pop();
|
||||
|
||||
action._cacheIndex = null;
|
||||
|
||||
|
||||
const 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;
|
||||
|
||||
|
||||
const actionByRoot = actionsForClip.actionByRoot,
|
||||
rootUuid = ( action._localRoot || this._root ).uuid;
|
||||
|
||||
delete actionByRoot[ rootUuid ];
|
||||
|
||||
if ( knownActionsForClip.length === 0 ) {
|
||||
|
||||
delete actionsByClip[ clipUuid ];
|
||||
|
||||
}
|
||||
|
||||
this._removeInactiveBindingsForAction( action );
|
||||
|
||||
}
|
||||
|
||||
_removeInactiveBindingsForAction( action ) {
|
||||
|
||||
const bindings = action._propertyBindings;
|
||||
|
||||
for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
const binding = bindings[ i ];
|
||||
|
||||
if ( -- binding.referenceCount === 0 ) {
|
||||
|
||||
this._removeInactiveBinding( binding );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_lendAction( action ) {
|
||||
|
||||
// [ active actions | inactive actions ]
|
||||
// [ active actions >| inactive actions ]
|
||||
// s a
|
||||
// <-swap->
|
||||
// a s
|
||||
|
||||
const 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( action ) {
|
||||
|
||||
// [ active actions | inactive actions ]
|
||||
// [ active actions |< inactive actions ]
|
||||
// a s
|
||||
// <-swap->
|
||||
// s a
|
||||
|
||||
const 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( binding, rootUuid, trackName ) {
|
||||
|
||||
const bindingsByRoot = this._bindingsByRootAndName,
|
||||
bindings = this._bindings;
|
||||
|
||||
let bindingByName = bindingsByRoot[ rootUuid ];
|
||||
|
||||
if ( bindingByName === undefined ) {
|
||||
|
||||
bindingByName = {};
|
||||
bindingsByRoot[ rootUuid ] = bindingByName;
|
||||
|
||||
}
|
||||
|
||||
bindingByName[ trackName ] = binding;
|
||||
|
||||
binding._cacheIndex = bindings.length;
|
||||
bindings.push( binding );
|
||||
|
||||
}
|
||||
|
||||
_removeInactiveBinding( binding ) {
|
||||
|
||||
const 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 ];
|
||||
|
||||
if ( Object.keys( bindingByName ).length === 0 ) {
|
||||
|
||||
delete bindingsByRoot[ rootUuid ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_lendBinding( binding ) {
|
||||
|
||||
const 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( binding ) {
|
||||
|
||||
const 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() {
|
||||
|
||||
const interpolants = this._controlInterpolants,
|
||||
lastActiveIndex = this._nActiveControlInterpolants ++;
|
||||
|
||||
let interpolant = interpolants[ lastActiveIndex ];
|
||||
|
||||
if ( interpolant === undefined ) {
|
||||
|
||||
interpolant = new LinearInterpolant(
|
||||
new Float32Array( 2 ), new Float32Array( 2 ),
|
||||
1, _controlInterpolantsResultBuffer );
|
||||
|
||||
interpolant.__cacheIndex = lastActiveIndex;
|
||||
interpolants[ lastActiveIndex ] = interpolant;
|
||||
|
||||
}
|
||||
|
||||
return interpolant;
|
||||
|
||||
}
|
||||
|
||||
_takeBackControlInterpolant( interpolant ) {
|
||||
|
||||
const interpolants = this._controlInterpolants,
|
||||
prevIndex = interpolant.__cacheIndex,
|
||||
|
||||
firstInactiveIndex = -- this._nActiveControlInterpolants,
|
||||
|
||||
lastActiveInterpolant = interpolants[ firstInactiveIndex ];
|
||||
|
||||
interpolant.__cacheIndex = firstInactiveIndex;
|
||||
interpolants[ firstInactiveIndex ] = interpolant;
|
||||
|
||||
lastActiveInterpolant.__cacheIndex = prevIndex;
|
||||
interpolants[ prevIndex ] = lastActiveInterpolant;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of {@link AnimationAction} for the passed clip.
|
||||
*
|
||||
* If an action fitting the clip and root parameters doesn't yet exist, it
|
||||
* will be created by this method. Calling this method several times with the
|
||||
* same clip and root parameters always returns the same action.
|
||||
*
|
||||
* @param {AnimationClip|string} clip - An animation clip or alternatively the name of the animation clip.
|
||||
* @param {Object3D} [optionalRoot] - An alternative root object.
|
||||
* @param {(NormalAnimationBlendMode|AdditiveAnimationBlendMode)} [blendMode] - The blend mode.
|
||||
* @return {?AnimationAction} The animation action.
|
||||
*/
|
||||
clipAction( clip, optionalRoot, blendMode ) {
|
||||
|
||||
const root = optionalRoot || this._root,
|
||||
rootUuid = root.uuid;
|
||||
|
||||
let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
|
||||
|
||||
const clipUuid = clipObject !== null ? clipObject.uuid : clip;
|
||||
|
||||
const actionsForClip = this._actionsByClip[ clipUuid ];
|
||||
let prototypeAction = null;
|
||||
|
||||
if ( blendMode === undefined ) {
|
||||
|
||||
if ( clipObject !== null ) {
|
||||
|
||||
blendMode = clipObject.blendMode;
|
||||
|
||||
} else {
|
||||
|
||||
blendMode = NormalAnimationBlendMode;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( actionsForClip !== undefined ) {
|
||||
|
||||
const existingAction = actionsForClip.actionByRoot[ rootUuid ];
|
||||
|
||||
if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
|
||||
|
||||
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
|
||||
const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
|
||||
|
||||
this._bindAction( newAction, prototypeAction );
|
||||
|
||||
// and make the action known to the memory manager
|
||||
this._addInactiveAction( newAction, clipUuid, rootUuid );
|
||||
|
||||
return newAction;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an existing animation action for the passed clip.
|
||||
*
|
||||
* @param {AnimationClip|string} clip - An animation clip or alternatively the name of the animation clip.
|
||||
* @param {Object3D} [optionalRoot] - An alternative root object.
|
||||
* @return {?AnimationAction} The animation action. Returns `null` if no action was found.
|
||||
*/
|
||||
existingAction( clip, optionalRoot ) {
|
||||
|
||||
const 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 on this mixer.
|
||||
*
|
||||
* @return {AnimationMixer} A reference to thi animation mixer.
|
||||
*/
|
||||
stopAllAction() {
|
||||
|
||||
const actions = this._actions,
|
||||
nActions = this._nActiveActions;
|
||||
|
||||
for ( let i = nActions - 1; i >= 0; -- i ) {
|
||||
|
||||
actions[ i ].stop();
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances the global mixer time and updates the animation.
|
||||
*
|
||||
* This is usually done in the render loop by passing the delta
|
||||
* time from {@link Clock} or {@link Timer}.
|
||||
*
|
||||
* @param {number} deltaTime - The delta time in seconds.
|
||||
* @return {AnimationMixer} A reference to thi animation mixer.
|
||||
*/
|
||||
update( deltaTime ) {
|
||||
|
||||
deltaTime *= this.timeScale;
|
||||
|
||||
const actions = this._actions,
|
||||
nActions = this._nActiveActions,
|
||||
|
||||
time = this.time += deltaTime,
|
||||
timeDirection = Math.sign( deltaTime ),
|
||||
|
||||
accuIndex = this._accuIndex ^= 1;
|
||||
|
||||
// run active actions
|
||||
|
||||
for ( let i = 0; i !== nActions; ++ i ) {
|
||||
|
||||
const action = actions[ i ];
|
||||
|
||||
action._update( time, deltaTime, timeDirection, accuIndex );
|
||||
|
||||
}
|
||||
|
||||
// update scene graph
|
||||
|
||||
const bindings = this._bindings,
|
||||
nBindings = this._nActiveBindings;
|
||||
|
||||
for ( let i = 0; i !== nBindings; ++ i ) {
|
||||
|
||||
bindings[ i ].apply( accuIndex );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the global mixer to a specific time and updates the animation accordingly.
|
||||
*
|
||||
* This is useful when you need to jump to an exact time in an animation. The
|
||||
* input parameter will be scaled by {@link AnimationMixer#timeScale}
|
||||
*
|
||||
* @param {number} time - The time to set in seconds.
|
||||
* @return {AnimationMixer} A reference to thi animation mixer.
|
||||
*/
|
||||
setTime( time ) {
|
||||
|
||||
this.time = 0; // Zero out time attribute for AnimationMixer object;
|
||||
for ( let i = 0; i < this._actions.length; i ++ ) {
|
||||
|
||||
this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
|
||||
|
||||
}
|
||||
|
||||
return this.update( time ); // Update used to set exact time. Returns "this" AnimationMixer object.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this mixer's root object.
|
||||
*
|
||||
* @return {Object3D} The mixer's root object.
|
||||
*/
|
||||
getRoot() {
|
||||
|
||||
return this._root;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deallocates all memory resources for a clip. Before using this method make
|
||||
* sure to call {@link AnimationAction#stop} for all related actions.
|
||||
*
|
||||
* @param {AnimationClip} clip - The clip to uncache.
|
||||
*/
|
||||
uncacheClip( clip ) {
|
||||
|
||||
const 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
|
||||
|
||||
const actionsToRemove = actionsForClip.knownActions;
|
||||
|
||||
for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
|
||||
|
||||
const action = actionsToRemove[ i ];
|
||||
|
||||
this._deactivateAction( action );
|
||||
|
||||
const 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 ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deallocates all memory resources for a root object. Before using this
|
||||
* method make sure to call {@link AnimationAction#stop} for all related
|
||||
* actions or alternatively {@link AnimationMixer#stopAllAction} when the
|
||||
* mixer operates on a single root.
|
||||
*
|
||||
* @param {Object3D} root - The root object to uncache.
|
||||
*/
|
||||
uncacheRoot( root ) {
|
||||
|
||||
const rootUuid = root.uuid,
|
||||
actionsByClip = this._actionsByClip;
|
||||
|
||||
for ( const clipUuid in actionsByClip ) {
|
||||
|
||||
const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
|
||||
action = actionByRoot[ rootUuid ];
|
||||
|
||||
if ( action !== undefined ) {
|
||||
|
||||
this._deactivateAction( action );
|
||||
this._removeInactiveAction( action );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const bindingsByRoot = this._bindingsByRootAndName,
|
||||
bindingByName = bindingsByRoot[ rootUuid ];
|
||||
|
||||
if ( bindingByName !== undefined ) {
|
||||
|
||||
for ( const trackName in bindingByName ) {
|
||||
|
||||
const binding = bindingByName[ trackName ];
|
||||
binding.restoreOriginalState();
|
||||
this._removeInactiveBinding( binding );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deallocates all memory resources for an action. The action is identified by the
|
||||
* given clip and an optional root object. Before using this method make
|
||||
* sure to call {@link AnimationAction#stop} to deactivate the action.
|
||||
*
|
||||
* @param {AnimationClip|string} clip - An animation clip or alternatively the name of the animation clip.
|
||||
* @param {Object3D} [optionalRoot] - An alternative root object.
|
||||
*/
|
||||
uncacheAction( clip, optionalRoot ) {
|
||||
|
||||
const action = this.existingAction( clip, optionalRoot );
|
||||
|
||||
if ( action !== null ) {
|
||||
|
||||
this._deactivateAction( action );
|
||||
this._removeInactiveAction( action );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { AnimationMixer };
|
||||
410
app/node_modules/three/src/animation/AnimationObjectGroup.js
generated
vendored
Normal file
410
app/node_modules/three/src/animation/AnimationObjectGroup.js
generated
vendored
Normal file
@@ -0,0 +1,410 @@
|
||||
import { PropertyBinding } from './PropertyBinding.js';
|
||||
import { generateUUID } from '../math/MathUtils.js';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class AnimationObjectGroup {
|
||||
|
||||
/**
|
||||
* Constructs a new animation group.
|
||||
*
|
||||
* @param {...Object3D} arguments - An arbitrary number of 3D objects that share the same animation state.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isAnimationObjectGroup = true;
|
||||
|
||||
/**
|
||||
* The UUID of the 3D object.
|
||||
*
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.uuid = generateUUID();
|
||||
|
||||
// cached objects followed by the active ones
|
||||
this._objects = Array.prototype.slice.call( arguments );
|
||||
|
||||
this.nCachedObjects_ = 0; // threshold
|
||||
// note: read by PropertyBinding.Composite
|
||||
|
||||
const indices = {};
|
||||
this._indicesByUUID = indices; // for bookkeeping
|
||||
|
||||
for ( let 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
|
||||
|
||||
const scope = this;
|
||||
|
||||
this.stats = {
|
||||
|
||||
objects: {
|
||||
get total() {
|
||||
|
||||
return scope._objects.length;
|
||||
|
||||
},
|
||||
get inUse() {
|
||||
|
||||
return this.total - scope.nCachedObjects_;
|
||||
|
||||
}
|
||||
},
|
||||
get bindingsPerObject() {
|
||||
|
||||
return scope._bindings.length;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an arbitrary number of objects to this animation group.
|
||||
*
|
||||
* @param {...Object3D} arguments - The 3D objects to add.
|
||||
*/
|
||||
add() {
|
||||
|
||||
const objects = this._objects,
|
||||
indicesByUUID = this._indicesByUUID,
|
||||
paths = this._paths,
|
||||
parsedPaths = this._parsedPaths,
|
||||
bindings = this._bindings,
|
||||
nBindings = bindings.length;
|
||||
|
||||
let knownObject = undefined,
|
||||
nObjects = objects.length,
|
||||
nCachedObjects = this.nCachedObjects_;
|
||||
|
||||
for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
|
||||
|
||||
const object = arguments[ i ],
|
||||
uuid = object.uuid;
|
||||
let index = indicesByUUID[ uuid ];
|
||||
|
||||
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 ( let 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
|
||||
|
||||
const 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 ( let j = 0, m = nBindings; j !== m; ++ j ) {
|
||||
|
||||
const bindingsForPath = bindings[ j ],
|
||||
lastCached = bindingsForPath[ firstActiveIndex ];
|
||||
|
||||
let 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( 'THREE.AnimationObjectGroup: 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an arbitrary number of objects to this animation group
|
||||
*
|
||||
* @param {...Object3D} arguments - The 3D objects to remove.
|
||||
*/
|
||||
remove() {
|
||||
|
||||
const objects = this._objects,
|
||||
indicesByUUID = this._indicesByUUID,
|
||||
bindings = this._bindings,
|
||||
nBindings = bindings.length;
|
||||
|
||||
let nCachedObjects = this.nCachedObjects_;
|
||||
|
||||
for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
|
||||
|
||||
const object = arguments[ i ],
|
||||
uuid = object.uuid,
|
||||
index = indicesByUUID[ uuid ];
|
||||
|
||||
if ( index !== undefined && index >= nCachedObjects ) {
|
||||
|
||||
// move existing object into the CACHED region
|
||||
|
||||
const 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 ( let j = 0, m = nBindings; j !== m; ++ j ) {
|
||||
|
||||
const bindingsForPath = bindings[ j ],
|
||||
firstActive = bindingsForPath[ lastCachedIndex ],
|
||||
binding = bindingsForPath[ index ];
|
||||
|
||||
bindingsForPath[ index ] = firstActive;
|
||||
bindingsForPath[ lastCachedIndex ] = binding;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // for arguments
|
||||
|
||||
this.nCachedObjects_ = nCachedObjects;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deallocates all memory resources for the passed 3D objects of this animation group.
|
||||
*
|
||||
* @param {...Object3D} arguments - The 3D objects to uncache.
|
||||
*/
|
||||
uncache() {
|
||||
|
||||
const objects = this._objects,
|
||||
indicesByUUID = this._indicesByUUID,
|
||||
bindings = this._bindings,
|
||||
nBindings = bindings.length;
|
||||
|
||||
let nCachedObjects = this.nCachedObjects_,
|
||||
nObjects = objects.length;
|
||||
|
||||
for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
|
||||
|
||||
const 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
|
||||
|
||||
const 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 ( let j = 0, m = nBindings; j !== m; ++ j ) {
|
||||
|
||||
const 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
|
||||
|
||||
const lastIndex = -- nObjects,
|
||||
lastObject = objects[ lastIndex ];
|
||||
|
||||
if ( lastIndex > 0 ) {
|
||||
|
||||
indicesByUUID[ lastObject.uuid ] = index;
|
||||
|
||||
}
|
||||
|
||||
objects[ index ] = lastObject;
|
||||
objects.pop();
|
||||
|
||||
// accounting is done, now do the same for all bindings
|
||||
|
||||
for ( let j = 0, m = nBindings; j !== m; ++ j ) {
|
||||
|
||||
const 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_( path, parsedPath ) {
|
||||
|
||||
// returns an array of bindings for the given path that is changed
|
||||
// according to the contained objects in the group
|
||||
|
||||
const indicesByPath = this._bindingsIndicesByPath;
|
||||
let index = indicesByPath[ path ];
|
||||
const bindings = this._bindings;
|
||||
|
||||
if ( index !== undefined ) return bindings[ index ];
|
||||
|
||||
const 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 ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
|
||||
|
||||
const object = objects[ i ];
|
||||
bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
|
||||
|
||||
}
|
||||
|
||||
return bindingsForPath;
|
||||
|
||||
}
|
||||
|
||||
unsubscribe_( path ) {
|
||||
|
||||
// tells the group to forget about a property path and no longer
|
||||
// update the array previously obtained with 'subscribe_'
|
||||
|
||||
const indicesByPath = this._bindingsIndicesByPath,
|
||||
index = indicesByPath[ path ];
|
||||
|
||||
if ( index !== undefined ) {
|
||||
|
||||
const 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 };
|
||||
506
app/node_modules/three/src/animation/AnimationUtils.js
generated
vendored
Normal file
506
app/node_modules/three/src/animation/AnimationUtils.js
generated
vendored
Normal file
@@ -0,0 +1,506 @@
|
||||
import { Quaternion } from '../math/Quaternion.js';
|
||||
import { AdditiveAnimationBlendMode } from '../constants.js';
|
||||
|
||||
/**
|
||||
* Converts an array to a specific type.
|
||||
*
|
||||
* @param {TypedArray|Array} array - The array to convert.
|
||||
* @param {TypedArray.constructor} type - The constructor of a typed array that defines the new type.
|
||||
* @return {TypedArray} The converted array.
|
||||
*/
|
||||
function convertArray( array, type ) {
|
||||
|
||||
if ( ! array || 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
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the given object is a typed array.
|
||||
*
|
||||
* @param {any} object - The object to check.
|
||||
* @return {boolean} Whether the given object is a typed array.
|
||||
*/
|
||||
function isTypedArray( object ) {
|
||||
|
||||
return ArrayBuffer.isView( object ) && ! ( object instanceof DataView );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array by which times and values can be sorted.
|
||||
*
|
||||
* @param {Array<number>} times - The keyframe time values.
|
||||
* @return {Array<number>} The array.
|
||||
*/
|
||||
function getKeyframeOrder( times ) {
|
||||
|
||||
function compareTime( i, j ) {
|
||||
|
||||
return times[ i ] - times[ j ];
|
||||
|
||||
}
|
||||
|
||||
const n = times.length;
|
||||
const result = new Array( n );
|
||||
for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
|
||||
|
||||
result.sort( compareTime );
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the given array by the previously computed order via `getKeyframeOrder()`.
|
||||
*
|
||||
* @param {Array<number>} values - The values to sort.
|
||||
* @param {number} stride - The stride.
|
||||
* @param {Array<number>} order - The sort order.
|
||||
* @return {Array<number>} The sorted values.
|
||||
*/
|
||||
function sortedArray( values, stride, order ) {
|
||||
|
||||
const nValues = values.length;
|
||||
const result = new values.constructor( nValues );
|
||||
|
||||
for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
|
||||
|
||||
const srcOffset = order[ i ] * stride;
|
||||
|
||||
for ( let j = 0; j !== stride; ++ j ) {
|
||||
|
||||
result[ dstOffset ++ ] = values[ srcOffset + j ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for parsing AOS keyframe formats.
|
||||
*
|
||||
* @param {Array<number>} jsonKeys - A list of JSON keyframes.
|
||||
* @param {Array<number>} times - This array will be filled with keyframe times by this function.
|
||||
* @param {Array<number>} values - This array will be filled with keyframe values by this function.
|
||||
* @param {string} valuePropertyName - The name of the property to use.
|
||||
*/
|
||||
function flattenJSON( jsonKeys, times, values, valuePropertyName ) {
|
||||
|
||||
let i = 1, key = jsonKeys[ 0 ];
|
||||
|
||||
while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
|
||||
|
||||
key = jsonKeys[ i ++ ];
|
||||
|
||||
}
|
||||
|
||||
if ( key === undefined ) return; // no data
|
||||
|
||||
let 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( ...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 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new clip, containing only the segment of the original clip between the given frames.
|
||||
*
|
||||
* @param {AnimationClip} sourceClip - The values to sort.
|
||||
* @param {string} name - The name of the clip.
|
||||
* @param {number} startFrame - The start frame.
|
||||
* @param {number} endFrame - The end frame.
|
||||
* @param {number} [fps=30] - The FPS.
|
||||
* @return {AnimationClip} The new sub clip.
|
||||
*/
|
||||
function subclip( sourceClip, name, startFrame, endFrame, fps = 30 ) {
|
||||
|
||||
const clip = sourceClip.clone();
|
||||
|
||||
clip.name = name;
|
||||
|
||||
const tracks = [];
|
||||
|
||||
for ( let i = 0; i < clip.tracks.length; ++ i ) {
|
||||
|
||||
const track = clip.tracks[ i ];
|
||||
const valueSize = track.getValueSize();
|
||||
|
||||
const times = [];
|
||||
const values = [];
|
||||
|
||||
for ( let j = 0; j < track.times.length; ++ j ) {
|
||||
|
||||
const frame = track.times[ j ] * fps;
|
||||
|
||||
if ( frame < startFrame || frame >= endFrame ) continue;
|
||||
|
||||
times.push( track.times[ j ] );
|
||||
|
||||
for ( let k = 0; k < valueSize; ++ k ) {
|
||||
|
||||
values.push( track.values[ j * valueSize + k ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( times.length === 0 ) continue;
|
||||
|
||||
track.times = convertArray( times, track.times.constructor );
|
||||
track.values = convertArray( values, track.values.constructor );
|
||||
|
||||
tracks.push( track );
|
||||
|
||||
}
|
||||
|
||||
clip.tracks = tracks;
|
||||
|
||||
// find minimum .times value across all tracks in the trimmed clip
|
||||
|
||||
let minStartTime = Infinity;
|
||||
|
||||
for ( let i = 0; i < clip.tracks.length; ++ i ) {
|
||||
|
||||
if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
|
||||
|
||||
minStartTime = clip.tracks[ i ].times[ 0 ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// shift all tracks such that clip begins at t=0
|
||||
|
||||
for ( let i = 0; i < clip.tracks.length; ++ i ) {
|
||||
|
||||
clip.tracks[ i ].shift( - 1 * minStartTime );
|
||||
|
||||
}
|
||||
|
||||
clip.resetDuration();
|
||||
|
||||
return clip;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the keyframes of the given animation clip to an additive format.
|
||||
*
|
||||
* @param {AnimationClip} targetClip - The clip to make additive.
|
||||
* @param {number} [referenceFrame=0] - The reference frame.
|
||||
* @param {AnimationClip} [referenceClip=targetClip] - The reference clip.
|
||||
* @param {number} [fps=30] - The FPS.
|
||||
* @return {AnimationClip} The updated clip which is now additive.
|
||||
*/
|
||||
function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
|
||||
|
||||
if ( fps <= 0 ) fps = 30;
|
||||
|
||||
const numTracks = referenceClip.tracks.length;
|
||||
const referenceTime = referenceFrame / fps;
|
||||
|
||||
// Make each track's values relative to the values at the reference frame
|
||||
for ( let i = 0; i < numTracks; ++ i ) {
|
||||
|
||||
const referenceTrack = referenceClip.tracks[ i ];
|
||||
const referenceTrackType = referenceTrack.ValueTypeName;
|
||||
|
||||
// Skip this track if it's non-numeric
|
||||
if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
|
||||
|
||||
// Find the track in the target clip whose name and type matches the reference track
|
||||
const targetTrack = targetClip.tracks.find( function ( track ) {
|
||||
|
||||
return track.name === referenceTrack.name
|
||||
&& track.ValueTypeName === referenceTrackType;
|
||||
|
||||
} );
|
||||
|
||||
if ( targetTrack === undefined ) continue;
|
||||
|
||||
let referenceOffset = 0;
|
||||
const referenceValueSize = referenceTrack.getValueSize();
|
||||
|
||||
if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
|
||||
|
||||
referenceOffset = referenceValueSize / 3;
|
||||
|
||||
}
|
||||
|
||||
let targetOffset = 0;
|
||||
const targetValueSize = targetTrack.getValueSize();
|
||||
|
||||
if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
|
||||
|
||||
targetOffset = targetValueSize / 3;
|
||||
|
||||
}
|
||||
|
||||
const lastIndex = referenceTrack.times.length - 1;
|
||||
let referenceValue;
|
||||
|
||||
// Find the value to subtract out of the track
|
||||
if ( referenceTime <= referenceTrack.times[ 0 ] ) {
|
||||
|
||||
// Reference frame is earlier than the first keyframe, so just use the first keyframe
|
||||
const startIndex = referenceOffset;
|
||||
const endIndex = referenceValueSize - referenceOffset;
|
||||
referenceValue = referenceTrack.values.slice( startIndex, endIndex );
|
||||
|
||||
} else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
|
||||
|
||||
// Reference frame is after the last keyframe, so just use the last keyframe
|
||||
const startIndex = lastIndex * referenceValueSize + referenceOffset;
|
||||
const endIndex = startIndex + referenceValueSize - referenceOffset;
|
||||
referenceValue = referenceTrack.values.slice( startIndex, endIndex );
|
||||
|
||||
} else {
|
||||
|
||||
// Interpolate to the reference value
|
||||
const interpolant = referenceTrack.createInterpolant();
|
||||
const startIndex = referenceOffset;
|
||||
const endIndex = referenceValueSize - referenceOffset;
|
||||
interpolant.evaluate( referenceTime );
|
||||
referenceValue = interpolant.resultBuffer.slice( startIndex, endIndex );
|
||||
|
||||
}
|
||||
|
||||
// Conjugate the quaternion
|
||||
if ( referenceTrackType === 'quaternion' ) {
|
||||
|
||||
const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
|
||||
referenceQuat.toArray( referenceValue );
|
||||
|
||||
}
|
||||
|
||||
// Subtract the reference value from all of the track values
|
||||
|
||||
const numTimes = targetTrack.times.length;
|
||||
for ( let j = 0; j < numTimes; ++ j ) {
|
||||
|
||||
const valueStart = j * targetValueSize + targetOffset;
|
||||
|
||||
if ( referenceTrackType === 'quaternion' ) {
|
||||
|
||||
// Multiply the conjugate for quaternion track types
|
||||
Quaternion.multiplyQuaternionsFlat(
|
||||
targetTrack.values,
|
||||
valueStart,
|
||||
referenceValue,
|
||||
0,
|
||||
targetTrack.values,
|
||||
valueStart
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
const valueEnd = targetValueSize - targetOffset * 2;
|
||||
|
||||
// Subtract each value for all other numeric track types
|
||||
for ( let k = 0; k < valueEnd; ++ k ) {
|
||||
|
||||
targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
targetClip.blendMode = AdditiveAnimationBlendMode;
|
||||
|
||||
return targetClip;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A class with various methods to assist with animations.
|
||||
*
|
||||
* @hideconstructor
|
||||
*/
|
||||
class AnimationUtils {
|
||||
|
||||
/**
|
||||
* Converts an array to a specific type
|
||||
*
|
||||
* @static
|
||||
* @param {TypedArray|Array} array - The array to convert.
|
||||
* @param {TypedArray.constructor} type - The constructor of a type array.
|
||||
* @return {TypedArray} The converted array
|
||||
*/
|
||||
static convertArray( array, type ) {
|
||||
|
||||
return convertArray( array, type );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the given object is a typed array.
|
||||
*
|
||||
* @static
|
||||
* @param {any} object - The object to check.
|
||||
* @return {boolean} Whether the given object is a typed array.
|
||||
*/
|
||||
static isTypedArray( object ) {
|
||||
|
||||
return isTypedArray( object );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array by which times and values can be sorted.
|
||||
*
|
||||
* @static
|
||||
* @param {Array<number>} times - The keyframe time values.
|
||||
* @return {Array<number>} The array.
|
||||
*/
|
||||
static getKeyframeOrder( times ) {
|
||||
|
||||
return getKeyframeOrder( times );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the given array by the previously computed order via `getKeyframeOrder()`.
|
||||
*
|
||||
* @static
|
||||
* @param {Array<number>} values - The values to sort.
|
||||
* @param {number} stride - The stride.
|
||||
* @param {Array<number>} order - The sort order.
|
||||
* @return {Array<number>} The sorted values.
|
||||
*/
|
||||
static sortedArray( values, stride, order ) {
|
||||
|
||||
return sortedArray( values, stride, order );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for parsing AOS keyframe formats.
|
||||
*
|
||||
* @static
|
||||
* @param {Array<number>} jsonKeys - A list of JSON keyframes.
|
||||
* @param {Array<number>} times - This array will be filled with keyframe times by this method.
|
||||
* @param {Array<number>} values - This array will be filled with keyframe values by this method.
|
||||
* @param {string} valuePropertyName - The name of the property to use.
|
||||
*/
|
||||
static flattenJSON( jsonKeys, times, values, valuePropertyName ) {
|
||||
|
||||
flattenJSON( jsonKeys, times, values, valuePropertyName );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new clip, containing only the segment of the original clip between the given frames.
|
||||
*
|
||||
* @static
|
||||
* @param {AnimationClip} sourceClip - The values to sort.
|
||||
* @param {string} name - The name of the clip.
|
||||
* @param {number} startFrame - The start frame.
|
||||
* @param {number} endFrame - The end frame.
|
||||
* @param {number} [fps=30] - The FPS.
|
||||
* @return {AnimationClip} The new sub clip.
|
||||
*/
|
||||
static subclip( sourceClip, name, startFrame, endFrame, fps = 30 ) {
|
||||
|
||||
return subclip( sourceClip, name, startFrame, endFrame, fps );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the keyframes of the given animation clip to an additive format.
|
||||
*
|
||||
* @static
|
||||
* @param {AnimationClip} targetClip - The clip to make additive.
|
||||
* @param {number} [referenceFrame=0] - The reference frame.
|
||||
* @param {AnimationClip} [referenceClip=targetClip] - The reference clip.
|
||||
* @param {number} [fps=30] - The FPS.
|
||||
* @return {AnimationClip} The updated clip which is now additive.
|
||||
*/
|
||||
static makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
|
||||
|
||||
return makeClipAdditive( targetClip, referenceFrame, referenceClip, fps );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export {
|
||||
convertArray,
|
||||
isTypedArray,
|
||||
getKeyframeOrder,
|
||||
sortedArray,
|
||||
flattenJSON,
|
||||
subclip,
|
||||
makeClipAdditive,
|
||||
AnimationUtils
|
||||
};
|
||||
596
app/node_modules/three/src/animation/KeyframeTrack.js
generated
vendored
Normal file
596
app/node_modules/three/src/animation/KeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,596 @@
|
||||
import {
|
||||
InterpolateLinear,
|
||||
InterpolateSmooth,
|
||||
InterpolateDiscrete
|
||||
} from '../constants.js';
|
||||
import { CubicInterpolant } from '../math/interpolants/CubicInterpolant.js';
|
||||
import { LinearInterpolant } from '../math/interpolants/LinearInterpolant.js';
|
||||
import { DiscreteInterpolant } from '../math/interpolants/DiscreteInterpolant.js';
|
||||
import * as AnimationUtils from './AnimationUtils.js';
|
||||
|
||||
/**
|
||||
* Represents s a timed sequence of keyframes, which are composed of lists of
|
||||
* times and related values, and which are used to animate a specific property
|
||||
* of an object.
|
||||
*/
|
||||
class KeyframeTrack {
|
||||
|
||||
/**
|
||||
* Constructs a new keyframe track.
|
||||
*
|
||||
* @param {string} name - The keyframe track's name.
|
||||
* @param {Array<number>} times - A list of keyframe times.
|
||||
* @param {Array<number>} values - A list of keyframe values.
|
||||
* @param {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)} [interpolation] - The interpolation type.
|
||||
*/
|
||||
constructor( name, times, values, interpolation ) {
|
||||
|
||||
if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
|
||||
if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
|
||||
|
||||
/**
|
||||
* The track's name can refer to morph targets or bones or
|
||||
* possibly other values within an animated object. See {@link PropertyBinding#parseTrackName}
|
||||
* for the forms of strings that can be parsed for property binding.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* The keyframe times.
|
||||
*
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
|
||||
|
||||
/**
|
||||
* The keyframe values.
|
||||
*
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
|
||||
|
||||
this.setInterpolation( interpolation || this.DefaultInterpolation );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the keyframe track to JSON.
|
||||
*
|
||||
* @static
|
||||
* @param {KeyframeTrack} track - The keyframe track to serialize.
|
||||
* @return {Object} The serialized keyframe track as JSON.
|
||||
*/
|
||||
static toJSON( track ) {
|
||||
|
||||
const trackType = track.constructor;
|
||||
|
||||
let json;
|
||||
|
||||
// derived classes can define a static toJSON method
|
||||
if ( trackType.toJSON !== this.toJSON ) {
|
||||
|
||||
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 )
|
||||
|
||||
};
|
||||
|
||||
const interpolation = track.getInterpolation();
|
||||
|
||||
if ( interpolation !== track.DefaultInterpolation ) {
|
||||
|
||||
json.interpolation = interpolation;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
json.type = track.ValueTypeName; // mandatory
|
||||
|
||||
return json;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating a new discrete interpolant.
|
||||
*
|
||||
* @static
|
||||
* @param {TypedArray} [result] - The result buffer.
|
||||
* @return {DiscreteInterpolant} The new interpolant.
|
||||
*/
|
||||
InterpolantFactoryMethodDiscrete( result ) {
|
||||
|
||||
return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating a new linear interpolant.
|
||||
*
|
||||
* @static
|
||||
* @param {TypedArray} [result] - The result buffer.
|
||||
* @return {LinearInterpolant} The new interpolant.
|
||||
*/
|
||||
InterpolantFactoryMethodLinear( result ) {
|
||||
|
||||
return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating a new smooth interpolant.
|
||||
*
|
||||
* @static
|
||||
* @param {TypedArray} [result] - The result buffer.
|
||||
* @return {CubicInterpolant} The new interpolant.
|
||||
*/
|
||||
InterpolantFactoryMethodSmooth( result ) {
|
||||
|
||||
return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the interpolation factor method for this keyframe track.
|
||||
*
|
||||
* @param {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)} interpolation - The interpolation type.
|
||||
* @return {KeyframeTrack} A reference to this keyframe track.
|
||||
*/
|
||||
setInterpolation( interpolation ) {
|
||||
|
||||
let factoryMethod;
|
||||
|
||||
switch ( interpolation ) {
|
||||
|
||||
case InterpolateDiscrete:
|
||||
|
||||
factoryMethod = this.InterpolantFactoryMethodDiscrete;
|
||||
|
||||
break;
|
||||
|
||||
case InterpolateLinear:
|
||||
|
||||
factoryMethod = this.InterpolantFactoryMethodLinear;
|
||||
|
||||
break;
|
||||
|
||||
case InterpolateSmooth:
|
||||
|
||||
factoryMethod = this.InterpolantFactoryMethodSmooth;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( factoryMethod === undefined ) {
|
||||
|
||||
const 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( 'THREE.KeyframeTrack:', message );
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
this.createInterpolant = factoryMethod;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current interpolation type.
|
||||
*
|
||||
* @return {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)} The interpolation type.
|
||||
*/
|
||||
getInterpolation() {
|
||||
|
||||
switch ( this.createInterpolant ) {
|
||||
|
||||
case this.InterpolantFactoryMethodDiscrete:
|
||||
|
||||
return InterpolateDiscrete;
|
||||
|
||||
case this.InterpolantFactoryMethodLinear:
|
||||
|
||||
return InterpolateLinear;
|
||||
|
||||
case this.InterpolantFactoryMethodSmooth:
|
||||
|
||||
return InterpolateSmooth;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value size.
|
||||
*
|
||||
* @return {number} The value size.
|
||||
*/
|
||||
getValueSize() {
|
||||
|
||||
return this.values.length / this.times.length;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves all keyframes either forward or backward in time.
|
||||
*
|
||||
* @param {number} timeOffset - The offset to move the time values.
|
||||
* @return {KeyframeTrack} A reference to this keyframe track.
|
||||
*/
|
||||
shift( timeOffset ) {
|
||||
|
||||
if ( timeOffset !== 0.0 ) {
|
||||
|
||||
const times = this.times;
|
||||
|
||||
for ( let 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).
|
||||
*
|
||||
* @param {number} timeScale - The time scale.
|
||||
* @return {KeyframeTrack} A reference to this keyframe track.
|
||||
*/
|
||||
scale( timeScale ) {
|
||||
|
||||
if ( timeScale !== 1.0 ) {
|
||||
|
||||
const times = this.times;
|
||||
|
||||
for ( let 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 defined time range.
|
||||
*
|
||||
* Note: The method does not shift around keys to the start of the track time, because for interpolated
|
||||
* keys this will change their values
|
||||
*
|
||||
* @param {number} startTime - The start time.
|
||||
* @param {number} endTime - The end time.
|
||||
* @return {KeyframeTrack} A reference to this keyframe track.
|
||||
*/
|
||||
trim( startTime, endTime ) {
|
||||
|
||||
const times = this.times,
|
||||
nKeys = times.length;
|
||||
|
||||
let 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;
|
||||
|
||||
}
|
||||
|
||||
const stride = this.getValueSize();
|
||||
this.times = times.slice( from, to );
|
||||
this.values = this.values.slice( from * stride, to * stride );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs minimal validation on the keyframe track. Returns `true` if the values
|
||||
* are valid.
|
||||
*
|
||||
* @return {boolean} Whether the keyframes are valid or not.
|
||||
*/
|
||||
validate() {
|
||||
|
||||
let valid = true;
|
||||
|
||||
const valueSize = this.getValueSize();
|
||||
if ( valueSize - Math.floor( valueSize ) !== 0 ) {
|
||||
|
||||
console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
|
||||
valid = false;
|
||||
|
||||
}
|
||||
|
||||
const times = this.times,
|
||||
values = this.values,
|
||||
|
||||
nKeys = times.length;
|
||||
|
||||
if ( nKeys === 0 ) {
|
||||
|
||||
console.error( 'THREE.KeyframeTrack: Track is empty.', this );
|
||||
valid = false;
|
||||
|
||||
}
|
||||
|
||||
let prevTime = null;
|
||||
|
||||
for ( let i = 0; i !== nKeys; i ++ ) {
|
||||
|
||||
const currTime = times[ i ];
|
||||
|
||||
if ( typeof currTime === 'number' && isNaN( currTime ) ) {
|
||||
|
||||
console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
|
||||
valid = false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( prevTime !== null && prevTime > currTime ) {
|
||||
|
||||
console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
|
||||
valid = false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
prevTime = currTime;
|
||||
|
||||
}
|
||||
|
||||
if ( values !== undefined ) {
|
||||
|
||||
if ( AnimationUtils.isTypedArray( values ) ) {
|
||||
|
||||
for ( let i = 0, n = values.length; i !== n; ++ i ) {
|
||||
|
||||
const value = values[ i ];
|
||||
|
||||
if ( isNaN( value ) ) {
|
||||
|
||||
console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
|
||||
valid = false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return valid;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimizes this keyframe track by removing equivalent sequential keys (which are
|
||||
* common in morph target sequences).
|
||||
*
|
||||
* @return {AnimationClip} A reference to this animation clip.
|
||||
*/
|
||||
optimize() {
|
||||
|
||||
// (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
|
||||
|
||||
// times or values may be shared with other tracks, so overwriting is unsafe
|
||||
const times = this.times.slice(),
|
||||
values = this.values.slice(),
|
||||
stride = this.getValueSize(),
|
||||
|
||||
smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
|
||||
|
||||
lastIndex = times.length - 1;
|
||||
|
||||
let writeIndex = 1;
|
||||
|
||||
for ( let i = 1; i < lastIndex; ++ i ) {
|
||||
|
||||
let keep = false;
|
||||
|
||||
const time = times[ i ];
|
||||
const timeNext = times[ i + 1 ];
|
||||
|
||||
// remove adjacent keyframes scheduled at the same time
|
||||
|
||||
if ( time !== timeNext && ( i !== 1 || time !== times[ 0 ] ) ) {
|
||||
|
||||
if ( ! smoothInterpolation ) {
|
||||
|
||||
// remove unnecessary keyframes same as their neighbors
|
||||
|
||||
const offset = i * stride,
|
||||
offsetP = offset - stride,
|
||||
offsetN = offset + stride;
|
||||
|
||||
for ( let j = 0; j !== stride; ++ j ) {
|
||||
|
||||
const 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 ];
|
||||
|
||||
const readOffset = i * stride,
|
||||
writeOffset = writeIndex * stride;
|
||||
|
||||
for ( let 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 ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
|
||||
|
||||
values[ writeOffset + j ] = values[ readOffset + j ];
|
||||
|
||||
}
|
||||
|
||||
++ writeIndex;
|
||||
|
||||
}
|
||||
|
||||
if ( writeIndex !== times.length ) {
|
||||
|
||||
this.times = times.slice( 0, writeIndex );
|
||||
this.values = values.slice( 0, writeIndex * stride );
|
||||
|
||||
} else {
|
||||
|
||||
this.times = times;
|
||||
this.values = values;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new keyframe track with copied values from this instance.
|
||||
*
|
||||
* @return {KeyframeTrack} A clone of this instance.
|
||||
*/
|
||||
clone() {
|
||||
|
||||
const times = this.times.slice();
|
||||
const values = this.values.slice();
|
||||
|
||||
const TypedKeyframeTrack = this.constructor;
|
||||
const track = new TypedKeyframeTrack( this.name, times, values );
|
||||
|
||||
// Interpolant argument to constructor is not saved, so copy the factory method directly.
|
||||
track.createInterpolant = this.createInterpolant;
|
||||
|
||||
return track;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The value type name.
|
||||
*
|
||||
* @type {String}
|
||||
* @default ''
|
||||
*/
|
||||
KeyframeTrack.prototype.ValueTypeName = '';
|
||||
|
||||
/**
|
||||
* The time buffer type of this keyframe track.
|
||||
*
|
||||
* @type {TypedArray|Array}
|
||||
* @default Float32Array.constructor
|
||||
*/
|
||||
KeyframeTrack.prototype.TimeBufferType = Float32Array;
|
||||
|
||||
/**
|
||||
* The value buffer type of this keyframe track.
|
||||
*
|
||||
* @type {TypedArray|Array}
|
||||
* @default Float32Array.constructor
|
||||
*/
|
||||
KeyframeTrack.prototype.ValueBufferType = Float32Array;
|
||||
|
||||
/**
|
||||
* The default interpolation type of this keyframe track.
|
||||
*
|
||||
* @type {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)}
|
||||
* @default InterpolateLinear
|
||||
*/
|
||||
KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
|
||||
|
||||
export { KeyframeTrack };
|
||||
793
app/node_modules/three/src/animation/PropertyBinding.js
generated
vendored
Normal file
793
app/node_modules/three/src/animation/PropertyBinding.js
generated
vendored
Normal file
@@ -0,0 +1,793 @@
|
||||
// Characters [].:/ are reserved for track binding syntax.
|
||||
const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
|
||||
const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
|
||||
|
||||
// Attempts to allow node names from any language. ES5's `\w` regexp matches
|
||||
// only latin characters, and the unicode \p{L} is not yet supported. So
|
||||
// instead, we exclude reserved characters and match everything else.
|
||||
const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
|
||||
const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
|
||||
|
||||
// Parent directories, delimited by '/' or ':'. Currently unused, but must
|
||||
// be matched to parse the rest of the track name.
|
||||
const _directoryRe = /*@__PURE__*/ /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
|
||||
|
||||
// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
|
||||
const _nodeRe = /*@__PURE__*/ /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
|
||||
|
||||
// Object on target node, and accessor. May not contain reserved
|
||||
// characters. Accessor may contain any character except closing bracket.
|
||||
const _objectRe = /*@__PURE__*/ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
|
||||
|
||||
// Property and accessor. May not contain reserved characters. Accessor may
|
||||
// contain any non-bracket characters.
|
||||
const _propertyRe = /*@__PURE__*/ /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
|
||||
|
||||
const _trackRe = new RegExp( ''
|
||||
+ '^'
|
||||
+ _directoryRe
|
||||
+ _nodeRe
|
||||
+ _objectRe
|
||||
+ _propertyRe
|
||||
+ '$'
|
||||
);
|
||||
|
||||
const _supportedObjectNames = [ 'material', 'materials', 'bones', 'map' ];
|
||||
|
||||
class Composite {
|
||||
|
||||
constructor( targetGroup, path, optionalParsedPath ) {
|
||||
|
||||
const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
|
||||
|
||||
this._targetGroup = targetGroup;
|
||||
this._bindings = targetGroup.subscribe_( path, parsedPath );
|
||||
|
||||
}
|
||||
|
||||
getValue( array, offset ) {
|
||||
|
||||
this.bind(); // bind all binding
|
||||
|
||||
const firstValidIndex = this._targetGroup.nCachedObjects_,
|
||||
binding = this._bindings[ firstValidIndex ];
|
||||
|
||||
// and only call .getValue on the first
|
||||
if ( binding !== undefined ) binding.getValue( array, offset );
|
||||
|
||||
}
|
||||
|
||||
setValue( array, offset ) {
|
||||
|
||||
const bindings = this._bindings;
|
||||
|
||||
for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
bindings[ i ].setValue( array, offset );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bind() {
|
||||
|
||||
const bindings = this._bindings;
|
||||
|
||||
for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
bindings[ i ].bind();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unbind() {
|
||||
|
||||
const bindings = this._bindings;
|
||||
|
||||
for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
|
||||
|
||||
bindings[ i ].unbind();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
|
||||
/**
|
||||
* This holds a reference to a real property in the scene graph; used internally.
|
||||
*/
|
||||
class PropertyBinding {
|
||||
|
||||
/**
|
||||
* Constructs a new property binding.
|
||||
*
|
||||
* @param {Object} rootNode - The root node.
|
||||
* @param {string} path - The path.
|
||||
* @param {?Object} [parsedPath] - The parsed path.
|
||||
*/
|
||||
constructor( rootNode, path, parsedPath ) {
|
||||
|
||||
/**
|
||||
* The object path to the animated property.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.path = path;
|
||||
|
||||
/**
|
||||
* An object holding information about the path.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
|
||||
|
||||
/**
|
||||
* The object owns the animated property.
|
||||
*
|
||||
* @type {?Object}
|
||||
*/
|
||||
this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName );
|
||||
|
||||
/**
|
||||
* The root node.
|
||||
*
|
||||
* @type {Object3D|Skeleton}
|
||||
*/
|
||||
this.rootNode = rootNode;
|
||||
|
||||
// initial state of these methods that calls 'bind'
|
||||
this.getValue = this._getValue_unbound;
|
||||
this.setValue = this._setValue_unbound;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory method for creating a property binding from the given parameters.
|
||||
*
|
||||
* @static
|
||||
* @param {Object} root - The root node.
|
||||
* @param {string} path - The path.
|
||||
* @param {?Object} [parsedPath] - The parsed path.
|
||||
* @return {PropertyBinding|Composite} The created property binding or composite.
|
||||
*/
|
||||
static create( root, path, parsedPath ) {
|
||||
|
||||
if ( ! ( root && root.isAnimationObjectGroup ) ) {
|
||||
|
||||
return new PropertyBinding( root, path, parsedPath );
|
||||
|
||||
} else {
|
||||
|
||||
return new PropertyBinding.Composite( root, path, parsedPath );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces spaces with underscores and removes unsupported characters from
|
||||
* node names, to ensure compatibility with parseTrackName().
|
||||
*
|
||||
* @param {string} name - Node name to be sanitized.
|
||||
* @return {string} The sanitized node name.
|
||||
*/
|
||||
static sanitizeNodeName( name ) {
|
||||
|
||||
return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given track name (an object path to an animated property) and
|
||||
* returns an object with information about the path. Matches strings in the following forms:
|
||||
*
|
||||
* - 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
|
||||
*
|
||||
* @static
|
||||
* @param {string} trackName - The track name to parse.
|
||||
* @return {Object} The parsed track name as an object.
|
||||
*/
|
||||
static parseTrackName( trackName ) {
|
||||
|
||||
const matches = _trackRe.exec( trackName );
|
||||
|
||||
if ( matches === null ) {
|
||||
|
||||
throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
|
||||
|
||||
}
|
||||
|
||||
const results = {
|
||||
// directoryName: matches[ 1 ], // (tschw) currently unused
|
||||
nodeName: matches[ 2 ],
|
||||
objectName: matches[ 3 ],
|
||||
objectIndex: matches[ 4 ],
|
||||
propertyName: matches[ 5 ], // required
|
||||
propertyIndex: matches[ 6 ]
|
||||
};
|
||||
|
||||
const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
|
||||
|
||||
if ( lastDot !== undefined && lastDot !== - 1 ) {
|
||||
|
||||
const objectName = results.nodeName.substring( lastDot + 1 );
|
||||
|
||||
// Object names must be checked against an allowlist. Otherwise, there
|
||||
// is no way to parse 'foo.bar.baz': 'baz' must be a property, but
|
||||
// 'bar' could be the objectName, or part of a nodeName (which can
|
||||
// include '.' characters).
|
||||
if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
|
||||
|
||||
results.nodeName = results.nodeName.substring( 0, lastDot );
|
||||
results.objectName = objectName;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( results.propertyName === null || results.propertyName.length === 0 ) {
|
||||
|
||||
throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
|
||||
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for a node in the hierarchy of the given root object by the given
|
||||
* node name.
|
||||
*
|
||||
* @static
|
||||
* @param {Object} root - The root object.
|
||||
* @param {string|number} nodeName - The name of the node.
|
||||
* @return {?Object} The found node. Returns `null` if no object was found.
|
||||
*/
|
||||
static findNode( root, nodeName ) {
|
||||
|
||||
if ( nodeName === undefined || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
|
||||
|
||||
return root;
|
||||
|
||||
}
|
||||
|
||||
// search into skeleton bones.
|
||||
if ( root.skeleton ) {
|
||||
|
||||
const bone = root.skeleton.getBoneByName( nodeName );
|
||||
|
||||
if ( bone !== undefined ) {
|
||||
|
||||
return bone;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// search into node subtree.
|
||||
if ( root.children ) {
|
||||
|
||||
const searchNodeSubtree = function ( children ) {
|
||||
|
||||
for ( let i = 0; i < children.length; i ++ ) {
|
||||
|
||||
const childNode = children[ i ];
|
||||
|
||||
if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
|
||||
|
||||
return childNode;
|
||||
|
||||
}
|
||||
|
||||
const result = searchNodeSubtree( childNode.children );
|
||||
|
||||
if ( result ) return result;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
};
|
||||
|
||||
const subTreeNode = searchNodeSubtree( root.children );
|
||||
|
||||
if ( subTreeNode ) {
|
||||
|
||||
return subTreeNode;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
// these are used to "bind" a nonexistent property
|
||||
_getValue_unavailable() {}
|
||||
_setValue_unavailable() {}
|
||||
|
||||
// Getters
|
||||
|
||||
_getValue_direct( buffer, offset ) {
|
||||
|
||||
buffer[ offset ] = this.targetObject[ this.propertyName ];
|
||||
|
||||
}
|
||||
|
||||
_getValue_array( buffer, offset ) {
|
||||
|
||||
const source = this.resolvedProperty;
|
||||
|
||||
for ( let i = 0, n = source.length; i !== n; ++ i ) {
|
||||
|
||||
buffer[ offset ++ ] = source[ i ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_getValue_arrayElement( buffer, offset ) {
|
||||
|
||||
buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
|
||||
|
||||
}
|
||||
|
||||
_getValue_toArray( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty.toArray( buffer, offset );
|
||||
|
||||
}
|
||||
|
||||
// Direct
|
||||
|
||||
_setValue_direct( buffer, offset ) {
|
||||
|
||||
this.targetObject[ this.propertyName ] = buffer[ offset ];
|
||||
|
||||
}
|
||||
|
||||
_setValue_direct_setNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.targetObject[ this.propertyName ] = buffer[ offset ];
|
||||
this.targetObject.needsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
_setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.targetObject[ this.propertyName ] = buffer[ offset ];
|
||||
this.targetObject.matrixWorldNeedsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
// EntireArray
|
||||
|
||||
_setValue_array( buffer, offset ) {
|
||||
|
||||
const dest = this.resolvedProperty;
|
||||
|
||||
for ( let i = 0, n = dest.length; i !== n; ++ i ) {
|
||||
|
||||
dest[ i ] = buffer[ offset ++ ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_setValue_array_setNeedsUpdate( buffer, offset ) {
|
||||
|
||||
const dest = this.resolvedProperty;
|
||||
|
||||
for ( let i = 0, n = dest.length; i !== n; ++ i ) {
|
||||
|
||||
dest[ i ] = buffer[ offset ++ ];
|
||||
|
||||
}
|
||||
|
||||
this.targetObject.needsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
_setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
|
||||
|
||||
const dest = this.resolvedProperty;
|
||||
|
||||
for ( let i = 0, n = dest.length; i !== n; ++ i ) {
|
||||
|
||||
dest[ i ] = buffer[ offset ++ ];
|
||||
|
||||
}
|
||||
|
||||
this.targetObject.matrixWorldNeedsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
// ArrayElement
|
||||
|
||||
_setValue_arrayElement( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
|
||||
|
||||
}
|
||||
|
||||
_setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
|
||||
this.targetObject.needsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
_setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
|
||||
this.targetObject.matrixWorldNeedsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
// HasToFromArray
|
||||
|
||||
_setValue_fromArray( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty.fromArray( buffer, offset );
|
||||
|
||||
}
|
||||
|
||||
_setValue_fromArray_setNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty.fromArray( buffer, offset );
|
||||
this.targetObject.needsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
_setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
|
||||
|
||||
this.resolvedProperty.fromArray( buffer, offset );
|
||||
this.targetObject.matrixWorldNeedsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
_getValue_unbound( targetArray, offset ) {
|
||||
|
||||
this.bind();
|
||||
this.getValue( targetArray, offset );
|
||||
|
||||
}
|
||||
|
||||
_setValue_unbound( sourceArray, offset ) {
|
||||
|
||||
this.bind();
|
||||
this.setValue( sourceArray, offset );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a getter / setter pair for the property tracked by this binding.
|
||||
*/
|
||||
bind() {
|
||||
|
||||
let targetObject = this.node;
|
||||
const parsedPath = this.parsedPath;
|
||||
|
||||
const objectName = parsedPath.objectName;
|
||||
const propertyName = parsedPath.propertyName;
|
||||
let propertyIndex = parsedPath.propertyIndex;
|
||||
|
||||
if ( ! targetObject ) {
|
||||
|
||||
targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName );
|
||||
|
||||
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.warn( 'THREE.PropertyBinding: No target node found for track: ' + this.path + '.' );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( objectName ) {
|
||||
|
||||
let 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( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( ! targetObject.material.materials ) {
|
||||
|
||||
console.error( 'THREE.PropertyBinding: 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( 'THREE.PropertyBinding: 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 ( let i = 0; i < targetObject.length; i ++ ) {
|
||||
|
||||
if ( targetObject[ i ].name === objectIndex ) {
|
||||
|
||||
objectIndex = i;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'map':
|
||||
|
||||
if ( 'map' in targetObject ) {
|
||||
|
||||
targetObject = targetObject.map;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( ! targetObject.material ) {
|
||||
|
||||
console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( ! targetObject.material.map ) {
|
||||
|
||||
console.error( 'THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
targetObject = targetObject.material.map;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
if ( targetObject[ objectName ] === undefined ) {
|
||||
|
||||
console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
targetObject = targetObject[ objectName ];
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ( objectIndex !== undefined ) {
|
||||
|
||||
if ( targetObject[ objectIndex ] === undefined ) {
|
||||
|
||||
console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
targetObject = targetObject[ objectIndex ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// resolve property
|
||||
const nodeProperty = targetObject[ propertyName ];
|
||||
|
||||
if ( nodeProperty === undefined ) {
|
||||
|
||||
const nodeName = parsedPath.nodeName;
|
||||
|
||||
console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
|
||||
'.' + propertyName + ' but it wasn\'t found.', targetObject );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// determine versioning scheme
|
||||
let versioning = this.Versioning.None;
|
||||
|
||||
this.targetObject = targetObject;
|
||||
|
||||
if ( targetObject.isMaterial === true ) {
|
||||
|
||||
versioning = this.Versioning.NeedsUpdate;
|
||||
|
||||
} else if ( targetObject.isObject3D === true ) {
|
||||
|
||||
versioning = this.Versioning.MatrixWorldNeedsUpdate;
|
||||
|
||||
}
|
||||
|
||||
// determine how the property gets bound
|
||||
let 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( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( ! targetObject.geometry.morphAttributes ) {
|
||||
|
||||
console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
|
||||
|
||||
propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 ( Array.isArray( nodeProperty ) ) {
|
||||
|
||||
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 ];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbinds the property.
|
||||
*/
|
||||
unbind() {
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PropertyBinding.Composite = Composite;
|
||||
|
||||
PropertyBinding.prototype.BindingType = {
|
||||
Direct: 0,
|
||||
EntireArray: 1,
|
||||
ArrayElement: 2,
|
||||
HasFromToArray: 3
|
||||
};
|
||||
|
||||
PropertyBinding.prototype.Versioning = {
|
||||
None: 0,
|
||||
NeedsUpdate: 1,
|
||||
MatrixWorldNeedsUpdate: 2
|
||||
};
|
||||
|
||||
PropertyBinding.prototype.GetterByBindingType = [
|
||||
|
||||
PropertyBinding.prototype._getValue_direct,
|
||||
PropertyBinding.prototype._getValue_array,
|
||||
PropertyBinding.prototype._getValue_arrayElement,
|
||||
PropertyBinding.prototype._getValue_toArray,
|
||||
|
||||
];
|
||||
|
||||
PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [
|
||||
|
||||
[
|
||||
// Direct
|
||||
PropertyBinding.prototype._setValue_direct,
|
||||
PropertyBinding.prototype._setValue_direct_setNeedsUpdate,
|
||||
PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate,
|
||||
|
||||
], [
|
||||
|
||||
// EntireArray
|
||||
|
||||
PropertyBinding.prototype._setValue_array,
|
||||
PropertyBinding.prototype._setValue_array_setNeedsUpdate,
|
||||
PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate,
|
||||
|
||||
], [
|
||||
|
||||
// ArrayElement
|
||||
PropertyBinding.prototype._setValue_arrayElement,
|
||||
PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate,
|
||||
PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate,
|
||||
|
||||
], [
|
||||
|
||||
// HasToFromArray
|
||||
PropertyBinding.prototype._setValue_fromArray,
|
||||
PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate,
|
||||
PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate,
|
||||
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
|
||||
export { PropertyBinding };
|
||||
385
app/node_modules/three/src/animation/PropertyMixer.js
generated
vendored
Normal file
385
app/node_modules/three/src/animation/PropertyMixer.js
generated
vendored
Normal file
@@ -0,0 +1,385 @@
|
||||
import { Quaternion } from '../math/Quaternion.js';
|
||||
|
||||
/**
|
||||
* Buffered scene graph property that allows weighted accumulation; used internally.
|
||||
*/
|
||||
class PropertyMixer {
|
||||
|
||||
/**
|
||||
* Constructs a new property mixer.
|
||||
*
|
||||
* @param {PropertyBinding} binding - The property binding.
|
||||
* @param {string} typeName - The keyframe track type name.
|
||||
* @param {number} valueSize - The keyframe track value size.
|
||||
*/
|
||||
constructor( binding, typeName, valueSize ) {
|
||||
|
||||
/**
|
||||
* The property binding.
|
||||
*
|
||||
* @type {PropertyBinding}
|
||||
*/
|
||||
this.binding = binding;
|
||||
|
||||
/**
|
||||
* The keyframe track value size.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.valueSize = valueSize;
|
||||
|
||||
let mixFunction,
|
||||
mixFunctionAdditive,
|
||||
setIdentity;
|
||||
|
||||
// buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// 'add' is used for additive cumulative results
|
||||
//
|
||||
// 'work' is optional and is only present for quaternion types. It is used
|
||||
// to store intermediate quaternion multiplication results
|
||||
|
||||
switch ( typeName ) {
|
||||
|
||||
case 'quaternion':
|
||||
mixFunction = this._slerp;
|
||||
mixFunctionAdditive = this._slerpAdditive;
|
||||
setIdentity = this._setAdditiveIdentityQuaternion;
|
||||
|
||||
this.buffer = new Float64Array( valueSize * 6 );
|
||||
this._workIndex = 5;
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
case 'bool':
|
||||
mixFunction = this._select;
|
||||
|
||||
// Use the regular mix function and for additive on these types,
|
||||
// additive is not relevant for non-numeric types
|
||||
mixFunctionAdditive = this._select;
|
||||
|
||||
setIdentity = this._setAdditiveIdentityOther;
|
||||
|
||||
this.buffer = new Array( valueSize * 5 );
|
||||
break;
|
||||
|
||||
default:
|
||||
mixFunction = this._lerp;
|
||||
mixFunctionAdditive = this._lerpAdditive;
|
||||
setIdentity = this._setAdditiveIdentityNumeric;
|
||||
|
||||
this.buffer = new Float64Array( valueSize * 5 );
|
||||
|
||||
}
|
||||
|
||||
this._mixBufferRegion = mixFunction;
|
||||
this._mixBufferRegionAdditive = mixFunctionAdditive;
|
||||
this._setIdentity = setIdentity;
|
||||
this._origIndex = 3;
|
||||
this._addIndex = 4;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.cumulativeWeight = 0;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.cumulativeWeightAdditive = 0;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.useCount = 0;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.referenceCount = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Accumulates data in the `incoming` region into `accu<i>`.
|
||||
*
|
||||
* @param {number} accuIndex - The accumulation index.
|
||||
* @param {number} weight - The weight.
|
||||
*/
|
||||
accumulate( 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
|
||||
|
||||
const buffer = this.buffer,
|
||||
stride = this.valueSize,
|
||||
offset = accuIndex * stride + stride;
|
||||
|
||||
let currentWeight = this.cumulativeWeight;
|
||||
|
||||
if ( currentWeight === 0 ) {
|
||||
|
||||
// accuN := incoming * weight
|
||||
|
||||
for ( let i = 0; i !== stride; ++ i ) {
|
||||
|
||||
buffer[ offset + i ] = buffer[ i ];
|
||||
|
||||
}
|
||||
|
||||
currentWeight = weight;
|
||||
|
||||
} else {
|
||||
|
||||
// accuN := accuN + incoming * weight
|
||||
|
||||
currentWeight += weight;
|
||||
const mix = weight / currentWeight;
|
||||
this._mixBufferRegion( buffer, offset, 0, mix, stride );
|
||||
|
||||
}
|
||||
|
||||
this.cumulativeWeight = currentWeight;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Accumulates data in the `incoming` region into `add`.
|
||||
*
|
||||
* @param {number} weight - The weight.
|
||||
*/
|
||||
accumulateAdditive( weight ) {
|
||||
|
||||
const buffer = this.buffer,
|
||||
stride = this.valueSize,
|
||||
offset = stride * this._addIndex;
|
||||
|
||||
if ( this.cumulativeWeightAdditive === 0 ) {
|
||||
|
||||
// add = identity
|
||||
|
||||
this._setIdentity();
|
||||
|
||||
}
|
||||
|
||||
// add := add + incoming * weight
|
||||
|
||||
this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
|
||||
this.cumulativeWeightAdditive += weight;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the state of `accu<i>` to the binding when accus differ.
|
||||
*
|
||||
* @param {number} accuIndex - The accumulation index.
|
||||
*/
|
||||
apply( accuIndex ) {
|
||||
|
||||
const stride = this.valueSize,
|
||||
buffer = this.buffer,
|
||||
offset = accuIndex * stride + stride,
|
||||
|
||||
weight = this.cumulativeWeight,
|
||||
weightAdditive = this.cumulativeWeightAdditive,
|
||||
|
||||
binding = this.binding;
|
||||
|
||||
this.cumulativeWeight = 0;
|
||||
this.cumulativeWeightAdditive = 0;
|
||||
|
||||
if ( weight < 1 ) {
|
||||
|
||||
// accuN := accuN + original * ( 1 - cumulativeWeight )
|
||||
|
||||
const originalValueOffset = stride * this._origIndex;
|
||||
|
||||
this._mixBufferRegion(
|
||||
buffer, offset, originalValueOffset, 1 - weight, stride );
|
||||
|
||||
}
|
||||
|
||||
if ( weightAdditive > 0 ) {
|
||||
|
||||
// accuN := accuN + additive accuN
|
||||
|
||||
this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
|
||||
|
||||
}
|
||||
|
||||
for ( let 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remembers the state of the bound property and copy it to both accus.
|
||||
*/
|
||||
saveOriginalState() {
|
||||
|
||||
const binding = this.binding;
|
||||
|
||||
const buffer = this.buffer,
|
||||
stride = this.valueSize,
|
||||
|
||||
originalValueOffset = stride * this._origIndex;
|
||||
|
||||
binding.getValue( buffer, originalValueOffset );
|
||||
|
||||
// accu[0..1] := orig -- initially detect changes against the original
|
||||
for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
|
||||
|
||||
buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
|
||||
|
||||
}
|
||||
|
||||
// Add to identity for additive
|
||||
this._setIdentity();
|
||||
|
||||
this.cumulativeWeight = 0;
|
||||
this.cumulativeWeightAdditive = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the state previously taken via {@link PropertyMixer#saveOriginalState} to the binding.
|
||||
*/
|
||||
restoreOriginalState() {
|
||||
|
||||
const originalValueOffset = this.valueSize * 3;
|
||||
this.binding.setValue( this.buffer, originalValueOffset );
|
||||
|
||||
}
|
||||
|
||||
// internals
|
||||
|
||||
_setAdditiveIdentityNumeric() {
|
||||
|
||||
const startIndex = this._addIndex * this.valueSize;
|
||||
const endIndex = startIndex + this.valueSize;
|
||||
|
||||
for ( let i = startIndex; i < endIndex; i ++ ) {
|
||||
|
||||
this.buffer[ i ] = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_setAdditiveIdentityQuaternion() {
|
||||
|
||||
this._setAdditiveIdentityNumeric();
|
||||
this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
|
||||
|
||||
}
|
||||
|
||||
_setAdditiveIdentityOther() {
|
||||
|
||||
const startIndex = this._origIndex * this.valueSize;
|
||||
const targetIndex = this._addIndex * this.valueSize;
|
||||
|
||||
for ( let i = 0; i < this.valueSize; i ++ ) {
|
||||
|
||||
this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// mix functions
|
||||
|
||||
_select( buffer, dstOffset, srcOffset, t, stride ) {
|
||||
|
||||
if ( t >= 0.5 ) {
|
||||
|
||||
for ( let i = 0; i !== stride; ++ i ) {
|
||||
|
||||
buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_slerp( buffer, dstOffset, srcOffset, t ) {
|
||||
|
||||
Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
|
||||
|
||||
}
|
||||
|
||||
_slerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
|
||||
|
||||
const workOffset = this._workIndex * stride;
|
||||
|
||||
// Store result in intermediate buffer offset
|
||||
Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
|
||||
|
||||
// Slerp to the intermediate result
|
||||
Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
|
||||
|
||||
}
|
||||
|
||||
_lerp( buffer, dstOffset, srcOffset, t, stride ) {
|
||||
|
||||
const s = 1 - t;
|
||||
|
||||
for ( let i = 0; i !== stride; ++ i ) {
|
||||
|
||||
const j = dstOffset + i;
|
||||
|
||||
buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_lerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
|
||||
|
||||
for ( let i = 0; i !== stride; ++ i ) {
|
||||
|
||||
const j = dstOffset + i;
|
||||
|
||||
buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { PropertyMixer };
|
||||
55
app/node_modules/three/src/animation/tracks/BooleanKeyframeTrack.js
generated
vendored
Normal file
55
app/node_modules/three/src/animation/tracks/BooleanKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import { InterpolateDiscrete } from '../../constants.js';
|
||||
import { KeyframeTrack } from '../KeyframeTrack.js';
|
||||
|
||||
/**
|
||||
* A track for boolean keyframe values.
|
||||
*
|
||||
* @augments KeyframeTrack
|
||||
*/
|
||||
class BooleanKeyframeTrack extends KeyframeTrack {
|
||||
|
||||
/**
|
||||
* Constructs a new boolean keyframe track.
|
||||
*
|
||||
* This keyframe track type has no `interpolation` parameter because the
|
||||
* interpolation is always discrete.
|
||||
*
|
||||
* @param {string} name - The keyframe track's name.
|
||||
* @param {Array<number>} times - A list of keyframe times.
|
||||
* @param {Array<number>} values - A list of keyframe values.
|
||||
*/
|
||||
constructor( name, times, values ) {
|
||||
|
||||
super( name, times, values );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The value type name.
|
||||
*
|
||||
* @type {String}
|
||||
* @default 'bool'
|
||||
*/
|
||||
BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
|
||||
|
||||
/**
|
||||
* The value buffer type of this keyframe track.
|
||||
*
|
||||
* @type {TypedArray|Array}
|
||||
* @default Array.constructor
|
||||
*/
|
||||
BooleanKeyframeTrack.prototype.ValueBufferType = Array;
|
||||
|
||||
/**
|
||||
* The default interpolation type of this keyframe track.
|
||||
*
|
||||
* @type {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)}
|
||||
* @default InterpolateDiscrete
|
||||
*/
|
||||
BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
|
||||
BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
|
||||
BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
|
||||
|
||||
export { BooleanKeyframeTrack };
|
||||
36
app/node_modules/three/src/animation/tracks/ColorKeyframeTrack.js
generated
vendored
Normal file
36
app/node_modules/three/src/animation/tracks/ColorKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import { KeyframeTrack } from '../KeyframeTrack.js';
|
||||
|
||||
/**
|
||||
* A track for color keyframe values.
|
||||
*
|
||||
* @augments KeyframeTrack
|
||||
*/
|
||||
class ColorKeyframeTrack extends KeyframeTrack {
|
||||
|
||||
/**
|
||||
* Constructs a new color keyframe track.
|
||||
*
|
||||
* @param {string} name - The keyframe track's name.
|
||||
* @param {Array<number>} times - A list of keyframe times.
|
||||
* @param {Array<number>} values - A list of keyframe values.
|
||||
* @param {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)} [interpolation] - The interpolation type.
|
||||
*/
|
||||
constructor( name, times, values, interpolation ) {
|
||||
|
||||
super( name, times, values, interpolation );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The value type name.
|
||||
*
|
||||
* @type {String}
|
||||
* @default 'color'
|
||||
*/
|
||||
ColorKeyframeTrack.prototype.ValueTypeName = 'color';
|
||||
// ValueBufferType is inherited
|
||||
// DefaultInterpolation is inherited
|
||||
|
||||
export { ColorKeyframeTrack };
|
||||
36
app/node_modules/three/src/animation/tracks/NumberKeyframeTrack.js
generated
vendored
Normal file
36
app/node_modules/three/src/animation/tracks/NumberKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import { KeyframeTrack } from '../KeyframeTrack.js';
|
||||
|
||||
/**
|
||||
* A track for numeric keyframe values.
|
||||
*
|
||||
* @augments KeyframeTrack
|
||||
*/
|
||||
class NumberKeyframeTrack extends KeyframeTrack {
|
||||
|
||||
/**
|
||||
* Constructs a new number keyframe track.
|
||||
*
|
||||
* @param {string} name - The keyframe track's name.
|
||||
* @param {Array<number>} times - A list of keyframe times.
|
||||
* @param {Array<number>} values - A list of keyframe values.
|
||||
* @param {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)} [interpolation] - The interpolation type.
|
||||
*/
|
||||
constructor( name, times, values, interpolation ) {
|
||||
|
||||
super( name, times, values, interpolation );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The value type name.
|
||||
*
|
||||
* @type {String}
|
||||
* @default 'number'
|
||||
*/
|
||||
NumberKeyframeTrack.prototype.ValueTypeName = 'number';
|
||||
// ValueBufferType is inherited
|
||||
// DefaultInterpolation is inherited
|
||||
|
||||
export { NumberKeyframeTrack };
|
||||
51
app/node_modules/three/src/animation/tracks/QuaternionKeyframeTrack.js
generated
vendored
Normal file
51
app/node_modules/three/src/animation/tracks/QuaternionKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import { KeyframeTrack } from '../KeyframeTrack.js';
|
||||
import { QuaternionLinearInterpolant } from '../../math/interpolants/QuaternionLinearInterpolant.js';
|
||||
|
||||
/**
|
||||
* A track for Quaternion keyframe values.
|
||||
*
|
||||
* @augments KeyframeTrack
|
||||
*/
|
||||
class QuaternionKeyframeTrack extends KeyframeTrack {
|
||||
|
||||
/**
|
||||
* Constructs a new Quaternion keyframe track.
|
||||
*
|
||||
* @param {string} name - The keyframe track's name.
|
||||
* @param {Array<number>} times - A list of keyframe times.
|
||||
* @param {Array<number>} values - A list of keyframe values.
|
||||
* @param {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)} [interpolation] - The interpolation type.
|
||||
*/
|
||||
constructor( name, times, values, interpolation ) {
|
||||
|
||||
super( name, times, values, interpolation );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwritten so the method returns Quaternion based interpolant.
|
||||
*
|
||||
* @static
|
||||
* @param {TypedArray} [result] - The result buffer.
|
||||
* @return {QuaternionLinearInterpolant} The new interpolant.
|
||||
*/
|
||||
InterpolantFactoryMethodLinear( result ) {
|
||||
|
||||
return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The value type name.
|
||||
*
|
||||
* @type {String}
|
||||
* @default 'quaternion'
|
||||
*/
|
||||
QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
|
||||
// ValueBufferType is inherited
|
||||
// DefaultInterpolation is inherited;
|
||||
QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
|
||||
|
||||
export { QuaternionKeyframeTrack };
|
||||
55
app/node_modules/three/src/animation/tracks/StringKeyframeTrack.js
generated
vendored
Normal file
55
app/node_modules/three/src/animation/tracks/StringKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import { InterpolateDiscrete } from '../../constants.js';
|
||||
import { KeyframeTrack } from '../KeyframeTrack.js';
|
||||
|
||||
/**
|
||||
* A track for string keyframe values.
|
||||
*
|
||||
* @augments KeyframeTrack
|
||||
*/
|
||||
class StringKeyframeTrack extends KeyframeTrack {
|
||||
|
||||
/**
|
||||
* Constructs a new string keyframe track.
|
||||
*
|
||||
* This keyframe track type has no `interpolation` parameter because the
|
||||
* interpolation is always discrete.
|
||||
*
|
||||
* @param {string} name - The keyframe track's name.
|
||||
* @param {Array<number>} times - A list of keyframe times.
|
||||
* @param {Array<number>} values - A list of keyframe values.
|
||||
*/
|
||||
constructor( name, times, values ) {
|
||||
|
||||
super( name, times, values );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The value type name.
|
||||
*
|
||||
* @type {String}
|
||||
* @default 'string'
|
||||
*/
|
||||
StringKeyframeTrack.prototype.ValueTypeName = 'string';
|
||||
|
||||
/**
|
||||
* The value buffer type of this keyframe track.
|
||||
*
|
||||
* @type {TypedArray|Array}
|
||||
* @default Array.constructor
|
||||
*/
|
||||
StringKeyframeTrack.prototype.ValueBufferType = Array;
|
||||
|
||||
/**
|
||||
* The default interpolation type of this keyframe track.
|
||||
*
|
||||
* @type {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)}
|
||||
* @default InterpolateDiscrete
|
||||
*/
|
||||
StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
|
||||
StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
|
||||
StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
|
||||
|
||||
export { StringKeyframeTrack };
|
||||
36
app/node_modules/three/src/animation/tracks/VectorKeyframeTrack.js
generated
vendored
Normal file
36
app/node_modules/three/src/animation/tracks/VectorKeyframeTrack.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import { KeyframeTrack } from '../KeyframeTrack.js';
|
||||
|
||||
/**
|
||||
* A track for vector keyframe values.
|
||||
*
|
||||
* @augments KeyframeTrack
|
||||
*/
|
||||
class VectorKeyframeTrack extends KeyframeTrack {
|
||||
|
||||
/**
|
||||
* Constructs a new vector keyframe track.
|
||||
*
|
||||
* @param {string} name - The keyframe track's name.
|
||||
* @param {Array<number>} times - A list of keyframe times.
|
||||
* @param {Array<number>} values - A list of keyframe values.
|
||||
* @param {(InterpolateLinear|InterpolateDiscrete|InterpolateSmooth)} [interpolation] - The interpolation type.
|
||||
*/
|
||||
constructor( name, times, values, interpolation ) {
|
||||
|
||||
super( name, times, values, interpolation );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The value type name.
|
||||
*
|
||||
* @type {String}
|
||||
* @default 'vector'
|
||||
*/
|
||||
VectorKeyframeTrack.prototype.ValueTypeName = 'vector';
|
||||
// ValueBufferType is inherited
|
||||
// DefaultInterpolation is inherited
|
||||
|
||||
export { VectorKeyframeTrack };
|
||||
777
app/node_modules/three/src/audio/Audio.js
generated
vendored
Normal file
777
app/node_modules/three/src/audio/Audio.js
generated
vendored
Normal file
@@ -0,0 +1,777 @@
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
|
||||
/**
|
||||
* Represents a non-positional ( global ) audio object.
|
||||
*
|
||||
* This and related audio modules make use of the [Web Audio API]{@link https://www.w3.org/TR/webaudio-1.1/}.
|
||||
*
|
||||
* ```js
|
||||
* // create an AudioListener and add it to the camera
|
||||
* const listener = new THREE.AudioListener();
|
||||
* camera.add( listener );
|
||||
*
|
||||
* // create a global audio source
|
||||
* const sound = new THREE.Audio( listener );
|
||||
*
|
||||
* // load a sound and set it as the Audio object's buffer
|
||||
* const audioLoader = new THREE.AudioLoader();
|
||||
* audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
|
||||
* sound.setBuffer( buffer );
|
||||
* sound.setLoop( true );
|
||||
* sound.setVolume( 0.5 );
|
||||
* sound.play();
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @augments Object3D
|
||||
*/
|
||||
class Audio extends Object3D {
|
||||
|
||||
/**
|
||||
* Constructs a new audio.
|
||||
*
|
||||
* @param {AudioListener} listener - The global audio listener.
|
||||
*/
|
||||
constructor( listener ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'Audio';
|
||||
|
||||
/**
|
||||
* The global audio listener.
|
||||
*
|
||||
* @type {AudioListener}
|
||||
* @readonly
|
||||
*/
|
||||
this.listener = listener;
|
||||
|
||||
/**
|
||||
* The audio context.
|
||||
*
|
||||
* @type {AudioContext}
|
||||
* @readonly
|
||||
*/
|
||||
this.context = listener.context;
|
||||
|
||||
/**
|
||||
* The gain node used for volume control.
|
||||
*
|
||||
* @type {GainNode}
|
||||
* @readonly
|
||||
*/
|
||||
this.gain = this.context.createGain();
|
||||
this.gain.connect( listener.getInput() );
|
||||
|
||||
/**
|
||||
* Whether to start playback automatically or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.autoplay = false;
|
||||
|
||||
/**
|
||||
* A reference to an audio buffer.
|
||||
*
|
||||
* Defined via {@link Audio#setBuffer}.
|
||||
*
|
||||
* @type {?AudioBuffer}
|
||||
* @default null
|
||||
* @readonly
|
||||
*/
|
||||
this.buffer = null;
|
||||
|
||||
/**
|
||||
* Modify pitch, measured in cents. +/- 100 is a semitone.
|
||||
* +/- 1200 is an octave.
|
||||
*
|
||||
* Defined via {@link Audio#setDetune}.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @readonly
|
||||
*/
|
||||
this.detune = 0;
|
||||
|
||||
/**
|
||||
* Whether the audio should loop or not.
|
||||
*
|
||||
* Defined via {@link Audio#setLoop}.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
* @readonly
|
||||
*/
|
||||
this.loop = false;
|
||||
|
||||
/**
|
||||
* Defines where in the audio buffer the replay should
|
||||
* start, in seconds.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.loopStart = 0;
|
||||
|
||||
/**
|
||||
* Defines where in the audio buffer the replay should
|
||||
* stop, in seconds.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.loopEnd = 0;
|
||||
|
||||
/**
|
||||
* An offset to the time within the audio buffer the playback
|
||||
* should begin, in seconds.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.offset = 0;
|
||||
|
||||
/**
|
||||
* Overrides the default duration of the audio.
|
||||
*
|
||||
* @type {undefined|number}
|
||||
* @default undefined
|
||||
*/
|
||||
this.duration = undefined;
|
||||
|
||||
/**
|
||||
* The playback speed.
|
||||
*
|
||||
* Defined via {@link Audio#setPlaybackRate}.
|
||||
*
|
||||
* @type {number}
|
||||
* @readonly
|
||||
* @default 1
|
||||
*/
|
||||
this.playbackRate = 1;
|
||||
|
||||
/**
|
||||
* Indicates whether the audio is playing or not.
|
||||
*
|
||||
* This flag will be automatically set when using {@link Audio#play},
|
||||
* {@link Audio#pause}, {@link Audio#stop}.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default false
|
||||
*/
|
||||
this.isPlaying = false;
|
||||
|
||||
/**
|
||||
* Indicates whether the audio playback can be controlled
|
||||
* with method like {@link Audio#play} or {@link Audio#pause}.
|
||||
*
|
||||
* This flag will be automatically set when audio sources are
|
||||
* defined.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.hasPlaybackControl = true;
|
||||
|
||||
/**
|
||||
* Holds a reference to the current audio source.
|
||||
*
|
||||
* The property is automatically by one of the `set*()` methods.
|
||||
*
|
||||
* @type {?AudioNode}
|
||||
* @readonly
|
||||
* @default null
|
||||
*/
|
||||
this.source = null;
|
||||
|
||||
/**
|
||||
* Defines the source type.
|
||||
*
|
||||
* The property is automatically by one of the `set*()` methods.
|
||||
*
|
||||
* @type {('empty'|'audioNode'|'mediaNode'|'mediaStreamNode'|'buffer')}
|
||||
* @readonly
|
||||
* @default 'empty'
|
||||
*/
|
||||
this.sourceType = 'empty';
|
||||
|
||||
this._startedAt = 0;
|
||||
this._progress = 0;
|
||||
this._connected = false;
|
||||
|
||||
/**
|
||||
* Can be used to apply a variety of low-order filters to create
|
||||
* more complex sound effects e.g. via `BiquadFilterNode`.
|
||||
*
|
||||
* The property is automatically set by {@link Audio#setFilters}.
|
||||
*
|
||||
* @type {Array<AudioNode>}
|
||||
* @readonly
|
||||
*/
|
||||
this.filters = [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output audio node.
|
||||
*
|
||||
* @return {GainNode} The output node.
|
||||
*/
|
||||
getOutput() {
|
||||
|
||||
return this.gain;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given audio node as the source of this instance.
|
||||
*
|
||||
* {@link Audio#sourceType} is set to `audioNode` and {@link Audio#hasPlaybackControl} to `false`.
|
||||
*
|
||||
* @param {AudioNode} audioNode - The audio node like an instance of `OscillatorNode`.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setNodeSource( audioNode ) {
|
||||
|
||||
this.hasPlaybackControl = false;
|
||||
this.sourceType = 'audioNode';
|
||||
this.source = audioNode;
|
||||
this.connect();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given media element as the source of this instance.
|
||||
*
|
||||
* {@link Audio#sourceType} is set to `mediaNode` and {@link Audio#hasPlaybackControl} to `false`.
|
||||
*
|
||||
* @param {HTMLMediaElement} mediaElement - The media element.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setMediaElementSource( mediaElement ) {
|
||||
|
||||
this.hasPlaybackControl = false;
|
||||
this.sourceType = 'mediaNode';
|
||||
this.source = this.context.createMediaElementSource( mediaElement );
|
||||
this.connect();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given media stream as the source of this instance.
|
||||
*
|
||||
* {@link Audio#sourceType} is set to `mediaStreamNode` and {@link Audio#hasPlaybackControl} to `false`.
|
||||
*
|
||||
* @param {MediaStream} mediaStream - The media stream.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setMediaStreamSource( mediaStream ) {
|
||||
|
||||
this.hasPlaybackControl = false;
|
||||
this.sourceType = 'mediaStreamNode';
|
||||
this.source = this.context.createMediaStreamSource( mediaStream );
|
||||
this.connect();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given audio buffer as the source of this instance.
|
||||
*
|
||||
* {@link Audio#sourceType} is set to `buffer` and {@link Audio#hasPlaybackControl} to `true`.
|
||||
*
|
||||
* @param {AudioBuffer} audioBuffer - The audio buffer.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setBuffer( audioBuffer ) {
|
||||
|
||||
this.buffer = audioBuffer;
|
||||
this.sourceType = 'buffer';
|
||||
|
||||
if ( this.autoplay ) this.play();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the playback of the audio.
|
||||
*
|
||||
* Can only be used with compatible audio sources that allow playback control.
|
||||
*
|
||||
* @param {number} [delay=0] - The delay, in seconds, at which the audio should start playing.
|
||||
* @return {Audio|undefined} A reference to this instance.
|
||||
*/
|
||||
play( delay = 0 ) {
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
this._startedAt = this.context.currentTime + delay;
|
||||
|
||||
const source = this.context.createBufferSource();
|
||||
source.buffer = this.buffer;
|
||||
source.loop = this.loop;
|
||||
source.loopStart = this.loopStart;
|
||||
source.loopEnd = this.loopEnd;
|
||||
source.onended = this.onEnded.bind( this );
|
||||
source.start( this._startedAt, this._progress + this.offset, this.duration );
|
||||
|
||||
this.isPlaying = true;
|
||||
|
||||
this.source = source;
|
||||
|
||||
this.setDetune( this.detune );
|
||||
this.setPlaybackRate( this.playbackRate );
|
||||
|
||||
return this.connect();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses the playback of the audio.
|
||||
*
|
||||
* Can only be used with compatible audio sources that allow playback control.
|
||||
*
|
||||
* @return {Audio|undefined} A reference to this instance.
|
||||
*/
|
||||
pause() {
|
||||
|
||||
if ( this.hasPlaybackControl === false ) {
|
||||
|
||||
console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( this.isPlaying === true ) {
|
||||
|
||||
// update current progress
|
||||
|
||||
this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
|
||||
|
||||
if ( this.loop === true ) {
|
||||
|
||||
// ensure _progress does not exceed duration with looped audios
|
||||
|
||||
this._progress = this._progress % ( this.duration || this.buffer.duration );
|
||||
|
||||
}
|
||||
|
||||
this.source.stop();
|
||||
this.source.onended = null;
|
||||
|
||||
this.isPlaying = false;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the playback of the audio.
|
||||
*
|
||||
* Can only be used with compatible audio sources that allow playback control.
|
||||
*
|
||||
* @param {number} [delay=0] - The delay, in seconds, at which the audio should stop playing.
|
||||
* @return {Audio|undefined} A reference to this instance.
|
||||
*/
|
||||
stop( delay = 0 ) {
|
||||
|
||||
if ( this.hasPlaybackControl === false ) {
|
||||
|
||||
console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this._progress = 0;
|
||||
|
||||
if ( this.source !== null ) {
|
||||
|
||||
this.source.stop( this.context.currentTime + delay );
|
||||
this.source.onended = null;
|
||||
|
||||
}
|
||||
|
||||
this.isPlaying = false;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the audio source. This is used internally on
|
||||
* initialisation and when setting / removing filters.
|
||||
*
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
connect() {
|
||||
|
||||
if ( this.filters.length > 0 ) {
|
||||
|
||||
this.source.connect( this.filters[ 0 ] );
|
||||
|
||||
for ( let 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() );
|
||||
|
||||
}
|
||||
|
||||
this._connected = true;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects to the audio source. This is used internally on
|
||||
* initialisation and when setting / removing filters.
|
||||
*
|
||||
* @return {Audio|undefined} A reference to this instance.
|
||||
*/
|
||||
disconnect() {
|
||||
|
||||
if ( this._connected === false ) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( this.filters.length > 0 ) {
|
||||
|
||||
this.source.disconnect( this.filters[ 0 ] );
|
||||
|
||||
for ( let 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() );
|
||||
|
||||
}
|
||||
|
||||
this._connected = false;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current set filters.
|
||||
*
|
||||
* @return {Array<AudioNode>} The list of filters.
|
||||
*/
|
||||
getFilters() {
|
||||
|
||||
return this.filters;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an array of filters and connects them with the audio source.
|
||||
*
|
||||
* @param {Array<AudioNode>} [value] - A list of filters.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setFilters( value ) {
|
||||
|
||||
if ( ! value ) value = [];
|
||||
|
||||
if ( this._connected === true ) {
|
||||
|
||||
this.disconnect();
|
||||
this.filters = value.slice();
|
||||
this.connect();
|
||||
|
||||
} else {
|
||||
|
||||
this.filters = value.slice();
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the detuning of oscillation in cents.
|
||||
*
|
||||
* @param {number} value - The detuning of oscillation in cents.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setDetune( value ) {
|
||||
|
||||
this.detune = value;
|
||||
|
||||
if ( this.isPlaying === true && this.source.detune !== undefined ) {
|
||||
|
||||
this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the detuning of oscillation in cents.
|
||||
*
|
||||
* @return {number} The detuning of oscillation in cents.
|
||||
*/
|
||||
getDetune() {
|
||||
|
||||
return this.detune;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first filter in the list of filters.
|
||||
*
|
||||
* @return {AudioNode|undefined} The first filter in the list of filters.
|
||||
*/
|
||||
getFilter() {
|
||||
|
||||
return this.getFilters()[ 0 ];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a single filter node to the audio.
|
||||
*
|
||||
* @param {AudioNode} [filter] - The filter to set.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setFilter( filter ) {
|
||||
|
||||
return this.setFilters( filter ? [ filter ] : [] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the playback rate.
|
||||
*
|
||||
* Can only be used with compatible audio sources that allow playback control.
|
||||
*
|
||||
* @param {number} [value] - The playback rate to set.
|
||||
* @return {Audio|undefined} A reference to this instance.
|
||||
*/
|
||||
setPlaybackRate( 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.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current playback rate.
|
||||
|
||||
* @return {number} The playback rate.
|
||||
*/
|
||||
getPlaybackRate() {
|
||||
|
||||
return this.playbackRate;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically called when playback finished.
|
||||
*/
|
||||
onEnded() {
|
||||
|
||||
this.isPlaying = false;
|
||||
this._progress = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loop flag.
|
||||
*
|
||||
* Can only be used with compatible audio sources that allow playback control.
|
||||
*
|
||||
* @return {boolean} Whether the audio should loop or not.
|
||||
*/
|
||||
getLoop() {
|
||||
|
||||
if ( this.hasPlaybackControl === false ) {
|
||||
|
||||
console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return this.loop;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop flag.
|
||||
*
|
||||
* Can only be used with compatible audio sources that allow playback control.
|
||||
*
|
||||
* @param {boolean} value - Whether the audio should loop or not.
|
||||
* @return {Audio|undefined} A reference to this instance.
|
||||
*/
|
||||
setLoop( 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop start value which defines where in the audio buffer the replay should
|
||||
* start, in seconds.
|
||||
*
|
||||
* @param {number} value - The loop start value.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setLoopStart( value ) {
|
||||
|
||||
this.loopStart = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop end value which defines where in the audio buffer the replay should
|
||||
* stop, in seconds.
|
||||
*
|
||||
* @param {number} value - The loop end value.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setLoopEnd( value ) {
|
||||
|
||||
this.loopEnd = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the volume.
|
||||
*
|
||||
* @return {number} The volume.
|
||||
*/
|
||||
getVolume() {
|
||||
|
||||
return this.gain.gain.value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume.
|
||||
*
|
||||
* @param {number} value - The volume to set.
|
||||
* @return {Audio} A reference to this instance.
|
||||
*/
|
||||
setVolume( value ) {
|
||||
|
||||
this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
copy( source, recursive ) {
|
||||
|
||||
super.copy( source, recursive );
|
||||
|
||||
if ( source.sourceType !== 'buffer' ) {
|
||||
|
||||
console.warn( 'THREE.Audio: Audio source type cannot be copied.' );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
this.autoplay = source.autoplay;
|
||||
|
||||
this.buffer = source.buffer;
|
||||
this.detune = source.detune;
|
||||
this.loop = source.loop;
|
||||
this.loopStart = source.loopStart;
|
||||
this.loopEnd = source.loopEnd;
|
||||
this.offset = source.offset;
|
||||
this.duration = source.duration;
|
||||
this.playbackRate = source.playbackRate;
|
||||
this.hasPlaybackControl = source.hasPlaybackControl;
|
||||
this.sourceType = source.sourceType;
|
||||
|
||||
this.filters = source.filters.slice();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
clone( recursive ) {
|
||||
|
||||
return new this.constructor( this.listener ).copy( this, recursive );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Audio };
|
||||
97
app/node_modules/three/src/audio/AudioAnalyser.js
generated
vendored
Normal file
97
app/node_modules/three/src/audio/AudioAnalyser.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* This class can be used to analyse audio data.
|
||||
*
|
||||
* ```js
|
||||
* // create an AudioListener and add it to the camera
|
||||
* const listener = new THREE.AudioListener();
|
||||
* camera.add( listener );
|
||||
*
|
||||
* // create an Audio source
|
||||
* const sound = new THREE.Audio( listener );
|
||||
*
|
||||
* // load a sound and set it as the Audio object's buffer
|
||||
* const audioLoader = new THREE.AudioLoader();
|
||||
* audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
|
||||
* sound.setBuffer( buffer );
|
||||
* sound.setLoop(true);
|
||||
* sound.setVolume(0.5);
|
||||
* sound.play();
|
||||
* });
|
||||
*
|
||||
* // create an AudioAnalyser, passing in the sound and desired fftSize
|
||||
* const analyser = new THREE.AudioAnalyser( sound, 32 );
|
||||
*
|
||||
* // get the average frequency of the sound
|
||||
* const data = analyser.getAverageFrequency();
|
||||
* ```
|
||||
*/
|
||||
class AudioAnalyser {
|
||||
|
||||
/**
|
||||
* Constructs a new audio analyzer.
|
||||
*
|
||||
* @param {Audio} audio - The audio to analyze.
|
||||
* @param {number} [fftSize=2048] - The window size in samples that is used when performing a Fast Fourier Transform (FFT) to get frequency domain data.
|
||||
*/
|
||||
constructor( audio, fftSize = 2048 ) {
|
||||
|
||||
/**
|
||||
* The global audio listener.
|
||||
*
|
||||
* @type {AnalyserNode}
|
||||
*/
|
||||
this.analyser = audio.context.createAnalyser();
|
||||
this.analyser.fftSize = fftSize;
|
||||
|
||||
/**
|
||||
* Holds the analyzed data.
|
||||
*
|
||||
* @type {Uint8Array}
|
||||
*/
|
||||
this.data = new Uint8Array( this.analyser.frequencyBinCount );
|
||||
|
||||
audio.getOutput().connect( this.analyser );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with frequency data of the audio.
|
||||
*
|
||||
* Each item in the array represents the decibel value for a specific frequency.
|
||||
* The frequencies are spread linearly from 0 to 1/2 of the sample rate.
|
||||
* For example, for 48000 sample rate, the last item of the array will represent
|
||||
* the decibel value for 24000 Hz.
|
||||
*
|
||||
* @return {Uint8Array} The frequency data.
|
||||
*/
|
||||
getFrequencyData() {
|
||||
|
||||
this.analyser.getByteFrequencyData( this.data );
|
||||
|
||||
return this.data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the average of the frequencies returned by {@link AudioAnalyser#getFrequencyData}.
|
||||
*
|
||||
* @return {number} The average frequency.
|
||||
*/
|
||||
getAverageFrequency() {
|
||||
|
||||
let value = 0;
|
||||
const data = this.getFrequencyData();
|
||||
|
||||
for ( let i = 0; i < data.length; i ++ ) {
|
||||
|
||||
value += data[ i ];
|
||||
|
||||
}
|
||||
|
||||
return value / data.length;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { AudioAnalyser };
|
||||
40
app/node_modules/three/src/audio/AudioContext.js
generated
vendored
Normal file
40
app/node_modules/three/src/audio/AudioContext.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
let _context;
|
||||
|
||||
/**
|
||||
* Manages the global audio context in the engine.
|
||||
*
|
||||
* @hideconstructor
|
||||
*/
|
||||
class AudioContext {
|
||||
|
||||
/**
|
||||
* Returns the global native audio context.
|
||||
*
|
||||
* @return {AudioContext} The native audio context.
|
||||
*/
|
||||
static getContext() {
|
||||
|
||||
if ( _context === undefined ) {
|
||||
|
||||
_context = new ( window.AudioContext || window.webkitAudioContext )();
|
||||
|
||||
}
|
||||
|
||||
return _context;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to set the global native audio context from outside.
|
||||
*
|
||||
* @param {AudioContext} value - The native context to set.
|
||||
*/
|
||||
static setContext( value ) {
|
||||
|
||||
_context = value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { AudioContext };
|
||||
216
app/node_modules/three/src/audio/AudioListener.js
generated
vendored
Normal file
216
app/node_modules/three/src/audio/AudioListener.js
generated
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Quaternion } from '../math/Quaternion.js';
|
||||
import { Clock } from '../core/Clock.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { AudioContext } from './AudioContext.js';
|
||||
|
||||
const _position = /*@__PURE__*/ new Vector3();
|
||||
const _quaternion = /*@__PURE__*/ new Quaternion();
|
||||
const _scale = /*@__PURE__*/ new Vector3();
|
||||
|
||||
const _forward = /*@__PURE__*/ new Vector3();
|
||||
const _up = /*@__PURE__*/ new Vector3();
|
||||
|
||||
/**
|
||||
* The class represents a virtual listener of the all positional and non-positional audio effects
|
||||
* in the scene. A three.js application usually creates a single listener. It is a mandatory
|
||||
* constructor parameter for audios entities like {@link Audio} and {@link PositionalAudio}.
|
||||
*
|
||||
* In most cases, the listener object is a child of the camera. So the 3D transformation of the
|
||||
* camera represents the 3D transformation of the listener.
|
||||
*
|
||||
* @augments Object3D
|
||||
*/
|
||||
class AudioListener extends Object3D {
|
||||
|
||||
/**
|
||||
* Constructs a new audio listener.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'AudioListener';
|
||||
|
||||
/**
|
||||
* The native audio context.
|
||||
*
|
||||
* @type {AudioContext}
|
||||
* @readonly
|
||||
*/
|
||||
this.context = AudioContext.getContext();
|
||||
|
||||
/**
|
||||
* The gain node used for volume control.
|
||||
*
|
||||
* @type {GainNode}
|
||||
* @readonly
|
||||
*/
|
||||
this.gain = this.context.createGain();
|
||||
this.gain.connect( this.context.destination );
|
||||
|
||||
/**
|
||||
* An optional filter.
|
||||
*
|
||||
* Defined via {@link AudioListener#setFilter}.
|
||||
*
|
||||
* @type {?AudioNode}
|
||||
* @default null
|
||||
* @readonly
|
||||
*/
|
||||
this.filter = null;
|
||||
|
||||
/**
|
||||
* Time delta values required for `linearRampToValueAtTime()` usage.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @readonly
|
||||
*/
|
||||
this.timeDelta = 0;
|
||||
|
||||
// private
|
||||
|
||||
this._clock = new Clock();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the listener's input node.
|
||||
*
|
||||
* This method is used by other audio nodes to connect to this listener.
|
||||
*
|
||||
* @return {GainNode} The input node.
|
||||
*/
|
||||
getInput() {
|
||||
|
||||
return this.gain;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the current filter from this listener.
|
||||
*
|
||||
* @return {AudioListener} A reference to this listener.
|
||||
*/
|
||||
removeFilter() {
|
||||
|
||||
if ( this.filter !== null ) {
|
||||
|
||||
this.gain.disconnect( this.filter );
|
||||
this.filter.disconnect( this.context.destination );
|
||||
this.gain.connect( this.context.destination );
|
||||
this.filter = null;
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current set filter.
|
||||
*
|
||||
* @return {?AudioNode} The filter.
|
||||
*/
|
||||
getFilter() {
|
||||
|
||||
return this.filter;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given filter to this listener.
|
||||
*
|
||||
* @param {AudioNode} value - The filter to set.
|
||||
* @return {AudioListener} A reference to this listener.
|
||||
*/
|
||||
setFilter( 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 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the applications master volume.
|
||||
*
|
||||
* @return {number} The master volume.
|
||||
*/
|
||||
getMasterVolume() {
|
||||
|
||||
return this.gain.gain.value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the applications master volume. This volume setting affects
|
||||
* all audio nodes in the scene.
|
||||
*
|
||||
* @param {number} value - The master volume to set.
|
||||
* @return {AudioListener} A reference to this listener.
|
||||
*/
|
||||
setMasterVolume( value ) {
|
||||
|
||||
this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
updateMatrixWorld( force ) {
|
||||
|
||||
super.updateMatrixWorld( force );
|
||||
|
||||
const listener = this.context.listener;
|
||||
|
||||
this.timeDelta = this._clock.getDelta();
|
||||
|
||||
this.matrixWorld.decompose( _position, _quaternion, _scale );
|
||||
|
||||
// the initial forward and up directions must be orthogonal
|
||||
_forward.set( 0, 0, - 1 ).applyQuaternion( _quaternion );
|
||||
_up.set( 0, 1, 0 ).applyQuaternion( _quaternion );
|
||||
|
||||
if ( listener.positionX ) {
|
||||
|
||||
// code path for Chrome (see #14393)
|
||||
|
||||
const endTime = this.context.currentTime + this.timeDelta;
|
||||
|
||||
listener.positionX.linearRampToValueAtTime( _position.x, endTime );
|
||||
listener.positionY.linearRampToValueAtTime( _position.y, endTime );
|
||||
listener.positionZ.linearRampToValueAtTime( _position.z, endTime );
|
||||
listener.forwardX.linearRampToValueAtTime( _forward.x, endTime );
|
||||
listener.forwardY.linearRampToValueAtTime( _forward.y, endTime );
|
||||
listener.forwardZ.linearRampToValueAtTime( _forward.z, endTime );
|
||||
listener.upX.linearRampToValueAtTime( _up.x, endTime );
|
||||
listener.upY.linearRampToValueAtTime( _up.y, endTime );
|
||||
listener.upZ.linearRampToValueAtTime( _up.z, endTime );
|
||||
|
||||
} else {
|
||||
|
||||
listener.setPosition( _position.x, _position.y, _position.z );
|
||||
listener.setOrientation( _forward.x, _forward.y, _forward.z, _up.x, _up.y, _up.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { AudioListener };
|
||||
253
app/node_modules/three/src/audio/PositionalAudio.js
generated
vendored
Normal file
253
app/node_modules/three/src/audio/PositionalAudio.js
generated
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Quaternion } from '../math/Quaternion.js';
|
||||
import { Audio } from './Audio.js';
|
||||
|
||||
const _position = /*@__PURE__*/ new Vector3();
|
||||
const _quaternion = /*@__PURE__*/ new Quaternion();
|
||||
const _scale = /*@__PURE__*/ new Vector3();
|
||||
const _orientation = /*@__PURE__*/ new Vector3();
|
||||
|
||||
/**
|
||||
* Represents a positional audio object.
|
||||
*
|
||||
* ```js
|
||||
* // create an AudioListener and add it to the camera
|
||||
* const listener = new THREE.AudioListener();
|
||||
* camera.add( listener );
|
||||
*
|
||||
* // create the PositionalAudio object (passing in the listener)
|
||||
* const sound = new THREE.PositionalAudio( listener );
|
||||
*
|
||||
* // load a sound and set it as the PositionalAudio object's buffer
|
||||
* const audioLoader = new THREE.AudioLoader();
|
||||
* audioLoader.load( 'sounds/song.ogg', function( buffer ) {
|
||||
* sound.setBuffer( buffer );
|
||||
* sound.setRefDistance( 20 );
|
||||
* sound.play();
|
||||
* });
|
||||
*
|
||||
* // create an object for the sound to play from
|
||||
* const sphere = new THREE.SphereGeometry( 20, 32, 16 );
|
||||
* const material = new THREE.MeshPhongMaterial( { color: 0xff2200 } );
|
||||
* const mesh = new THREE.Mesh( sphere, material );
|
||||
* scene.add( mesh );
|
||||
*
|
||||
* // finally add the sound to the mesh
|
||||
* mesh.add( sound );
|
||||
*
|
||||
* @augments Audio
|
||||
*/
|
||||
class PositionalAudio extends Audio {
|
||||
|
||||
/**
|
||||
* Constructs a positional audio.
|
||||
*
|
||||
* @param {AudioListener} listener - The global audio listener.
|
||||
*/
|
||||
constructor( listener ) {
|
||||
|
||||
super( listener );
|
||||
|
||||
/**
|
||||
* The panner node represents the location, direction, and behavior of an audio
|
||||
* source in 3D space.
|
||||
*
|
||||
* @type {PannerNode}
|
||||
* @readonly
|
||||
*/
|
||||
this.panner = this.context.createPanner();
|
||||
this.panner.panningModel = 'HRTF';
|
||||
this.panner.connect( this.gain );
|
||||
|
||||
}
|
||||
|
||||
connect() {
|
||||
|
||||
super.connect();
|
||||
|
||||
this.panner.connect( this.gain );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
|
||||
super.disconnect();
|
||||
|
||||
this.panner.disconnect( this.gain );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
getOutput() {
|
||||
|
||||
return this.panner;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current reference distance.
|
||||
*
|
||||
* @return {number} The reference distance.
|
||||
*/
|
||||
getRefDistance() {
|
||||
|
||||
return this.panner.refDistance;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the reference distance for reducing volume as the audio source moves
|
||||
* further from the listener – i.e. the distance at which the volume reduction
|
||||
* starts taking effect.
|
||||
*
|
||||
* @param {number} value - The reference distance to set.
|
||||
* @return {PositionalAudio} A reference to this instance.
|
||||
*/
|
||||
setRefDistance( value ) {
|
||||
|
||||
this.panner.refDistance = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current rolloff factor.
|
||||
*
|
||||
* @return {number} The rolloff factor.
|
||||
*/
|
||||
getRolloffFactor() {
|
||||
|
||||
return this.panner.rolloffFactor;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines how quickly the volume is reduced as the source moves away from the listener.
|
||||
*
|
||||
* @param {number} value - The rolloff factor.
|
||||
* @return {PositionalAudio} A reference to this instance.
|
||||
*/
|
||||
setRolloffFactor( value ) {
|
||||
|
||||
this.panner.rolloffFactor = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current distance model.
|
||||
*
|
||||
* @return {('linear'|'inverse'|'exponential')} The distance model.
|
||||
*/
|
||||
getDistanceModel() {
|
||||
|
||||
return this.panner.distanceModel;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines which algorithm to use to reduce the volume of the audio source
|
||||
* as it moves away from the listener.
|
||||
*
|
||||
* Read [the spec]{@link https://www.w3.org/TR/webaudio-1.1/#enumdef-distancemodeltype}
|
||||
* for more details.
|
||||
*
|
||||
* @param {('linear'|'inverse'|'exponential')} value - The distance model to set.
|
||||
* @return {PositionalAudio} A reference to this instance.
|
||||
*/
|
||||
setDistanceModel( value ) {
|
||||
|
||||
this.panner.distanceModel = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current max distance.
|
||||
*
|
||||
* @return {number} The max distance.
|
||||
*/
|
||||
getMaxDistance() {
|
||||
|
||||
return this.panner.maxDistance;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the maximum distance between the audio source and the listener,
|
||||
* after which the volume is not reduced any further.
|
||||
*
|
||||
* This value is used only by the `linear` distance model.
|
||||
*
|
||||
* @param {number} value - The max distance.
|
||||
* @return {PositionalAudio} A reference to this instance.
|
||||
*/
|
||||
setMaxDistance( value ) {
|
||||
|
||||
this.panner.maxDistance = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the directional cone in which the audio can be listened.
|
||||
*
|
||||
* @param {number} coneInnerAngle - An angle, in degrees, of a cone inside of which there will be no volume reduction.
|
||||
* @param {number} coneOuterAngle - An angle, in degrees, of a cone outside of which the volume will be reduced by a constant value, defined by the `coneOuterGain` parameter.
|
||||
* @param {number} coneOuterGain - The amount of volume reduction outside the cone defined by the `coneOuterAngle`. When set to `0`, no sound can be heard.
|
||||
* @return {PositionalAudio} A reference to this instance.
|
||||
*/
|
||||
setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
|
||||
|
||||
this.panner.coneInnerAngle = coneInnerAngle;
|
||||
this.panner.coneOuterAngle = coneOuterAngle;
|
||||
this.panner.coneOuterGain = coneOuterGain;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
updateMatrixWorld( force ) {
|
||||
|
||||
super.updateMatrixWorld( force );
|
||||
|
||||
if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
|
||||
|
||||
this.matrixWorld.decompose( _position, _quaternion, _scale );
|
||||
|
||||
_orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
|
||||
|
||||
const panner = this.panner;
|
||||
|
||||
if ( panner.positionX ) {
|
||||
|
||||
// code path for Chrome and Firefox (see #14393)
|
||||
|
||||
const endTime = this.context.currentTime + this.listener.timeDelta;
|
||||
|
||||
panner.positionX.linearRampToValueAtTime( _position.x, endTime );
|
||||
panner.positionY.linearRampToValueAtTime( _position.y, endTime );
|
||||
panner.positionZ.linearRampToValueAtTime( _position.z, endTime );
|
||||
panner.orientationX.linearRampToValueAtTime( _orientation.x, endTime );
|
||||
panner.orientationY.linearRampToValueAtTime( _orientation.y, endTime );
|
||||
panner.orientationZ.linearRampToValueAtTime( _orientation.z, endTime );
|
||||
|
||||
} else {
|
||||
|
||||
panner.setPosition( _position.x, _position.y, _position.z );
|
||||
panner.setOrientation( _orientation.x, _orientation.y, _orientation.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { PositionalAudio };
|
||||
54
app/node_modules/three/src/cameras/ArrayCamera.js
generated
vendored
Normal file
54
app/node_modules/three/src/cameras/ArrayCamera.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import { PerspectiveCamera } from './PerspectiveCamera.js';
|
||||
|
||||
/**
|
||||
* This type of camera can be used in order to efficiently render a scene with a
|
||||
* predefined set of cameras. This is an important performance aspect for
|
||||
* rendering VR scenes.
|
||||
*
|
||||
* An instance of `ArrayCamera` always has an array of sub cameras. It's mandatory
|
||||
* to define for each sub camera the `viewport` property which determines the
|
||||
* part of the viewport that is rendered with this camera.
|
||||
*
|
||||
* @augments PerspectiveCamera
|
||||
*/
|
||||
class ArrayCamera extends PerspectiveCamera {
|
||||
|
||||
/**
|
||||
* Constructs a new array camera.
|
||||
*
|
||||
* @param {Array<PerspectiveCamera>} [array=[]] - An array of perspective sub cameras.
|
||||
*/
|
||||
constructor( array = [] ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isArrayCamera = true;
|
||||
|
||||
/**
|
||||
* Whether this camera is used with multiview rendering or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default false
|
||||
*/
|
||||
this.isMultiViewCamera = false;
|
||||
|
||||
/**
|
||||
* An array of perspective sub cameras.
|
||||
*
|
||||
* @type {Array<PerspectiveCamera>}
|
||||
*/
|
||||
this.cameras = array;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { ArrayCamera };
|
||||
116
app/node_modules/three/src/cameras/Camera.js
generated
vendored
Normal file
116
app/node_modules/three/src/cameras/Camera.js
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
import { WebGLCoordinateSystem } from '../constants.js';
|
||||
import { Matrix4 } from '../math/Matrix4.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
|
||||
/**
|
||||
* Abstract base class for cameras. This class should always be inherited
|
||||
* when you build a new camera.
|
||||
*
|
||||
* @abstract
|
||||
* @augments Object3D
|
||||
*/
|
||||
class Camera extends Object3D {
|
||||
|
||||
/**
|
||||
* Constructs a new camera.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isCamera = true;
|
||||
|
||||
this.type = 'Camera';
|
||||
|
||||
/**
|
||||
* The inverse of the camera's world matrix.
|
||||
*
|
||||
* @type {Matrix4}
|
||||
*/
|
||||
this.matrixWorldInverse = new Matrix4();
|
||||
|
||||
/**
|
||||
* The camera's projection matrix.
|
||||
*
|
||||
* @type {Matrix4}
|
||||
*/
|
||||
this.projectionMatrix = new Matrix4();
|
||||
|
||||
/**
|
||||
* The inverse of the camera's projection matrix.
|
||||
*
|
||||
* @type {Matrix4}
|
||||
*/
|
||||
this.projectionMatrixInverse = new Matrix4();
|
||||
|
||||
/**
|
||||
* The coordinate system in which the camera is used.
|
||||
*
|
||||
* @type {(WebGLCoordinateSystem|WebGPUCoordinateSystem)}
|
||||
*/
|
||||
this.coordinateSystem = WebGLCoordinateSystem;
|
||||
|
||||
}
|
||||
|
||||
copy( source, recursive ) {
|
||||
|
||||
super.copy( source, recursive );
|
||||
|
||||
this.matrixWorldInverse.copy( source.matrixWorldInverse );
|
||||
|
||||
this.projectionMatrix.copy( source.projectionMatrix );
|
||||
this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
|
||||
|
||||
this.coordinateSystem = source.coordinateSystem;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a vector representing the ("look") direction of the 3D object in world space.
|
||||
*
|
||||
* This method is overwritten since cameras have a different forward vector compared to other
|
||||
* 3D objects. A camera looks down its local, negative z-axis by default.
|
||||
*
|
||||
* @param {Vector3} target - The target vector the result is stored to.
|
||||
* @return {Vector3} The 3D object's direction in world space.
|
||||
*/
|
||||
getWorldDirection( target ) {
|
||||
|
||||
return super.getWorldDirection( target ).negate();
|
||||
|
||||
}
|
||||
|
||||
updateMatrixWorld( force ) {
|
||||
|
||||
super.updateMatrixWorld( force );
|
||||
|
||||
this.matrixWorldInverse.copy( this.matrixWorld ).invert();
|
||||
|
||||
}
|
||||
|
||||
updateWorldMatrix( updateParents, updateChildren ) {
|
||||
|
||||
super.updateWorldMatrix( updateParents, updateChildren );
|
||||
|
||||
this.matrixWorldInverse.copy( this.matrixWorld ).invert();
|
||||
|
||||
}
|
||||
|
||||
clone() {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Camera };
|
||||
239
app/node_modules/three/src/cameras/CubeCamera.js
generated
vendored
Normal file
239
app/node_modules/three/src/cameras/CubeCamera.js
generated
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
import { WebGLCoordinateSystem, WebGPUCoordinateSystem } from '../constants.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { PerspectiveCamera } from './PerspectiveCamera.js';
|
||||
|
||||
const fov = - 90; // negative fov is not an error
|
||||
const aspect = 1;
|
||||
|
||||
/**
|
||||
* A special type of camera that is positioned in 3D space to render its surroundings into a
|
||||
* cube render target. The render target can then be used as an environment map for rendering
|
||||
* realtime reflections in your scene.
|
||||
*
|
||||
* ```js
|
||||
* // Create cube render target
|
||||
* const cubeRenderTarget = new THREE.WebGLCubeRenderTarget( 256, { generateMipmaps: true, minFilter: THREE.LinearMipmapLinearFilter } );
|
||||
*
|
||||
* // Create cube camera
|
||||
* const cubeCamera = new THREE.CubeCamera( 1, 100000, cubeRenderTarget );
|
||||
* scene.add( cubeCamera );
|
||||
*
|
||||
* // Create car
|
||||
* const chromeMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: cubeRenderTarget.texture } );
|
||||
* const car = new THREE.Mesh( carGeometry, chromeMaterial );
|
||||
* scene.add( car );
|
||||
*
|
||||
* // Update the render target cube
|
||||
* car.visible = false;
|
||||
* cubeCamera.position.copy( car.position );
|
||||
* cubeCamera.update( renderer, scene );
|
||||
*
|
||||
* // Render the scene
|
||||
* car.visible = true;
|
||||
* renderer.render( scene, camera );
|
||||
* ```
|
||||
*
|
||||
* @augments Object3D
|
||||
*/
|
||||
class CubeCamera extends Object3D {
|
||||
|
||||
/**
|
||||
* Constructs a new cube camera.
|
||||
*
|
||||
* @param {number} near - The camera's near plane.
|
||||
* @param {number} far - The camera's far plane.
|
||||
* @param {WebGLCubeRenderTarget} renderTarget - The cube render target.
|
||||
*/
|
||||
constructor( near, far, renderTarget ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'CubeCamera';
|
||||
|
||||
/**
|
||||
* A reference to the cube render target.
|
||||
*
|
||||
* @type {WebGLCubeRenderTarget}
|
||||
*/
|
||||
this.renderTarget = renderTarget;
|
||||
|
||||
/**
|
||||
* The current active coordinate system.
|
||||
*
|
||||
* @type {?(WebGLCoordinateSystem|WebGPUCoordinateSystem)}
|
||||
* @default null
|
||||
*/
|
||||
this.coordinateSystem = null;
|
||||
|
||||
/**
|
||||
* The current active mipmap level
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.activeMipmapLevel = 0;
|
||||
|
||||
const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraPX.layers = this.layers;
|
||||
this.add( cameraPX );
|
||||
|
||||
const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraNX.layers = this.layers;
|
||||
this.add( cameraNX );
|
||||
|
||||
const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraPY.layers = this.layers;
|
||||
this.add( cameraPY );
|
||||
|
||||
const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraNY.layers = this.layers;
|
||||
this.add( cameraNY );
|
||||
|
||||
const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraPZ.layers = this.layers;
|
||||
this.add( cameraPZ );
|
||||
|
||||
const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraNZ.layers = this.layers;
|
||||
this.add( cameraNZ );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called when the coordinate system of the cube camera is changed.
|
||||
*/
|
||||
updateCoordinateSystem() {
|
||||
|
||||
const coordinateSystem = this.coordinateSystem;
|
||||
|
||||
const cameras = this.children.concat();
|
||||
|
||||
const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = cameras;
|
||||
|
||||
for ( const camera of cameras ) this.remove( camera );
|
||||
|
||||
if ( coordinateSystem === WebGLCoordinateSystem ) {
|
||||
|
||||
cameraPX.up.set( 0, 1, 0 );
|
||||
cameraPX.lookAt( 1, 0, 0 );
|
||||
|
||||
cameraNX.up.set( 0, 1, 0 );
|
||||
cameraNX.lookAt( - 1, 0, 0 );
|
||||
|
||||
cameraPY.up.set( 0, 0, - 1 );
|
||||
cameraPY.lookAt( 0, 1, 0 );
|
||||
|
||||
cameraNY.up.set( 0, 0, 1 );
|
||||
cameraNY.lookAt( 0, - 1, 0 );
|
||||
|
||||
cameraPZ.up.set( 0, 1, 0 );
|
||||
cameraPZ.lookAt( 0, 0, 1 );
|
||||
|
||||
cameraNZ.up.set( 0, 1, 0 );
|
||||
cameraNZ.lookAt( 0, 0, - 1 );
|
||||
|
||||
} else if ( coordinateSystem === WebGPUCoordinateSystem ) {
|
||||
|
||||
cameraPX.up.set( 0, - 1, 0 );
|
||||
cameraPX.lookAt( - 1, 0, 0 );
|
||||
|
||||
cameraNX.up.set( 0, - 1, 0 );
|
||||
cameraNX.lookAt( 1, 0, 0 );
|
||||
|
||||
cameraPY.up.set( 0, 0, 1 );
|
||||
cameraPY.lookAt( 0, 1, 0 );
|
||||
|
||||
cameraNY.up.set( 0, 0, - 1 );
|
||||
cameraNY.lookAt( 0, - 1, 0 );
|
||||
|
||||
cameraPZ.up.set( 0, - 1, 0 );
|
||||
cameraPZ.lookAt( 0, 0, 1 );
|
||||
|
||||
cameraNZ.up.set( 0, - 1, 0 );
|
||||
cameraNZ.lookAt( 0, 0, - 1 );
|
||||
|
||||
} else {
|
||||
|
||||
throw new Error( 'THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: ' + coordinateSystem );
|
||||
|
||||
}
|
||||
|
||||
for ( const camera of cameras ) {
|
||||
|
||||
this.add( camera );
|
||||
|
||||
camera.updateMatrixWorld();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calling this method will render the given scene with the given renderer
|
||||
* into the cube render target of the camera.
|
||||
*
|
||||
* @param {(Renderer|WebGLRenderer)} renderer - The renderer.
|
||||
* @param {Scene} scene - The scene to render.
|
||||
*/
|
||||
update( renderer, scene ) {
|
||||
|
||||
if ( this.parent === null ) this.updateMatrixWorld();
|
||||
|
||||
const { renderTarget, activeMipmapLevel } = this;
|
||||
|
||||
if ( this.coordinateSystem !== renderer.coordinateSystem ) {
|
||||
|
||||
this.coordinateSystem = renderer.coordinateSystem;
|
||||
|
||||
this.updateCoordinateSystem();
|
||||
|
||||
}
|
||||
|
||||
const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;
|
||||
|
||||
const currentRenderTarget = renderer.getRenderTarget();
|
||||
const currentActiveCubeFace = renderer.getActiveCubeFace();
|
||||
const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
||||
|
||||
const currentXrEnabled = renderer.xr.enabled;
|
||||
|
||||
renderer.xr.enabled = false;
|
||||
|
||||
const generateMipmaps = renderTarget.texture.generateMipmaps;
|
||||
|
||||
renderTarget.texture.generateMipmaps = false;
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 0, activeMipmapLevel );
|
||||
renderer.render( scene, cameraPX );
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 1, activeMipmapLevel );
|
||||
renderer.render( scene, cameraNX );
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 2, activeMipmapLevel );
|
||||
renderer.render( scene, cameraPY );
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 3, activeMipmapLevel );
|
||||
renderer.render( scene, cameraNY );
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 4, activeMipmapLevel );
|
||||
renderer.render( scene, cameraPZ );
|
||||
|
||||
// mipmaps are generated during the last call of render()
|
||||
// at this point, all sides of the cube render target are defined
|
||||
|
||||
renderTarget.texture.generateMipmaps = generateMipmaps;
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 5, activeMipmapLevel );
|
||||
renderer.render( scene, cameraNZ );
|
||||
|
||||
renderer.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );
|
||||
|
||||
renderer.xr.enabled = currentXrEnabled;
|
||||
|
||||
renderTarget.texture.needsPMREMUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { CubeCamera };
|
||||
245
app/node_modules/three/src/cameras/OrthographicCamera.js
generated
vendored
Executable file
245
app/node_modules/three/src/cameras/OrthographicCamera.js
generated
vendored
Executable file
@@ -0,0 +1,245 @@
|
||||
import { Camera } from './Camera.js';
|
||||
|
||||
/**
|
||||
* Camera that uses [orthographic projection]{@link https://en.wikipedia.org/wiki/Orthographic_projection}.
|
||||
*
|
||||
* In this projection mode, an object's size in the rendered image stays
|
||||
* constant regardless of its distance from the camera. This can be useful
|
||||
* for rendering 2D scenes and UI elements, amongst other things.
|
||||
*
|
||||
* ```js
|
||||
* const camera = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, 1, 1000 );
|
||||
* scene.add( camera );
|
||||
* ```
|
||||
*
|
||||
* @augments Camera
|
||||
*/
|
||||
class OrthographicCamera extends Camera {
|
||||
|
||||
/**
|
||||
* Constructs a new orthographic camera.
|
||||
*
|
||||
* @param {number} [left=-1] - The left plane of the camera's frustum.
|
||||
* @param {number} [right=1] - The right plane of the camera's frustum.
|
||||
* @param {number} [top=1] - The top plane of the camera's frustum.
|
||||
* @param {number} [bottom=-1] - The bottom plane of the camera's frustum.
|
||||
* @param {number} [near=0.1] - The camera's near plane.
|
||||
* @param {number} [far=2000] - The camera's far plane.
|
||||
*/
|
||||
constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isOrthographicCamera = true;
|
||||
|
||||
this.type = 'OrthographicCamera';
|
||||
|
||||
/**
|
||||
* The zoom factor of the camera.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.zoom = 1;
|
||||
|
||||
/**
|
||||
* Represents the frustum window specification. This property should not be edited
|
||||
* directly but via {@link PerspectiveCamera#setViewOffset} and {@link PerspectiveCamera#clearViewOffset}.
|
||||
*
|
||||
* @type {?Object}
|
||||
* @default null
|
||||
*/
|
||||
this.view = null;
|
||||
|
||||
/**
|
||||
* The left plane of the camera's frustum.
|
||||
*
|
||||
* @type {number}
|
||||
* @default -1
|
||||
*/
|
||||
this.left = left;
|
||||
|
||||
/**
|
||||
* The right plane of the camera's frustum.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.right = right;
|
||||
|
||||
/**
|
||||
* The top plane of the camera's frustum.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.top = top;
|
||||
|
||||
/**
|
||||
* The bottom plane of the camera's frustum.
|
||||
*
|
||||
* @type {number}
|
||||
* @default -1
|
||||
*/
|
||||
this.bottom = bottom;
|
||||
|
||||
/**
|
||||
* The camera's near plane. The valid range is greater than `0`
|
||||
* and less than the current value of {@link OrthographicCamera#far}.
|
||||
*
|
||||
* Note that, unlike for the {@link PerspectiveCamera}, `0` is a
|
||||
* valid value for an orthographic camera's near plane.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0.1
|
||||
*/
|
||||
this.near = near;
|
||||
|
||||
/**
|
||||
* The camera's far plane. Must be greater than the
|
||||
* current value of {@link OrthographicCamera#near}.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 2000
|
||||
*/
|
||||
this.far = far;
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
copy( source, recursive ) {
|
||||
|
||||
super.copy( source, recursive );
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an offset in a larger frustum. This is useful for multi-window or
|
||||
* multi-monitor/multi-machine setups.
|
||||
*
|
||||
* @param {number} fullWidth - The full width of multiview setup.
|
||||
* @param {number} fullHeight - The full height of multiview setup.
|
||||
* @param {number} x - The horizontal offset of the subcamera.
|
||||
* @param {number} y - The vertical offset of the subcamera.
|
||||
* @param {number} width - The width of subcamera.
|
||||
* @param {number} height - The height of subcamera.
|
||||
* @see {@link PerspectiveCamera#setViewOffset}
|
||||
*/
|
||||
setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
|
||||
|
||||
if ( this.view === null ) {
|
||||
|
||||
this.view = {
|
||||
enabled: true,
|
||||
fullWidth: 1,
|
||||
fullHeight: 1,
|
||||
offsetX: 0,
|
||||
offsetY: 0,
|
||||
width: 1,
|
||||
height: 1
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
this.view.enabled = true;
|
||||
this.view.fullWidth = fullWidth;
|
||||
this.view.fullHeight = fullHeight;
|
||||
this.view.offsetX = x;
|
||||
this.view.offsetY = y;
|
||||
this.view.width = width;
|
||||
this.view.height = height;
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the view offset from the projection matrix.
|
||||
*/
|
||||
clearViewOffset() {
|
||||
|
||||
if ( this.view !== null ) {
|
||||
|
||||
this.view.enabled = false;
|
||||
|
||||
}
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the camera's projection matrix. Must be called after any change of
|
||||
* camera properties.
|
||||
*/
|
||||
updateProjectionMatrix() {
|
||||
|
||||
const dx = ( this.right - this.left ) / ( 2 * this.zoom );
|
||||
const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
|
||||
const cx = ( this.right + this.left ) / 2;
|
||||
const cy = ( this.top + this.bottom ) / 2;
|
||||
|
||||
let left = cx - dx;
|
||||
let right = cx + dx;
|
||||
let top = cy + dy;
|
||||
let bottom = cy - dy;
|
||||
|
||||
if ( this.view !== null && this.view.enabled ) {
|
||||
|
||||
const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
|
||||
const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
|
||||
|
||||
left += scaleW * this.view.offsetX;
|
||||
right = left + scaleW * this.view.width;
|
||||
top -= scaleH * this.view.offsetY;
|
||||
bottom = top - scaleH * this.view.height;
|
||||
|
||||
}
|
||||
|
||||
this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far, this.coordinateSystem );
|
||||
|
||||
this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
|
||||
|
||||
}
|
||||
|
||||
toJSON( meta ) {
|
||||
|
||||
const data = super.toJSON( 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 };
|
||||
407
app/node_modules/three/src/cameras/PerspectiveCamera.js
generated
vendored
Normal file
407
app/node_modules/three/src/cameras/PerspectiveCamera.js
generated
vendored
Normal file
@@ -0,0 +1,407 @@
|
||||
import { Camera } from './Camera.js';
|
||||
import { RAD2DEG, DEG2RAD } from '../math/MathUtils.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
const _v3 = /*@__PURE__*/ new Vector3();
|
||||
const _minTarget = /*@__PURE__*/ new Vector2();
|
||||
const _maxTarget = /*@__PURE__*/ new Vector2();
|
||||
|
||||
/**
|
||||
* Camera that uses [perspective projection]{@link https://en.wikipedia.org/wiki/Perspective_(graphical)}.
|
||||
*
|
||||
* This projection mode is designed to mimic the way the human eye sees. It
|
||||
* is the most common projection mode used for rendering a 3D scene.
|
||||
*
|
||||
* ```js
|
||||
* const camera = new THREE.PerspectiveCamera( 45, width / height, 1, 1000 );
|
||||
* scene.add( camera );
|
||||
* ```
|
||||
*
|
||||
* @augments Camera
|
||||
*/
|
||||
class PerspectiveCamera extends Camera {
|
||||
|
||||
/**
|
||||
* Constructs a new perspective camera.
|
||||
*
|
||||
* @param {number} [fov=50] - The vertical field of view.
|
||||
* @param {number} [aspect=1] - The aspect ratio.
|
||||
* @param {number} [near=0.1] - The camera's near plane.
|
||||
* @param {number} [far=2000] - The camera's far plane.
|
||||
*/
|
||||
constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isPerspectiveCamera = true;
|
||||
|
||||
this.type = 'PerspectiveCamera';
|
||||
|
||||
/**
|
||||
* The vertical field of view, from bottom to top of view,
|
||||
* in degrees.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 50
|
||||
*/
|
||||
this.fov = fov;
|
||||
|
||||
/**
|
||||
* The zoom factor of the camera.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.zoom = 1;
|
||||
|
||||
/**
|
||||
* The camera's near plane. The valid range is greater than `0`
|
||||
* and less than the current value of {@link PerspectiveCamera#far}.
|
||||
*
|
||||
* Note that, unlike for the {@link OrthographicCamera}, `0` is <em>not</em> a
|
||||
* valid value for a perspective camera's near plane.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0.1
|
||||
*/
|
||||
this.near = near;
|
||||
|
||||
/**
|
||||
* The camera's far plane. Must be greater than the
|
||||
* current value of {@link PerspectiveCamera#near}.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 2000
|
||||
*/
|
||||
this.far = far;
|
||||
|
||||
/**
|
||||
* Object distance used for stereoscopy and depth-of-field effects. This
|
||||
* parameter does not influence the projection matrix unless a
|
||||
* {@link StereoCamera} is being used.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 10
|
||||
*/
|
||||
this.focus = 10;
|
||||
|
||||
/**
|
||||
* The aspect ratio, usually the canvas width / canvas height.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.aspect = aspect;
|
||||
|
||||
/**
|
||||
* Represents the frustum window specification. This property should not be edited
|
||||
* directly but via {@link PerspectiveCamera#setViewOffset} and {@link PerspectiveCamera#clearViewOffset}.
|
||||
*
|
||||
* @type {?Object}
|
||||
* @default null
|
||||
*/
|
||||
this.view = null;
|
||||
|
||||
/**
|
||||
* Film size used for the larger axis. Default is `35` (millimeters). This
|
||||
* parameter does not influence the projection matrix unless {@link PerspectiveCamera#filmOffset}
|
||||
* is set to a nonzero value.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 35
|
||||
*/
|
||||
this.filmGauge = 35;
|
||||
|
||||
/**
|
||||
* Horizontal off-center offset in the same unit as {@link PerspectiveCamera#filmGauge}.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.filmOffset = 0;
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
copy( source, recursive ) {
|
||||
|
||||
super.copy( source, recursive );
|
||||
|
||||
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 {@link PerspectiveCamera#filmGauge}.
|
||||
*
|
||||
* The default film gauge is 35, so that the focal length can be specified for
|
||||
* a 35mm (full frame) camera.
|
||||
*
|
||||
* @param {number} focalLength - Values for focal length and film gauge must have the same unit.
|
||||
*/
|
||||
setFocalLength( focalLength ) {
|
||||
|
||||
/** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
|
||||
const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
|
||||
|
||||
this.fov = RAD2DEG * 2 * Math.atan( vExtentSlope );
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the focal length from the current {@link PerspectiveCamera#fov} and
|
||||
* {@link PerspectiveCamera#filmGauge}.
|
||||
*
|
||||
* @return {number} The computed focal length.
|
||||
*/
|
||||
getFocalLength() {
|
||||
|
||||
const vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov );
|
||||
|
||||
return 0.5 * this.getFilmHeight() / vExtentSlope;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current vertical field of view angle in degrees considering {@link PerspectiveCamera#zoom}.
|
||||
*
|
||||
* @return {number} The effective FOV.
|
||||
*/
|
||||
getEffectiveFOV() {
|
||||
|
||||
return RAD2DEG * 2 * Math.atan(
|
||||
Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the image on the film. If {@link PerspectiveCamera#aspect} is greater than or
|
||||
* equal to one (landscape format), the result equals {@link PerspectiveCamera#filmGauge}.
|
||||
*
|
||||
* @return {number} The film width.
|
||||
*/
|
||||
getFilmWidth() {
|
||||
|
||||
// film not completely covered in portrait format (aspect < 1)
|
||||
return this.filmGauge * Math.min( this.aspect, 1 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of the image on the film. If {@link PerspectiveCamera#aspect} is greater than or
|
||||
* equal to one (landscape format), the result equals {@link PerspectiveCamera#filmGauge}.
|
||||
*
|
||||
* @return {number} The film width.
|
||||
*/
|
||||
getFilmHeight() {
|
||||
|
||||
// film not completely covered in landscape format (aspect > 1)
|
||||
return this.filmGauge / Math.max( this.aspect, 1 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
|
||||
* Sets `minTarget` and `maxTarget` to the coordinates of the lower-left and upper-right corners of the view rectangle.
|
||||
*
|
||||
* @param {number} distance - The viewing distance.
|
||||
* @param {Vector2} minTarget - The lower-left corner of the view rectangle is written into this vector.
|
||||
* @param {Vector2} maxTarget - The upper-right corner of the view rectangle is written into this vector.
|
||||
*/
|
||||
getViewBounds( distance, minTarget, maxTarget ) {
|
||||
|
||||
_v3.set( - 1, - 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
|
||||
|
||||
minTarget.set( _v3.x, _v3.y ).multiplyScalar( - distance / _v3.z );
|
||||
|
||||
_v3.set( 1, 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
|
||||
|
||||
maxTarget.set( _v3.x, _v3.y ).multiplyScalar( - distance / _v3.z );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
|
||||
*
|
||||
* @param {number} distance - The viewing distance.
|
||||
* @param {Vector2} target - The target vector that is used to store result where x is width and y is height.
|
||||
* @returns {Vector2} The view size.
|
||||
*/
|
||||
getViewSize( distance, target ) {
|
||||
|
||||
this.getViewBounds( distance, _minTarget, _maxTarget );
|
||||
|
||||
return target.subVectors( _maxTarget, _minTarget );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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:
|
||||
*```js
|
||||
* const w = 1920;
|
||||
* const h = 1080;
|
||||
* const fullWidth = w * 3;
|
||||
* const fullHeight = h * 2;
|
||||
*
|
||||
* // --A--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
|
||||
* // --B--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
|
||||
* // --C--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
|
||||
* // --D--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
|
||||
* // --E--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
|
||||
* // --F--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
|
||||
* ```
|
||||
*
|
||||
* Note there is no reason monitors have to be the same size or in a grid.
|
||||
*
|
||||
* @param {number} fullWidth - The full width of multiview setup.
|
||||
* @param {number} fullHeight - The full height of multiview setup.
|
||||
* @param {number} x - The horizontal offset of the subcamera.
|
||||
* @param {number} y - The vertical offset of the subcamera.
|
||||
* @param {number} width - The width of subcamera.
|
||||
* @param {number} height - The height of subcamera.
|
||||
*/
|
||||
setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
|
||||
|
||||
this.aspect = fullWidth / fullHeight;
|
||||
|
||||
if ( this.view === null ) {
|
||||
|
||||
this.view = {
|
||||
enabled: true,
|
||||
fullWidth: 1,
|
||||
fullHeight: 1,
|
||||
offsetX: 0,
|
||||
offsetY: 0,
|
||||
width: 1,
|
||||
height: 1
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
this.view.enabled = true;
|
||||
this.view.fullWidth = fullWidth;
|
||||
this.view.fullHeight = fullHeight;
|
||||
this.view.offsetX = x;
|
||||
this.view.offsetY = y;
|
||||
this.view.width = width;
|
||||
this.view.height = height;
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the view offset from the projection matrix.
|
||||
*/
|
||||
clearViewOffset() {
|
||||
|
||||
if ( this.view !== null ) {
|
||||
|
||||
this.view.enabled = false;
|
||||
|
||||
}
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the camera's projection matrix. Must be called after any change of
|
||||
* camera properties.
|
||||
*/
|
||||
updateProjectionMatrix() {
|
||||
|
||||
const near = this.near;
|
||||
let top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom;
|
||||
let height = 2 * top;
|
||||
let width = this.aspect * height;
|
||||
let left = - 0.5 * width;
|
||||
const view = this.view;
|
||||
|
||||
if ( this.view !== null && this.view.enabled ) {
|
||||
|
||||
const fullWidth = view.fullWidth,
|
||||
fullHeight = view.fullHeight;
|
||||
|
||||
left += view.offsetX * width / fullWidth;
|
||||
top -= view.offsetY * height / fullHeight;
|
||||
width *= view.width / fullWidth;
|
||||
height *= view.height / fullHeight;
|
||||
|
||||
}
|
||||
|
||||
const skew = this.filmOffset;
|
||||
if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
|
||||
|
||||
this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far, this.coordinateSystem );
|
||||
|
||||
this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
|
||||
|
||||
}
|
||||
|
||||
toJSON( meta ) {
|
||||
|
||||
const data = super.toJSON( 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 };
|
||||
146
app/node_modules/three/src/cameras/StereoCamera.js
generated
vendored
Normal file
146
app/node_modules/three/src/cameras/StereoCamera.js
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
import { Matrix4 } from '../math/Matrix4.js';
|
||||
import { DEG2RAD } from '../math/MathUtils.js';
|
||||
import { PerspectiveCamera } from './PerspectiveCamera.js';
|
||||
|
||||
const _eyeRight = /*@__PURE__*/ new Matrix4();
|
||||
const _eyeLeft = /*@__PURE__*/ new Matrix4();
|
||||
const _projectionMatrix = /*@__PURE__*/ new Matrix4();
|
||||
|
||||
/**
|
||||
* A special type of camera that uses two perspective cameras with
|
||||
* stereoscopic projection. Can be used for rendering stereo effects
|
||||
* like [3D Anaglyph]{@link https://en.wikipedia.org/wiki/Anaglyph_3D} or
|
||||
* [Parallax Barrier]{@link https://en.wikipedia.org/wiki/parallax_barrier}.
|
||||
*/
|
||||
class StereoCamera {
|
||||
|
||||
/**
|
||||
* Constructs a new stereo camera.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
/**
|
||||
* The type property is used for detecting the object type
|
||||
* in context of serialization/deserialization.
|
||||
*
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.type = 'StereoCamera';
|
||||
|
||||
/**
|
||||
* The aspect.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.aspect = 1;
|
||||
|
||||
/**
|
||||
* The eye separation which represents the distance
|
||||
* between the left and right camera.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0.064
|
||||
*/
|
||||
this.eyeSep = 0.064;
|
||||
|
||||
/**
|
||||
* The camera representing the left eye. This is added to layer `1` so objects to be
|
||||
* rendered by the left camera must also be added to this layer.
|
||||
*
|
||||
* @type {PerspectiveCamera}
|
||||
*/
|
||||
this.cameraL = new PerspectiveCamera();
|
||||
this.cameraL.layers.enable( 1 );
|
||||
this.cameraL.matrixAutoUpdate = false;
|
||||
|
||||
/**
|
||||
* The camera representing the right eye. This is added to layer `2` so objects to be
|
||||
* rendered by the right camera must also be added to this layer.
|
||||
*
|
||||
* @type {PerspectiveCamera}
|
||||
*/
|
||||
this.cameraR = new PerspectiveCamera();
|
||||
this.cameraR.layers.enable( 2 );
|
||||
this.cameraR.matrixAutoUpdate = false;
|
||||
|
||||
this._cache = {
|
||||
focus: null,
|
||||
fov: null,
|
||||
aspect: null,
|
||||
near: null,
|
||||
far: null,
|
||||
zoom: null,
|
||||
eyeSep: null
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the stereo camera based on the given perspective camera.
|
||||
*
|
||||
* @param {PerspectiveCamera} camera - The perspective camera.
|
||||
*/
|
||||
update( camera ) {
|
||||
|
||||
const cache = this._cache;
|
||||
|
||||
const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
|
||||
cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
|
||||
cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
|
||||
|
||||
if ( needsUpdate ) {
|
||||
|
||||
cache.focus = camera.focus;
|
||||
cache.fov = camera.fov;
|
||||
cache.aspect = camera.aspect * this.aspect;
|
||||
cache.near = camera.near;
|
||||
cache.far = camera.far;
|
||||
cache.zoom = camera.zoom;
|
||||
cache.eyeSep = this.eyeSep;
|
||||
|
||||
// Off-axis stereoscopic effect based on
|
||||
// http://paulbourke.net/stereographics/stereorender/
|
||||
|
||||
_projectionMatrix.copy( camera.projectionMatrix );
|
||||
const eyeSepHalf = cache.eyeSep / 2;
|
||||
const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
|
||||
const ymax = ( cache.near * Math.tan( DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
|
||||
let xmin, xmax;
|
||||
|
||||
// translate xOffset
|
||||
|
||||
_eyeLeft.elements[ 12 ] = - eyeSepHalf;
|
||||
_eyeRight.elements[ 12 ] = eyeSepHalf;
|
||||
|
||||
// for left eye
|
||||
|
||||
xmin = - ymax * cache.aspect + eyeSepOnProjection;
|
||||
xmax = ymax * cache.aspect + eyeSepOnProjection;
|
||||
|
||||
_projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
|
||||
_projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
|
||||
|
||||
this.cameraL.projectionMatrix.copy( _projectionMatrix );
|
||||
|
||||
// for right eye
|
||||
|
||||
xmin = - ymax * cache.aspect - eyeSepOnProjection;
|
||||
xmax = ymax * cache.aspect - eyeSepOnProjection;
|
||||
|
||||
_projectionMatrix.elements[ 0 ] = 2 * cache.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 };
|
||||
1667
app/node_modules/three/src/constants.js
generated
vendored
Normal file
1667
app/node_modules/three/src/constants.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1044
app/node_modules/three/src/core/BufferAttribute.js
generated
vendored
Normal file
1044
app/node_modules/three/src/core/BufferAttribute.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1446
app/node_modules/three/src/core/BufferGeometry.js
generated
vendored
Normal file
1446
app/node_modules/three/src/core/BufferGeometry.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
128
app/node_modules/three/src/core/Clock.js
generated
vendored
Normal file
128
app/node_modules/three/src/core/Clock.js
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* Class for keeping track of time.
|
||||
*/
|
||||
class Clock {
|
||||
|
||||
/**
|
||||
* Constructs a new clock.
|
||||
*
|
||||
* @param {boolean} [autoStart=true] - Whether to automatically start the clock when
|
||||
* `getDelta()` is called for the first time.
|
||||
*/
|
||||
constructor( autoStart = true ) {
|
||||
|
||||
/**
|
||||
* If set to `true`, the clock starts automatically when `getDelta()` is called
|
||||
* for the first time.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.autoStart = autoStart;
|
||||
|
||||
/**
|
||||
* Holds the time at which the clock's `start()` method was last called.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.startTime = 0;
|
||||
|
||||
/**
|
||||
* Holds the time at which the clock's `start()`, `getElapsedTime()` or
|
||||
* `getDelta()` methods were last called.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.oldTime = 0;
|
||||
|
||||
/**
|
||||
* Keeps track of the total time that the clock has been running.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.elapsedTime = 0;
|
||||
|
||||
/**
|
||||
* Whether the clock is running or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.running = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the clock. When `autoStart` is set to `true`, the method is automatically
|
||||
* called by the class.
|
||||
*/
|
||||
start() {
|
||||
|
||||
this.startTime = performance.now();
|
||||
|
||||
this.oldTime = this.startTime;
|
||||
this.elapsedTime = 0;
|
||||
this.running = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the clock.
|
||||
*/
|
||||
stop() {
|
||||
|
||||
this.getElapsedTime();
|
||||
this.running = false;
|
||||
this.autoStart = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the elapsed time in seconds.
|
||||
*
|
||||
* @return {number} The elapsed time.
|
||||
*/
|
||||
getElapsedTime() {
|
||||
|
||||
this.getDelta();
|
||||
return this.elapsedTime;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the delta time in seconds.
|
||||
*
|
||||
* @return {number} The delta time.
|
||||
*/
|
||||
getDelta() {
|
||||
|
||||
let diff = 0;
|
||||
|
||||
if ( this.autoStart && ! this.running ) {
|
||||
|
||||
this.start();
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
if ( this.running ) {
|
||||
|
||||
const newTime = performance.now();
|
||||
|
||||
diff = ( newTime - this.oldTime ) / 1000;
|
||||
this.oldTime = newTime;
|
||||
|
||||
this.elapsedTime += diff;
|
||||
|
||||
}
|
||||
|
||||
return diff;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Clock };
|
||||
131
app/node_modules/three/src/core/EventDispatcher.js
generated
vendored
Normal file
131
app/node_modules/three/src/core/EventDispatcher.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* This modules allows to dispatch event objects on custom JavaScript objects.
|
||||
*
|
||||
* Main repository: [eventdispatcher.js]{@link https://github.com/mrdoob/eventdispatcher.js/}
|
||||
*
|
||||
* Code Example:
|
||||
* ```js
|
||||
* class Car extends EventDispatcher {
|
||||
* start() {
|
||||
* this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
|
||||
* }
|
||||
*};
|
||||
*
|
||||
* // Using events with the custom object
|
||||
* const car = new Car();
|
||||
* car.addEventListener( 'start', function ( event ) {
|
||||
* alert( event.message );
|
||||
* } );
|
||||
*
|
||||
* car.start();
|
||||
* ```
|
||||
*/
|
||||
class EventDispatcher {
|
||||
|
||||
/**
|
||||
* Adds the given event listener to the given event type.
|
||||
*
|
||||
* @param {string} type - The type of event to listen to.
|
||||
* @param {Function} listener - The function that gets called when the event is fired.
|
||||
*/
|
||||
addEventListener( type, listener ) {
|
||||
|
||||
if ( this._listeners === undefined ) this._listeners = {};
|
||||
|
||||
const listeners = this._listeners;
|
||||
|
||||
if ( listeners[ type ] === undefined ) {
|
||||
|
||||
listeners[ type ] = [];
|
||||
|
||||
}
|
||||
|
||||
if ( listeners[ type ].indexOf( listener ) === - 1 ) {
|
||||
|
||||
listeners[ type ].push( listener );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the given event listener has been added to the given event type.
|
||||
*
|
||||
* @param {string} type - The type of event.
|
||||
* @param {Function} listener - The listener to check.
|
||||
* @return {boolean} Whether the given event listener has been added to the given event type.
|
||||
*/
|
||||
hasEventListener( type, listener ) {
|
||||
|
||||
const listeners = this._listeners;
|
||||
|
||||
if ( listeners === undefined ) return false;
|
||||
|
||||
return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given event listener from the given event type.
|
||||
*
|
||||
* @param {string} type - The type of event.
|
||||
* @param {Function} listener - The listener to remove.
|
||||
*/
|
||||
removeEventListener( type, listener ) {
|
||||
|
||||
const listeners = this._listeners;
|
||||
|
||||
if ( listeners === undefined ) return;
|
||||
|
||||
const listenerArray = listeners[ type ];
|
||||
|
||||
if ( listenerArray !== undefined ) {
|
||||
|
||||
const index = listenerArray.indexOf( listener );
|
||||
|
||||
if ( index !== - 1 ) {
|
||||
|
||||
listenerArray.splice( index, 1 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches an event object.
|
||||
*
|
||||
* @param {Object} event - The event that gets fired.
|
||||
*/
|
||||
dispatchEvent( event ) {
|
||||
|
||||
const listeners = this._listeners;
|
||||
|
||||
if ( listeners === undefined ) return;
|
||||
|
||||
const listenerArray = listeners[ event.type ];
|
||||
|
||||
if ( listenerArray !== undefined ) {
|
||||
|
||||
event.target = this;
|
||||
|
||||
// Make a copy, in case listeners are removed while iterating.
|
||||
const array = listenerArray.slice( 0 );
|
||||
|
||||
for ( let i = 0, l = array.length; i < l; i ++ ) {
|
||||
|
||||
array[ i ].call( this, event );
|
||||
|
||||
}
|
||||
|
||||
event.target = null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { EventDispatcher };
|
||||
171
app/node_modules/three/src/core/GLBufferAttribute.js
generated
vendored
Normal file
171
app/node_modules/three/src/core/GLBufferAttribute.js
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* An alternative version of a buffer attribute with more control over the VBO.
|
||||
*
|
||||
* The renderer does not construct a VBO for this kind of attribute. Instead, it uses
|
||||
* whatever VBO is passed in constructor and can later be altered via the `buffer` property.
|
||||
*
|
||||
* The most common use case for this class is when some kind of GPGPU calculation interferes
|
||||
* or even produces the VBOs in question.
|
||||
*
|
||||
* Notice that this class can only be used with {@link WebGLRenderer}.
|
||||
*/
|
||||
class GLBufferAttribute {
|
||||
|
||||
/**
|
||||
* Constructs a new GL buffer attribute.
|
||||
*
|
||||
* @param {WebGLBuffer} buffer - The native WebGL buffer.
|
||||
* @param {number} type - The native data type (e.g. `gl.FLOAT`).
|
||||
* @param {number} itemSize - The item size.
|
||||
* @param {number} elementSize - The corresponding size (in bytes) for the given `type` parameter.
|
||||
* @param {number} count - The expected number of vertices in VBO.
|
||||
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
|
||||
*/
|
||||
constructor( buffer, type, itemSize, elementSize, count, normalized = false ) {
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isGLBufferAttribute = true;
|
||||
|
||||
/**
|
||||
* The name of the buffer attribute.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* The native WebGL buffer.
|
||||
*
|
||||
* @type {WebGLBuffer}
|
||||
*/
|
||||
this.buffer = buffer;
|
||||
|
||||
/**
|
||||
* The native data type.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.type = type;
|
||||
|
||||
/**
|
||||
* The item size, see {@link BufferAttribute#itemSize}.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.itemSize = itemSize;
|
||||
|
||||
/**
|
||||
* The corresponding size (in bytes) for the given `type` parameter.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.elementSize = elementSize;
|
||||
|
||||
/**
|
||||
* The expected number of vertices in VBO.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.count = count;
|
||||
|
||||
/**
|
||||
* Applies to integer data only. Indicates how the underlying data in the buffer maps to
|
||||
* the values in the GLSL code. For instance, if `buffer` contains data of `gl.UNSIGNED_SHORT`,
|
||||
* and `normalized` is `true`, the values `0 - +65535` in the buffer data will be mapped to
|
||||
* `0.0f - +1.0f` in the GLSL attribute. If `normalized` is `false`, the values will be converted
|
||||
* to floats unmodified, i.e. `65535` becomes `65535.0f`.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.normalized = normalized;
|
||||
|
||||
/**
|
||||
* A version number, incremented every time the `needsUpdate` is set to `true`.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.version = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to indicate that this attribute has changed and should be re-sent to
|
||||
* the GPU. Set this to `true` when you modify the value of the array.
|
||||
*
|
||||
* @type {number}
|
||||
* @default false
|
||||
* @param {boolean} value
|
||||
*/
|
||||
set needsUpdate( value ) {
|
||||
|
||||
if ( value === true ) this.version ++;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given native WebGL buffer.
|
||||
*
|
||||
* @param {WebGLBuffer} buffer - The buffer to set.
|
||||
* @return {BufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setBuffer( buffer ) {
|
||||
|
||||
this.buffer = buffer;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given native data type and element size.
|
||||
*
|
||||
* @param {number} type - The native data type (e.g. `gl.FLOAT`).
|
||||
* @param {number} elementSize - The corresponding size (in bytes) for the given `type` parameter.
|
||||
* @return {BufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setType( type, elementSize ) {
|
||||
|
||||
this.type = type;
|
||||
this.elementSize = elementSize;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the item size.
|
||||
*
|
||||
* @param {number} itemSize - The item size.
|
||||
* @return {BufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setItemSize( itemSize ) {
|
||||
|
||||
this.itemSize = itemSize;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the count (the expected number of vertices in VBO).
|
||||
*
|
||||
* @param {number} count - The count.
|
||||
* @return {BufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setCount( count ) {
|
||||
|
||||
this.count = count;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { GLBufferAttribute };
|
||||
68
app/node_modules/three/src/core/InstancedBufferAttribute.js
generated
vendored
Normal file
68
app/node_modules/three/src/core/InstancedBufferAttribute.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import { BufferAttribute } from './BufferAttribute.js';
|
||||
|
||||
/**
|
||||
* An instanced version of a buffer attribute.
|
||||
*
|
||||
* @augments BufferAttribute
|
||||
*/
|
||||
class InstancedBufferAttribute extends BufferAttribute {
|
||||
|
||||
/**
|
||||
* Constructs a new instanced buffer attribute.
|
||||
*
|
||||
* @param {TypedArray} array - The array holding the attribute data.
|
||||
* @param {number} itemSize - The item size.
|
||||
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
|
||||
* @param {number} [meshPerAttribute=1] - How often a value of this buffer attribute should be repeated.
|
||||
*/
|
||||
constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {
|
||||
|
||||
super( array, itemSize, normalized );
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInstancedBufferAttribute = true;
|
||||
|
||||
/**
|
||||
* Defines how often a value of this buffer attribute should be repeated. A
|
||||
* value of one means that each value of the instanced attribute is used for
|
||||
* a single instance. A value of two means that each value is used for two
|
||||
* consecutive instances (and so on).
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.meshPerAttribute = meshPerAttribute;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.meshPerAttribute = source.meshPerAttribute;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.meshPerAttribute = this.meshPerAttribute;
|
||||
|
||||
data.isInstancedBufferAttribute = true;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { InstancedBufferAttribute };
|
||||
60
app/node_modules/three/src/core/InstancedBufferGeometry.js
generated
vendored
Normal file
60
app/node_modules/three/src/core/InstancedBufferGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
import { BufferGeometry } from './BufferGeometry.js';
|
||||
|
||||
/**
|
||||
* An instanced version of a geometry.
|
||||
*/
|
||||
class InstancedBufferGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new instanced buffer geometry.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInstancedBufferGeometry = true;
|
||||
|
||||
this.type = 'InstancedBufferGeometry';
|
||||
|
||||
/**
|
||||
* The instance count.
|
||||
*
|
||||
* @type {number}
|
||||
* @default Infinity
|
||||
*/
|
||||
this.instanceCount = Infinity;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.instanceCount = source.instanceCount;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.instanceCount = this.instanceCount;
|
||||
|
||||
data.isInstancedBufferGeometry = true;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { InstancedBufferGeometry };
|
||||
74
app/node_modules/three/src/core/InstancedInterleavedBuffer.js
generated
vendored
Normal file
74
app/node_modules/three/src/core/InstancedInterleavedBuffer.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
import { InterleavedBuffer } from './InterleavedBuffer.js';
|
||||
|
||||
/**
|
||||
* An instanced version of an interleaved buffer.
|
||||
*
|
||||
* @augments InterleavedBuffer
|
||||
*/
|
||||
class InstancedInterleavedBuffer extends InterleavedBuffer {
|
||||
|
||||
/**
|
||||
* Constructs a new instanced interleaved buffer.
|
||||
*
|
||||
* @param {TypedArray} array - A typed array with a shared buffer storing attribute data.
|
||||
* @param {number} stride - The number of typed-array elements per vertex.
|
||||
* @param {number} [meshPerAttribute=1] - Defines how often a value of this interleaved buffer should be repeated.
|
||||
*/
|
||||
constructor( array, stride, meshPerAttribute = 1 ) {
|
||||
|
||||
super( array, stride );
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInstancedInterleavedBuffer = true;
|
||||
|
||||
/**
|
||||
* Defines how often a value of this buffer attribute should be repeated,
|
||||
* see {@link InstancedBufferAttribute#meshPerAttribute}.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.meshPerAttribute = meshPerAttribute;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.meshPerAttribute = source.meshPerAttribute;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
clone( data ) {
|
||||
|
||||
const ib = super.clone( data );
|
||||
|
||||
ib.meshPerAttribute = this.meshPerAttribute;
|
||||
|
||||
return ib;
|
||||
|
||||
}
|
||||
|
||||
toJSON( data ) {
|
||||
|
||||
const json = super.toJSON( data );
|
||||
|
||||
json.isInstancedInterleavedBuffer = true;
|
||||
json.meshPerAttribute = this.meshPerAttribute;
|
||||
|
||||
return json;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { InstancedInterleavedBuffer };
|
||||
291
app/node_modules/three/src/core/InterleavedBuffer.js
generated
vendored
Normal file
291
app/node_modules/three/src/core/InterleavedBuffer.js
generated
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
import { generateUUID } from '../math/MathUtils.js';
|
||||
import { StaticDrawUsage } from '../constants.js';
|
||||
|
||||
/**
|
||||
* "Interleaved" means that multiple attributes, possibly of different types,
|
||||
* (e.g., position, normal, uv, color) are packed into a single array buffer.
|
||||
*
|
||||
* An introduction into interleaved arrays can be found here: [Interleaved array basics]{@link https://blog.tojicode.com/2011/05/interleaved-array-basics.html}
|
||||
*/
|
||||
class InterleavedBuffer {
|
||||
|
||||
/**
|
||||
* Constructs a new interleaved buffer.
|
||||
*
|
||||
* @param {TypedArray} array - A typed array with a shared buffer storing attribute data.
|
||||
* @param {number} stride - The number of typed-array elements per vertex.
|
||||
*/
|
||||
constructor( array, stride ) {
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInterleavedBuffer = true;
|
||||
|
||||
/**
|
||||
* A typed array with a shared buffer storing attribute data.
|
||||
*
|
||||
* @type {TypedArray}
|
||||
*/
|
||||
this.array = array;
|
||||
|
||||
/**
|
||||
* The number of typed-array elements per vertex.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.stride = stride;
|
||||
|
||||
/**
|
||||
* The total number of elements in the array
|
||||
*
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
this.count = array !== undefined ? array.length / stride : 0;
|
||||
|
||||
/**
|
||||
* Defines the intended usage pattern of the data store for optimization purposes.
|
||||
*
|
||||
* Note: After the initial use of a buffer, its usage cannot be changed. Instead,
|
||||
* instantiate a new one and set the desired usage before the next render.
|
||||
*
|
||||
* @type {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)}
|
||||
* @default StaticDrawUsage
|
||||
*/
|
||||
this.usage = StaticDrawUsage;
|
||||
|
||||
/**
|
||||
* This can be used to only update some components of stored vectors (for example, just the
|
||||
* component related to color). Use the `addUpdateRange()` function to add ranges to this array.
|
||||
*
|
||||
* @type {Array<Object>}
|
||||
*/
|
||||
this.updateRanges = [];
|
||||
|
||||
/**
|
||||
* A version number, incremented every time the `needsUpdate` is set to `true`.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.version = 0;
|
||||
|
||||
/**
|
||||
* The UUID of the interleaved buffer.
|
||||
*
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.uuid = generateUUID();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback function that is executed after the renderer has transferred the attribute array
|
||||
* data to the GPU.
|
||||
*/
|
||||
onUploadCallback() {}
|
||||
|
||||
/**
|
||||
* Flag to indicate that this attribute has changed and should be re-sent to
|
||||
* the GPU. Set this to `true` when you modify the value of the array.
|
||||
*
|
||||
* @type {number}
|
||||
* @default false
|
||||
* @param {boolean} value
|
||||
*/
|
||||
set needsUpdate( value ) {
|
||||
|
||||
if ( value === true ) this.version ++;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the usage of this interleaved buffer.
|
||||
*
|
||||
* @param {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)} value - The usage to set.
|
||||
* @return {InterleavedBuffer} A reference to this interleaved buffer.
|
||||
*/
|
||||
setUsage( value ) {
|
||||
|
||||
this.usage = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a range of data in the data array to be updated on the GPU.
|
||||
*
|
||||
* @param {number} start - Position at which to start update.
|
||||
* @param {number} count - The number of components to update.
|
||||
*/
|
||||
addUpdateRange( start, count ) {
|
||||
|
||||
this.updateRanges.push( { start, count } );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the update ranges.
|
||||
*/
|
||||
clearUpdateRanges() {
|
||||
|
||||
this.updateRanges.length = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the values of the given interleaved buffer to this instance.
|
||||
*
|
||||
* @param {InterleavedBuffer} source - The interleaved buffer to copy.
|
||||
* @return {InterleavedBuffer} A reference to this instance.
|
||||
*/
|
||||
copy( source ) {
|
||||
|
||||
this.array = new source.array.constructor( source.array );
|
||||
this.count = source.count;
|
||||
this.stride = source.stride;
|
||||
this.usage = source.usage;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a vector from the given interleaved buffer to this one. The start
|
||||
* and destination position in the attribute buffers are represented by the
|
||||
* given indices.
|
||||
*
|
||||
* @param {number} index1 - The destination index into this interleaved buffer.
|
||||
* @param {InterleavedBuffer} interleavedBuffer - The interleaved buffer to copy from.
|
||||
* @param {number} index2 - The source index into the given interleaved buffer.
|
||||
* @return {InterleavedBuffer} A reference to this instance.
|
||||
*/
|
||||
copyAt( index1, interleavedBuffer, index2 ) {
|
||||
|
||||
index1 *= this.stride;
|
||||
index2 *= interleavedBuffer.stride;
|
||||
|
||||
for ( let i = 0, l = this.stride; i < l; i ++ ) {
|
||||
|
||||
this.array[ index1 + i ] = interleavedBuffer.array[ index2 + i ];
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given array data in the interleaved buffer.
|
||||
*
|
||||
* @param {(TypedArray|Array)} value - The array data to set.
|
||||
* @param {number} [offset=0] - The offset in this interleaved buffer's array.
|
||||
* @return {InterleavedBuffer} A reference to this instance.
|
||||
*/
|
||||
set( value, offset = 0 ) {
|
||||
|
||||
this.array.set( value, offset );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new interleaved buffer with copied values from this instance.
|
||||
*
|
||||
* @param {Object} [data] - An object with shared array buffers that allows to retain shared structures.
|
||||
* @return {InterleavedBuffer} A clone of this instance.
|
||||
*/
|
||||
clone( data ) {
|
||||
|
||||
if ( data.arrayBuffers === undefined ) {
|
||||
|
||||
data.arrayBuffers = {};
|
||||
|
||||
}
|
||||
|
||||
if ( this.array.buffer._uuid === undefined ) {
|
||||
|
||||
this.array.buffer._uuid = generateUUID();
|
||||
|
||||
}
|
||||
|
||||
if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
|
||||
|
||||
data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
|
||||
|
||||
}
|
||||
|
||||
const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
|
||||
|
||||
const ib = new this.constructor( array, this.stride );
|
||||
ib.setUsage( this.usage );
|
||||
|
||||
return ib;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given callback function that is executed after the Renderer has transferred
|
||||
* the array data to the GPU. Can be used to perform clean-up operations after
|
||||
* the upload when data are not needed anymore on the CPU side.
|
||||
*
|
||||
* @param {Function} callback - The `onUpload()` callback.
|
||||
* @return {InterleavedBuffer} A reference to this instance.
|
||||
*/
|
||||
onUpload( callback ) {
|
||||
|
||||
this.onUploadCallback = callback;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the interleaved buffer into JSON.
|
||||
*
|
||||
* @param {Object} [data] - An optional value holding meta information about the serialization.
|
||||
* @return {Object} A JSON object representing the serialized interleaved buffer.
|
||||
*/
|
||||
toJSON( data ) {
|
||||
|
||||
if ( data.arrayBuffers === undefined ) {
|
||||
|
||||
data.arrayBuffers = {};
|
||||
|
||||
}
|
||||
|
||||
// generate UUID for array buffer if necessary
|
||||
|
||||
if ( this.array.buffer._uuid === undefined ) {
|
||||
|
||||
this.array.buffer._uuid = generateUUID();
|
||||
|
||||
}
|
||||
|
||||
if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
|
||||
|
||||
data.arrayBuffers[ this.array.buffer._uuid ] = Array.from( new Uint32Array( this.array.buffer ) );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
return {
|
||||
uuid: this.uuid,
|
||||
buffer: this.array.buffer._uuid,
|
||||
type: this.array.constructor.name,
|
||||
stride: this.stride
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { InterleavedBuffer };
|
||||
548
app/node_modules/three/src/core/InterleavedBufferAttribute.js
generated
vendored
Normal file
548
app/node_modules/three/src/core/InterleavedBufferAttribute.js
generated
vendored
Normal file
@@ -0,0 +1,548 @@
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { BufferAttribute } from './BufferAttribute.js';
|
||||
import { denormalize, normalize } from '../math/MathUtils.js';
|
||||
|
||||
const _vector = /*@__PURE__*/ new Vector3();
|
||||
|
||||
/**
|
||||
* An alternative version of a buffer attribute with interleaved data. Interleaved
|
||||
* attributes share a common interleaved data storage ({@link InterleavedBuffer}) and refer with
|
||||
* different offsets into the buffer.
|
||||
*/
|
||||
class InterleavedBufferAttribute {
|
||||
|
||||
/**
|
||||
* Constructs a new interleaved buffer attribute.
|
||||
*
|
||||
* @param {InterleavedBuffer} interleavedBuffer - The buffer holding the interleaved data.
|
||||
* @param {number} itemSize - The item size.
|
||||
* @param {number} offset - The attribute offset into the buffer.
|
||||
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
|
||||
*/
|
||||
constructor( interleavedBuffer, itemSize, offset, normalized = false ) {
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isInterleavedBufferAttribute = true;
|
||||
|
||||
/**
|
||||
* The name of the buffer attribute.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* The buffer holding the interleaved data.
|
||||
*
|
||||
* @type {InterleavedBuffer}
|
||||
*/
|
||||
this.data = interleavedBuffer;
|
||||
|
||||
/**
|
||||
* The item size, see {@link BufferAttribute#itemSize}.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.itemSize = itemSize;
|
||||
|
||||
/**
|
||||
* The attribute offset into the buffer.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.offset = offset;
|
||||
|
||||
/**
|
||||
* Whether the data are normalized or not, see {@link BufferAttribute#normalized}
|
||||
*
|
||||
* @type {InterleavedBuffer}
|
||||
*/
|
||||
this.normalized = normalized;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The item count of this buffer attribute.
|
||||
*
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get count() {
|
||||
|
||||
return this.data.count;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The array holding the interleaved buffer attribute data.
|
||||
*
|
||||
* @type {TypedArray}
|
||||
*/
|
||||
get array() {
|
||||
|
||||
return this.data.array;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to indicate that this attribute has changed and should be re-sent to
|
||||
* the GPU. Set this to `true` when you modify the value of the array.
|
||||
*
|
||||
* @type {number}
|
||||
* @default false
|
||||
* @param {boolean} value
|
||||
*/
|
||||
set needsUpdate( value ) {
|
||||
|
||||
this.data.needsUpdate = value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the given 4x4 matrix to the given attribute. Only works with
|
||||
* item size `3`.
|
||||
*
|
||||
* @param {Matrix4} m - The matrix to apply.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
applyMatrix4( m ) {
|
||||
|
||||
for ( let i = 0, l = this.data.count; i < l; i ++ ) {
|
||||
|
||||
_vector.fromBufferAttribute( this, i );
|
||||
|
||||
_vector.applyMatrix4( m );
|
||||
|
||||
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the given 3x3 normal matrix to the given attribute. Only works with
|
||||
* item size `3`.
|
||||
*
|
||||
* @param {Matrix3} m - The normal matrix to apply.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
applyNormalMatrix( m ) {
|
||||
|
||||
for ( let i = 0, l = this.count; i < l; i ++ ) {
|
||||
|
||||
_vector.fromBufferAttribute( this, i );
|
||||
|
||||
_vector.applyNormalMatrix( m );
|
||||
|
||||
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the given 4x4 matrix to the given attribute. Only works with
|
||||
* item size `3` and with direction vectors.
|
||||
*
|
||||
* @param {Matrix4} m - The matrix to apply.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
transformDirection( m ) {
|
||||
|
||||
for ( let i = 0, l = this.count; i < l; i ++ ) {
|
||||
|
||||
_vector.fromBufferAttribute( this, i );
|
||||
|
||||
_vector.transformDirection( m );
|
||||
|
||||
this.setXYZ( i, _vector.x, _vector.y, _vector.z );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} component - The component index.
|
||||
* @return {number} The returned value.
|
||||
*/
|
||||
getComponent( index, component ) {
|
||||
|
||||
let value = this.array[ index * this.data.stride + this.offset + component ];
|
||||
|
||||
if ( this.normalized ) value = denormalize( value, this.array );
|
||||
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given value to the given component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} component - The component index.
|
||||
* @param {number} value - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setComponent( index, component, value ) {
|
||||
|
||||
if ( this.normalized ) value = normalize( value, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + component ] = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} x - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setX( index, x ) {
|
||||
|
||||
if ( this.normalized ) x = normalize( x, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset ] = x;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the y component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} y - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setY( index, y ) {
|
||||
|
||||
if ( this.normalized ) y = normalize( y, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the z component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} z - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setZ( index, z ) {
|
||||
|
||||
if ( this.normalized ) z = normalize( z, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the w component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} w - The value to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setW( index, w ) {
|
||||
|
||||
if ( this.normalized ) w = normalize( w, this.array );
|
||||
|
||||
this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the x component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @return {number} The x component.
|
||||
*/
|
||||
getX( index ) {
|
||||
|
||||
let x = this.data.array[ index * this.data.stride + this.offset ];
|
||||
|
||||
if ( this.normalized ) x = denormalize( x, this.array );
|
||||
|
||||
return x;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the y component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @return {number} The y component.
|
||||
*/
|
||||
getY( index ) {
|
||||
|
||||
let y = this.data.array[ index * this.data.stride + this.offset + 1 ];
|
||||
|
||||
if ( this.normalized ) y = denormalize( y, this.array );
|
||||
|
||||
return y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the z component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @return {number} The z component.
|
||||
*/
|
||||
getZ( index ) {
|
||||
|
||||
let z = this.data.array[ index * this.data.stride + this.offset + 2 ];
|
||||
|
||||
if ( this.normalized ) z = denormalize( z, this.array );
|
||||
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the w component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @return {number} The w component.
|
||||
*/
|
||||
getW( index ) {
|
||||
|
||||
let w = this.data.array[ index * this.data.stride + this.offset + 3 ];
|
||||
|
||||
if ( this.normalized ) w = denormalize( w, this.array );
|
||||
|
||||
return w;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x and y component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} x - The value for the x component to set.
|
||||
* @param {number} y - The value for the y component to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setXY( index, x, y ) {
|
||||
|
||||
index = index * this.data.stride + this.offset;
|
||||
|
||||
if ( this.normalized ) {
|
||||
|
||||
x = normalize( x, this.array );
|
||||
y = normalize( y, this.array );
|
||||
|
||||
}
|
||||
|
||||
this.data.array[ index + 0 ] = x;
|
||||
this.data.array[ index + 1 ] = y;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x, y and z component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} x - The value for the x component to set.
|
||||
* @param {number} y - The value for the y component to set.
|
||||
* @param {number} z - The value for the z component to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setXYZ( index, x, y, z ) {
|
||||
|
||||
index = index * this.data.stride + this.offset;
|
||||
|
||||
if ( this.normalized ) {
|
||||
|
||||
x = normalize( x, this.array );
|
||||
y = normalize( y, this.array );
|
||||
z = normalize( z, this.array );
|
||||
|
||||
}
|
||||
|
||||
this.data.array[ index + 0 ] = x;
|
||||
this.data.array[ index + 1 ] = y;
|
||||
this.data.array[ index + 2 ] = z;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x, y, z and w component of the vector at the given index.
|
||||
*
|
||||
* @param {number} index - The index into the buffer attribute.
|
||||
* @param {number} x - The value for the x component to set.
|
||||
* @param {number} y - The value for the y component to set.
|
||||
* @param {number} z - The value for the z component to set.
|
||||
* @param {number} w - The value for the w component to set.
|
||||
* @return {InterleavedBufferAttribute} A reference to this instance.
|
||||
*/
|
||||
setXYZW( index, x, y, z, w ) {
|
||||
|
||||
index = index * this.data.stride + this.offset;
|
||||
|
||||
if ( this.normalized ) {
|
||||
|
||||
x = normalize( x, this.array );
|
||||
y = normalize( y, this.array );
|
||||
z = normalize( z, this.array );
|
||||
w = normalize( w, this.array );
|
||||
|
||||
}
|
||||
|
||||
this.data.array[ index + 0 ] = x;
|
||||
this.data.array[ index + 1 ] = y;
|
||||
this.data.array[ index + 2 ] = z;
|
||||
this.data.array[ index + 3 ] = w;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new buffer attribute with copied values from this instance.
|
||||
*
|
||||
* If no parameter is provided, cloning an interleaved buffer attribute will de-interleave buffer data.
|
||||
*
|
||||
* @param {Object} [data] - An object with interleaved buffers that allows to retain the interleaved property.
|
||||
* @return {BufferAttribute|InterleavedBufferAttribute} A clone of this instance.
|
||||
*/
|
||||
clone( data ) {
|
||||
|
||||
if ( data === undefined ) {
|
||||
|
||||
console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );
|
||||
|
||||
const array = [];
|
||||
|
||||
for ( let i = 0; i < this.count; i ++ ) {
|
||||
|
||||
const index = i * this.data.stride + this.offset;
|
||||
|
||||
for ( let j = 0; j < this.itemSize; j ++ ) {
|
||||
|
||||
array.push( this.data.array[ index + j ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
|
||||
|
||||
} else {
|
||||
|
||||
if ( data.interleavedBuffers === undefined ) {
|
||||
|
||||
data.interleavedBuffers = {};
|
||||
|
||||
}
|
||||
|
||||
if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
|
||||
|
||||
data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
|
||||
|
||||
}
|
||||
|
||||
return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the buffer attribute into JSON.
|
||||
*
|
||||
* If no parameter is provided, cloning an interleaved buffer attribute will de-interleave buffer data.
|
||||
*
|
||||
* @param {Object} [data] - An optional value holding meta information about the serialization.
|
||||
* @return {Object} A JSON object representing the serialized buffer attribute.
|
||||
*/
|
||||
toJSON( data ) {
|
||||
|
||||
if ( data === undefined ) {
|
||||
|
||||
console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );
|
||||
|
||||
const array = [];
|
||||
|
||||
for ( let i = 0; i < this.count; i ++ ) {
|
||||
|
||||
const index = i * this.data.stride + this.offset;
|
||||
|
||||
for ( let j = 0; j < this.itemSize; j ++ ) {
|
||||
|
||||
array.push( this.data.array[ index + j ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// de-interleave data and save it as an ordinary buffer attribute for now
|
||||
|
||||
return {
|
||||
itemSize: this.itemSize,
|
||||
type: this.array.constructor.name,
|
||||
array: array,
|
||||
normalized: this.normalized
|
||||
};
|
||||
|
||||
} else {
|
||||
|
||||
// save as true interleaved attribute
|
||||
|
||||
if ( data.interleavedBuffers === undefined ) {
|
||||
|
||||
data.interleavedBuffers = {};
|
||||
|
||||
}
|
||||
|
||||
if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
|
||||
|
||||
data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
isInterleavedBufferAttribute: true,
|
||||
itemSize: this.itemSize,
|
||||
data: this.data.uuid,
|
||||
offset: this.offset,
|
||||
normalized: this.normalized
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { InterleavedBufferAttribute };
|
||||
121
app/node_modules/three/src/core/Layers.js
generated
vendored
Normal file
121
app/node_modules/three/src/core/Layers.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* A layers object assigns an 3D object to 1 or more of 32
|
||||
* layers numbered `0` to `31` - internally the layers are stored as a
|
||||
* bit mask], and by default all 3D objects are a member of layer `0`.
|
||||
*
|
||||
* This can be used to control visibility - an object must share a layer with
|
||||
* a camera to be visible when that camera's view is
|
||||
* rendered.
|
||||
*
|
||||
* All classes that inherit from {@link Object3D} have an `layers` property which
|
||||
* is an instance of this class.
|
||||
*/
|
||||
class Layers {
|
||||
|
||||
/**
|
||||
* Constructs a new layers instance, with membership
|
||||
* initially set to layer `0`.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
/**
|
||||
* A bit mask storing which of the 32 layers this layers object is currently
|
||||
* a member of.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.mask = 1 | 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets membership to the given layer, and remove membership all other layers.
|
||||
*
|
||||
* @param {number} layer - The layer to set.
|
||||
*/
|
||||
set( layer ) {
|
||||
|
||||
this.mask = ( 1 << layer | 0 ) >>> 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds membership of the given layer.
|
||||
*
|
||||
* @param {number} layer - The layer to enable.
|
||||
*/
|
||||
enable( layer ) {
|
||||
|
||||
this.mask |= 1 << layer | 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds membership to all layers.
|
||||
*/
|
||||
enableAll() {
|
||||
|
||||
this.mask = 0xffffffff | 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the membership of the given layer.
|
||||
*
|
||||
* @param {number} layer - The layer to toggle.
|
||||
*/
|
||||
toggle( layer ) {
|
||||
|
||||
this.mask ^= 1 << layer | 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes membership of the given layer.
|
||||
*
|
||||
* @param {number} layer - The layer to enable.
|
||||
*/
|
||||
disable( layer ) {
|
||||
|
||||
this.mask &= ~ ( 1 << layer | 0 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the membership from all layers.
|
||||
*/
|
||||
disableAll() {
|
||||
|
||||
this.mask = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if this and the given layers object have at least one
|
||||
* layer in common.
|
||||
*
|
||||
* @param {Layers} layers - The layers to test.
|
||||
* @return {boolean } Whether this and the given layers object have at least one layer in common or not.
|
||||
*/
|
||||
test( layers ) {
|
||||
|
||||
return ( this.mask & layers.mask ) !== 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the given layer is enabled.
|
||||
*
|
||||
* @param {number} layer - The layer to test.
|
||||
* @return {boolean } Whether the given layer is enabled or not.
|
||||
*/
|
||||
isEnabled( layer ) {
|
||||
|
||||
return ( this.mask & ( 1 << layer | 0 ) ) !== 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { Layers };
|
||||
1618
app/node_modules/three/src/core/Object3D.js
generated
vendored
Normal file
1618
app/node_modules/three/src/core/Object3D.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
261
app/node_modules/three/src/core/Raycaster.js
generated
vendored
Normal file
261
app/node_modules/three/src/core/Raycaster.js
generated
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
import { Matrix4 } from '../math/Matrix4.js';
|
||||
import { Ray } from '../math/Ray.js';
|
||||
import { Layers } from './Layers.js';
|
||||
|
||||
const _matrix = /*@__PURE__*/ new Matrix4();
|
||||
|
||||
/**
|
||||
* This class is designed to assist with raycasting. Raycasting is used for
|
||||
* mouse picking (working out what objects in the 3d space the mouse is over)
|
||||
* amongst other things.
|
||||
*/
|
||||
class Raycaster {
|
||||
|
||||
/**
|
||||
* Constructs a new raycaster.
|
||||
*
|
||||
* @param {Vector3} origin - The origin vector where the ray casts from.
|
||||
* @param {Vector3} direction - The (normalized) direction vector that gives direction to the ray.
|
||||
* @param {number} [near=0] - All results returned are further away than near. Near can't be negative.
|
||||
* @param {number} [far=Infinity] - All results returned are closer than far. Far can't be lower than near.
|
||||
*/
|
||||
constructor( origin, direction, near = 0, far = Infinity ) {
|
||||
|
||||
/**
|
||||
* The ray used for raycasting.
|
||||
*
|
||||
* @type {Ray}
|
||||
*/
|
||||
this.ray = new Ray( origin, direction );
|
||||
|
||||
/**
|
||||
* All results returned are further away than near. Near can't be negative.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.near = near;
|
||||
|
||||
/**
|
||||
* All results returned are further away than near. Near can't be negative.
|
||||
*
|
||||
* @type {number}
|
||||
* @default Infinity
|
||||
*/
|
||||
this.far = far;
|
||||
|
||||
/**
|
||||
* The camera to use when raycasting against view-dependent objects such as
|
||||
* billboarded objects like sprites. This field can be set manually or
|
||||
* is set when calling `setFromCamera()`.
|
||||
*
|
||||
* @type {?Camera}
|
||||
* @default null
|
||||
*/
|
||||
this.camera = null;
|
||||
|
||||
/**
|
||||
* Allows to selectively ignore 3D objects when performing intersection tests.
|
||||
* The following code example ensures that only 3D objects on layer `1` will be
|
||||
* honored by raycaster.
|
||||
* ```js
|
||||
* raycaster.layers.set( 1 );
|
||||
* object.layers.enable( 1 );
|
||||
* ```
|
||||
*
|
||||
* @type {Layers}
|
||||
*/
|
||||
this.layers = new Layers();
|
||||
|
||||
|
||||
/**
|
||||
* A parameter object that configures the raycasting. It has the structure:
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
* Mesh: {},
|
||||
* Line: { threshold: 1 },
|
||||
* LOD: {},
|
||||
* Points: { threshold: 1 },
|
||||
* Sprite: {}
|
||||
* }
|
||||
* ```
|
||||
* Where `threshold` is the precision of the raycaster when intersecting objects, in world units.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.params = {
|
||||
Mesh: {},
|
||||
Line: { threshold: 1 },
|
||||
LOD: {},
|
||||
Points: { threshold: 1 },
|
||||
Sprite: {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the ray with a new origin and direction by copying the values from the arguments.
|
||||
*
|
||||
* @param {Vector3} origin - The origin vector where the ray casts from.
|
||||
* @param {Vector3} direction - The (normalized) direction vector that gives direction to the ray.
|
||||
*/
|
||||
set( origin, direction ) {
|
||||
|
||||
// direction is assumed to be normalized (for accurate distance calculations)
|
||||
|
||||
this.ray.set( origin, direction );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the given coordinates and camera to compute a new origin and direction for the internal ray.
|
||||
*
|
||||
* @param {Vector2} coords - 2D coordinates of the mouse, in normalized device coordinates (NDC).
|
||||
* X and Y components should be between `-1` and `1`.
|
||||
* @param {Camera} camera - The camera from which the ray should originate.
|
||||
*/
|
||||
setFromCamera( coords, camera ) {
|
||||
|
||||
if ( camera.isPerspectiveCamera ) {
|
||||
|
||||
this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
|
||||
this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
|
||||
this.camera = camera;
|
||||
|
||||
} else if ( camera.isOrthographicCamera ) {
|
||||
|
||||
this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
|
||||
this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
|
||||
this.camera = camera;
|
||||
|
||||
} else {
|
||||
|
||||
console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the given WebXR controller to compute a new origin and direction for the internal ray.
|
||||
*
|
||||
* @param {WebXRController} controller - The controller to copy the position and direction from.
|
||||
* @return {Raycaster} A reference to this raycaster.
|
||||
*/
|
||||
setFromXRController( controller ) {
|
||||
|
||||
_matrix.identity().extractRotation( controller.matrixWorld );
|
||||
|
||||
this.ray.origin.setFromMatrixPosition( controller.matrixWorld );
|
||||
this.ray.direction.set( 0, 0, - 1 ).applyMatrix4( _matrix );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The intersection point of a raycaster intersection test.
|
||||
* @typedef {Object} Raycaster~Intersection
|
||||
* @property {number} distance - The distance from the ray's origin to the intersection point.
|
||||
* @property {number} distanceToRay - Some 3D objects e.g. {@link Points} provide the distance of the
|
||||
* intersection to the nearest point on the ray. For other objects it will be `undefined`.
|
||||
* @property {Vector3} point - The intersection point, in world coordinates.
|
||||
* @property {Object} face - The face that has been intersected.
|
||||
* @property {number} faceIndex - The face index.
|
||||
* @property {Object3D} object - The 3D object that has been intersected.
|
||||
* @property {Vector2} uv - U,V coordinates at point of intersection.
|
||||
* @property {Vector2} uv1 - Second set of U,V coordinates at point of intersection.
|
||||
* @property {Vector3} uv1 - Interpolated normal vector at point of intersection.
|
||||
* @property {number} instanceId - The index number of the instance where the ray
|
||||
* intersects the {@link InstancedMesh}.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks all intersection between the ray and the object with or without the
|
||||
* descendants. Intersections are returned sorted by distance, closest first.
|
||||
*
|
||||
* `Raycaster` delegates to the `raycast()` method of the passed 3D object, when
|
||||
* evaluating whether the ray intersects the object or not. This allows meshes to respond
|
||||
* differently to ray casting than lines or points.
|
||||
*
|
||||
* Note that for meshes, faces must be pointed towards the origin of the ray in order
|
||||
* to be detected; intersections of the ray passing through the back of a face will not
|
||||
* be detected. To raycast against both faces of an object, you'll want to set {@link Material#side}
|
||||
* to `THREE.DoubleSide`.
|
||||
*
|
||||
* @param {Object3D} object - The 3D object to check for intersection with the ray.
|
||||
* @param {boolean} [recursive=true] - If set to `true`, it also checks all descendants.
|
||||
* Otherwise it only checks intersection with the object.
|
||||
* @param {Array<Raycaster~Intersection>} [intersects=[]] The target array that holds the result of the method.
|
||||
* @return {Array<Raycaster~Intersection>} An array holding the intersection points.
|
||||
*/
|
||||
intersectObject( object, recursive = true, intersects = [] ) {
|
||||
|
||||
intersect( object, this, intersects, recursive );
|
||||
|
||||
intersects.sort( ascSort );
|
||||
|
||||
return intersects;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks all intersection between the ray and the objects with or without
|
||||
* the descendants. Intersections are returned sorted by distance, closest first.
|
||||
*
|
||||
* @param {Array<Object3D>} objects - The 3D objects to check for intersection with the ray.
|
||||
* @param {boolean} [recursive=true] - If set to `true`, it also checks all descendants.
|
||||
* Otherwise it only checks intersection with the object.
|
||||
* @param {Array<Raycaster~Intersection>} [intersects=[]] The target array that holds the result of the method.
|
||||
* @return {Array<Raycaster~Intersection>} An array holding the intersection points.
|
||||
*/
|
||||
intersectObjects( objects, recursive = true, intersects = [] ) {
|
||||
|
||||
for ( let i = 0, l = objects.length; i < l; i ++ ) {
|
||||
|
||||
intersect( objects[ i ], this, intersects, recursive );
|
||||
|
||||
}
|
||||
|
||||
intersects.sort( ascSort );
|
||||
|
||||
return intersects;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ascSort( a, b ) {
|
||||
|
||||
return a.distance - b.distance;
|
||||
|
||||
}
|
||||
|
||||
function intersect( object, raycaster, intersects, recursive ) {
|
||||
|
||||
let propagate = true;
|
||||
|
||||
if ( object.layers.test( raycaster.layers ) ) {
|
||||
|
||||
const result = object.raycast( raycaster, intersects );
|
||||
|
||||
if ( result === false ) propagate = false;
|
||||
|
||||
}
|
||||
|
||||
if ( propagate === true && recursive === true ) {
|
||||
|
||||
const children = object.children;
|
||||
|
||||
for ( let i = 0, l = children.length; i < l; i ++ ) {
|
||||
|
||||
intersect( children[ i ], raycaster, intersects, true );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Raycaster };
|
||||
383
app/node_modules/three/src/core/RenderTarget.js
generated
vendored
Normal file
383
app/node_modules/three/src/core/RenderTarget.js
generated
vendored
Normal file
@@ -0,0 +1,383 @@
|
||||
import { EventDispatcher } from './EventDispatcher.js';
|
||||
import { Texture } from '../textures/Texture.js';
|
||||
import { LinearFilter } from '../constants.js';
|
||||
import { Vector4 } from '../math/Vector4.js';
|
||||
import { Source } from '../textures/Source.js';
|
||||
|
||||
/**
|
||||
* A render target is a buffer where the video card draws pixels for a scene
|
||||
* that is being rendered in the background. It is used in different effects,
|
||||
* such as applying postprocessing to a rendered image before displaying it
|
||||
* on the screen.
|
||||
*
|
||||
* @augments EventDispatcher
|
||||
*/
|
||||
class RenderTarget extends EventDispatcher {
|
||||
|
||||
/**
|
||||
* Render target options.
|
||||
*
|
||||
* @typedef {Object} RenderTarget~Options
|
||||
* @property {boolean} [generateMipmaps=false] - Whether to generate mipmaps or not.
|
||||
* @property {number} [magFilter=LinearFilter] - The mag filter.
|
||||
* @property {number} [minFilter=LinearFilter] - The min filter.
|
||||
* @property {number} [format=RGBAFormat] - The texture format.
|
||||
* @property {number} [type=UnsignedByteType] - The texture type.
|
||||
* @property {?string} [internalFormat=null] - The texture's internal format.
|
||||
* @property {number} [wrapS=ClampToEdgeWrapping] - The texture's uv wrapping mode.
|
||||
* @property {number} [wrapT=ClampToEdgeWrapping] - The texture's uv wrapping mode.
|
||||
* @property {number} [anisotropy=1] - The texture's anisotropy value.
|
||||
* @property {string} [colorSpace=NoColorSpace] - The texture's color space.
|
||||
* @property {boolean} [depthBuffer=true] - Whether to allocate a depth buffer or not.
|
||||
* @property {boolean} [stencilBuffer=false] - Whether to allocate a stencil buffer or not.
|
||||
* @property {boolean} [resolveDepthBuffer=true] - Whether to resolve the depth buffer or not.
|
||||
* @property {boolean} [resolveStencilBuffer=true] - Whether to resolve the stencil buffer or not.
|
||||
* @property {?Texture} [depthTexture=null] - Reference to a depth texture.
|
||||
* @property {number} [samples=0] - The MSAA samples count.
|
||||
* @property {number} [count=1] - Defines the number of color attachments . Must be at least `1`.
|
||||
* @property {number} [depth=1] - The texture depth.
|
||||
* @property {boolean} [multiview=false] - Whether this target is used for multiview rendering.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructs a new render target.
|
||||
*
|
||||
* @param {number} [width=1] - The width of the render target.
|
||||
* @param {number} [height=1] - The height of the render target.
|
||||
* @param {RenderTarget~Options} [options] - The configuration object.
|
||||
*/
|
||||
constructor( width = 1, height = 1, options = {} ) {
|
||||
|
||||
super();
|
||||
|
||||
options = Object.assign( {
|
||||
generateMipmaps: false,
|
||||
internalFormat: null,
|
||||
minFilter: LinearFilter,
|
||||
depthBuffer: true,
|
||||
stencilBuffer: false,
|
||||
resolveDepthBuffer: true,
|
||||
resolveStencilBuffer: true,
|
||||
depthTexture: null,
|
||||
samples: 0,
|
||||
count: 1,
|
||||
depth: 1,
|
||||
multiview: false
|
||||
}, options );
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isRenderTarget = true;
|
||||
|
||||
/**
|
||||
* The width of the render target.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.width = width;
|
||||
|
||||
/**
|
||||
* The height of the render target.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.height = height;
|
||||
|
||||
/**
|
||||
* The depth of the render target.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.depth = options.depth;
|
||||
|
||||
/**
|
||||
* A rectangular area inside the render target's viewport. Fragments that are
|
||||
* outside the area will be discarded.
|
||||
*
|
||||
* @type {Vector4}
|
||||
* @default (0,0,width,height)
|
||||
*/
|
||||
this.scissor = new Vector4( 0, 0, width, height );
|
||||
|
||||
/**
|
||||
* Indicates whether the scissor test should be enabled when rendering into
|
||||
* this render target or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.scissorTest = false;
|
||||
|
||||
/**
|
||||
* A rectangular area representing the render target's viewport.
|
||||
*
|
||||
* @type {Vector4}
|
||||
* @default (0,0,width,height)
|
||||
*/
|
||||
this.viewport = new Vector4( 0, 0, width, height );
|
||||
|
||||
const image = { width: width, height: height, depth: options.depth };
|
||||
|
||||
const texture = new Texture( image );
|
||||
|
||||
/**
|
||||
* An array of textures. Each color attachment is represented as a separate texture.
|
||||
* Has at least a single entry for the default color attachment.
|
||||
*
|
||||
* @type {Array<Texture>}
|
||||
*/
|
||||
this.textures = [];
|
||||
|
||||
const count = options.count;
|
||||
for ( let i = 0; i < count; i ++ ) {
|
||||
|
||||
this.textures[ i ] = texture.clone();
|
||||
this.textures[ i ].isRenderTargetTexture = true;
|
||||
this.textures[ i ].renderTarget = this;
|
||||
|
||||
}
|
||||
|
||||
this._setTextureOptions( options );
|
||||
|
||||
/**
|
||||
* Whether to allocate a depth buffer or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.depthBuffer = options.depthBuffer;
|
||||
|
||||
/**
|
||||
* Whether to allocate a stencil buffer or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.stencilBuffer = options.stencilBuffer;
|
||||
|
||||
/**
|
||||
* Whether to resolve the depth buffer or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.resolveDepthBuffer = options.resolveDepthBuffer;
|
||||
|
||||
/**
|
||||
* Whether to resolve the stencil buffer or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.resolveStencilBuffer = options.resolveStencilBuffer;
|
||||
|
||||
this._depthTexture = null;
|
||||
this.depthTexture = options.depthTexture;
|
||||
|
||||
/**
|
||||
* The number of MSAA samples.
|
||||
*
|
||||
* A value of `0` disables MSAA.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.samples = options.samples;
|
||||
|
||||
/**
|
||||
* Whether to this target is used in multiview rendering.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.multiview = options.multiview;
|
||||
|
||||
}
|
||||
|
||||
_setTextureOptions( options = {} ) {
|
||||
|
||||
const values = {
|
||||
minFilter: LinearFilter,
|
||||
generateMipmaps: false,
|
||||
flipY: false,
|
||||
internalFormat: null
|
||||
};
|
||||
|
||||
if ( options.mapping !== undefined ) values.mapping = options.mapping;
|
||||
if ( options.wrapS !== undefined ) values.wrapS = options.wrapS;
|
||||
if ( options.wrapT !== undefined ) values.wrapT = options.wrapT;
|
||||
if ( options.wrapR !== undefined ) values.wrapR = options.wrapR;
|
||||
if ( options.magFilter !== undefined ) values.magFilter = options.magFilter;
|
||||
if ( options.minFilter !== undefined ) values.minFilter = options.minFilter;
|
||||
if ( options.format !== undefined ) values.format = options.format;
|
||||
if ( options.type !== undefined ) values.type = options.type;
|
||||
if ( options.anisotropy !== undefined ) values.anisotropy = options.anisotropy;
|
||||
if ( options.colorSpace !== undefined ) values.colorSpace = options.colorSpace;
|
||||
if ( options.flipY !== undefined ) values.flipY = options.flipY;
|
||||
if ( options.generateMipmaps !== undefined ) values.generateMipmaps = options.generateMipmaps;
|
||||
if ( options.internalFormat !== undefined ) values.internalFormat = options.internalFormat;
|
||||
|
||||
for ( let i = 0; i < this.textures.length; i ++ ) {
|
||||
|
||||
const texture = this.textures[ i ];
|
||||
texture.setValues( values );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The texture representing the default color attachment.
|
||||
*
|
||||
* @type {Texture}
|
||||
*/
|
||||
get texture() {
|
||||
|
||||
return this.textures[ 0 ];
|
||||
|
||||
}
|
||||
|
||||
set texture( value ) {
|
||||
|
||||
this.textures[ 0 ] = value;
|
||||
|
||||
}
|
||||
|
||||
set depthTexture( current ) {
|
||||
|
||||
if ( this._depthTexture !== null ) this._depthTexture.renderTarget = null;
|
||||
if ( current !== null ) current.renderTarget = this;
|
||||
|
||||
this._depthTexture = current;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instead of saving the depth in a renderbuffer, a texture
|
||||
* can be used instead which is useful for further processing
|
||||
* e.g. in context of post-processing.
|
||||
*
|
||||
* @type {?DepthTexture}
|
||||
* @default null
|
||||
*/
|
||||
get depthTexture() {
|
||||
|
||||
return this._depthTexture;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of this render target.
|
||||
*
|
||||
* @param {number} width - The width.
|
||||
* @param {number} height - The height.
|
||||
* @param {number} [depth=1] - The depth.
|
||||
*/
|
||||
setSize( width, height, depth = 1 ) {
|
||||
|
||||
if ( this.width !== width || this.height !== height || this.depth !== depth ) {
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = depth;
|
||||
|
||||
for ( let i = 0, il = this.textures.length; i < il; i ++ ) {
|
||||
|
||||
this.textures[ i ].image.width = width;
|
||||
this.textures[ i ].image.height = height;
|
||||
this.textures[ i ].image.depth = depth;
|
||||
this.textures[ i ].isArrayTexture = this.textures[ i ].image.depth > 1;
|
||||
|
||||
}
|
||||
|
||||
this.dispose();
|
||||
|
||||
}
|
||||
|
||||
this.viewport.set( 0, 0, width, height );
|
||||
this.scissor.set( 0, 0, width, height );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new render target with copied values from this instance.
|
||||
*
|
||||
* @return {RenderTarget} A clone of this instance.
|
||||
*/
|
||||
clone() {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the settings of the given render target. This is a structural copy so
|
||||
* no resources are shared between render targets after the copy. That includes
|
||||
* all MRT textures and the depth texture.
|
||||
*
|
||||
* @param {RenderTarget} source - The render target to copy.
|
||||
* @return {RenderTarget} A reference to this instance.
|
||||
*/
|
||||
copy( source ) {
|
||||
|
||||
this.width = source.width;
|
||||
this.height = source.height;
|
||||
this.depth = source.depth;
|
||||
|
||||
this.scissor.copy( source.scissor );
|
||||
this.scissorTest = source.scissorTest;
|
||||
|
||||
this.viewport.copy( source.viewport );
|
||||
|
||||
this.textures.length = 0;
|
||||
|
||||
for ( let i = 0, il = source.textures.length; i < il; i ++ ) {
|
||||
|
||||
this.textures[ i ] = source.textures[ i ].clone();
|
||||
this.textures[ i ].isRenderTargetTexture = true;
|
||||
this.textures[ i ].renderTarget = this;
|
||||
|
||||
// ensure image object is not shared, see #20328
|
||||
|
||||
const image = Object.assign( {}, source.textures[ i ].image );
|
||||
this.textures[ i ].source = new Source( image );
|
||||
|
||||
}
|
||||
|
||||
this.depthBuffer = source.depthBuffer;
|
||||
this.stencilBuffer = source.stencilBuffer;
|
||||
|
||||
this.resolveDepthBuffer = source.resolveDepthBuffer;
|
||||
this.resolveStencilBuffer = source.resolveStencilBuffer;
|
||||
|
||||
if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();
|
||||
|
||||
this.samples = source.samples;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever this instance is no longer used in your app.
|
||||
*
|
||||
* @fires RenderTarget#dispose
|
||||
*/
|
||||
dispose() {
|
||||
|
||||
this.dispatchEvent( { type: 'dispose' } );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { RenderTarget };
|
||||
48
app/node_modules/three/src/core/RenderTarget3D.js
generated
vendored
Normal file
48
app/node_modules/three/src/core/RenderTarget3D.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import { RenderTarget } from './RenderTarget.js';
|
||||
import { Data3DTexture } from '../textures/Data3DTexture.js';
|
||||
|
||||
/**
|
||||
* Represents a 3D render target.
|
||||
*
|
||||
* @augments RenderTarget
|
||||
*/
|
||||
class RenderTarget3D extends RenderTarget {
|
||||
|
||||
/**
|
||||
* Constructs a new 3D render target.
|
||||
*
|
||||
* @param {number} [width=1] - The width of the render target.
|
||||
* @param {number} [height=1] - The height of the render target.
|
||||
* @param {number} [depth=1] - The height of the render target.
|
||||
* @param {RenderTarget~Options} [options] - The configuration object.
|
||||
*/
|
||||
constructor( width = 1, height = 1, depth = 1, options = {} ) {
|
||||
|
||||
super( width, height, options );
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isRenderTarget3D = true;
|
||||
|
||||
this.depth = depth;
|
||||
|
||||
/**
|
||||
* Overwritten with a different texture type.
|
||||
*
|
||||
* @type {Data3DTexture}
|
||||
*/
|
||||
this.texture = new Data3DTexture( null, width, height, depth );
|
||||
this._setTextureOptions( options );
|
||||
|
||||
this.texture.isRenderTargetTexture = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { RenderTarget3D };
|
||||
46
app/node_modules/three/src/core/Uniform.js
generated
vendored
Normal file
46
app/node_modules/three/src/core/Uniform.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Represents a uniform which is a global shader variable. They are passed to shader programs.
|
||||
*
|
||||
* When declaring a uniform of a {@link ShaderMaterial}, it is declared by value or by object.
|
||||
* ```js
|
||||
* uniforms: {
|
||||
* time: { value: 1.0 },
|
||||
* resolution: new Uniform( new Vector2() )
|
||||
* };
|
||||
* ```
|
||||
* Since this class can only be used in context of {@link ShaderMaterial}, it is only supported
|
||||
* in {@link WebGLRenderer}.
|
||||
*/
|
||||
class Uniform {
|
||||
|
||||
/**
|
||||
* Constructs a new uniform.
|
||||
*
|
||||
* @param {any} value - The uniform value.
|
||||
*/
|
||||
constructor( value ) {
|
||||
|
||||
/**
|
||||
* The uniform value.
|
||||
*
|
||||
* @type {any}
|
||||
*/
|
||||
this.value = value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new uniform with copied values from this instance.
|
||||
* If the value has a `clone()` method, the value is cloned as well.
|
||||
*
|
||||
* @return {Uniform} A clone of this instance.
|
||||
*/
|
||||
clone() {
|
||||
|
||||
return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Uniform };
|
||||
180
app/node_modules/three/src/core/UniformsGroup.js
generated
vendored
Normal file
180
app/node_modules/three/src/core/UniformsGroup.js
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
import { EventDispatcher } from './EventDispatcher.js';
|
||||
import { StaticDrawUsage } from '../constants.js';
|
||||
|
||||
let _id = 0;
|
||||
|
||||
/**
|
||||
* A class for managing multiple uniforms in a single group. The renderer will process
|
||||
* such a definition as a single UBO.
|
||||
*
|
||||
* Since this class can only be used in context of {@link ShaderMaterial}, it is only supported
|
||||
* in {@link WebGLRenderer}.
|
||||
*
|
||||
* @augments EventDispatcher
|
||||
*/
|
||||
class UniformsGroup extends EventDispatcher {
|
||||
|
||||
/**
|
||||
* Constructs a new uniforms group.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isUniformsGroup = true;
|
||||
|
||||
/**
|
||||
* The ID of the 3D object.
|
||||
*
|
||||
* @name UniformsGroup#id
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty( this, 'id', { value: _id ++ } );
|
||||
|
||||
/**
|
||||
* The name of the uniforms group.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* The buffer usage.
|
||||
*
|
||||
* @type {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)}
|
||||
* @default StaticDrawUsage
|
||||
*/
|
||||
this.usage = StaticDrawUsage;
|
||||
|
||||
/**
|
||||
* An array holding the uniforms.
|
||||
*
|
||||
* @type {Array<Uniform>}
|
||||
*/
|
||||
this.uniforms = [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given uniform to this uniforms group.
|
||||
*
|
||||
* @param {Uniform} uniform - The uniform to add.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
add( uniform ) {
|
||||
|
||||
this.uniforms.push( uniform );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given uniform from this uniforms group.
|
||||
*
|
||||
* @param {Uniform} uniform - The uniform to remove.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
remove( uniform ) {
|
||||
|
||||
const index = this.uniforms.indexOf( uniform );
|
||||
|
||||
if ( index !== - 1 ) this.uniforms.splice( index, 1 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of this uniforms group.
|
||||
*
|
||||
* @param {string} name - The name to set.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
setName( name ) {
|
||||
|
||||
this.name = name;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the usage of this uniforms group.
|
||||
*
|
||||
* @param {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)} value - The usage to set.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
setUsage( value ) {
|
||||
|
||||
this.usage = value;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever this instance is no longer used in your app.
|
||||
*
|
||||
* @fires Texture#dispose
|
||||
*/
|
||||
dispose() {
|
||||
|
||||
this.dispatchEvent( { type: 'dispose' } );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the values of the given uniforms group to this instance.
|
||||
*
|
||||
* @param {UniformsGroup} source - The uniforms group to copy.
|
||||
* @return {UniformsGroup} A reference to this uniforms group.
|
||||
*/
|
||||
copy( source ) {
|
||||
|
||||
this.name = source.name;
|
||||
this.usage = source.usage;
|
||||
|
||||
const uniformsSource = source.uniforms;
|
||||
|
||||
this.uniforms.length = 0;
|
||||
|
||||
for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {
|
||||
|
||||
const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];
|
||||
|
||||
for ( let j = 0; j < uniforms.length; j ++ ) {
|
||||
|
||||
this.uniforms.push( uniforms[ j ].clone() );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new uniforms group with copied values from this instance.
|
||||
*
|
||||
* @return {UniformsGroup} A clone of this instance.
|
||||
*/
|
||||
clone() {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { UniformsGroup };
|
||||
119
app/node_modules/three/src/extras/Controls.js
generated
vendored
Normal file
119
app/node_modules/three/src/extras/Controls.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
import { EventDispatcher } from '../core/EventDispatcher.js';
|
||||
|
||||
/**
|
||||
* Abstract base class for controls.
|
||||
*
|
||||
* @abstract
|
||||
* @augments EventDispatcher
|
||||
*/
|
||||
class Controls extends EventDispatcher {
|
||||
|
||||
/**
|
||||
* Constructs a new controls instance.
|
||||
*
|
||||
* @param {Object3D} object - The object that is managed by the controls.
|
||||
* @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
|
||||
*/
|
||||
constructor( object, domElement = null ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* The object that is managed by the controls.
|
||||
*
|
||||
* @type {Object3D}
|
||||
*/
|
||||
this.object = object;
|
||||
|
||||
/**
|
||||
* The HTML element used for event listeners.
|
||||
*
|
||||
* @type {?HTMLDOMElement}
|
||||
* @default null
|
||||
*/
|
||||
this.domElement = domElement;
|
||||
|
||||
/**
|
||||
* Whether the controls responds to user input or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
*/
|
||||
this.enabled = true;
|
||||
|
||||
/**
|
||||
* The internal state of the controls.
|
||||
*
|
||||
* @type {number}
|
||||
* @default -1
|
||||
*/
|
||||
this.state = - 1;
|
||||
|
||||
/**
|
||||
* This object defines the keyboard input of the controls.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.keys = {};
|
||||
|
||||
/**
|
||||
* This object defines what type of actions are assigned to the available mouse buttons.
|
||||
* It depends on the control implementation what kind of mouse buttons and actions are supported.
|
||||
*
|
||||
* @type {{LEFT: ?number, MIDDLE: ?number, RIGHT: ?number}}
|
||||
*/
|
||||
this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null };
|
||||
|
||||
/**
|
||||
* This object defines what type of actions are assigned to what kind of touch interaction.
|
||||
* It depends on the control implementation what kind of touch interaction and actions are supported.
|
||||
*
|
||||
* @type {{ONE: ?number, TWO: ?number}}
|
||||
*/
|
||||
this.touches = { ONE: null, TWO: null };
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects the controls to the DOM. This method has so called "side effects" since
|
||||
* it adds the module's event listeners to the DOM.
|
||||
*
|
||||
* @param {HTMLDOMElement} element - The DOM element to connect to.
|
||||
*/
|
||||
connect( element ) {
|
||||
|
||||
if ( element === undefined ) {
|
||||
|
||||
console.warn( 'THREE.Controls: connect() now requires an element.' ); // @deprecated, the warning can be removed with r185
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( this.domElement !== null ) this.disconnect();
|
||||
|
||||
this.domElement = element;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the controls from the DOM.
|
||||
*/
|
||||
disconnect() {}
|
||||
|
||||
/**
|
||||
* Call this method if you no longer want use to the controls. It frees all internal
|
||||
* resources and removes all event listeners.
|
||||
*/
|
||||
dispose() {}
|
||||
|
||||
/**
|
||||
* Controls should implement this method if they have to update their internal state
|
||||
* per simulation step.
|
||||
*
|
||||
* @param {number} [delta] - The time delta in seconds.
|
||||
*/
|
||||
update( /* delta */ ) {}
|
||||
|
||||
}
|
||||
|
||||
export { Controls };
|
||||
216
app/node_modules/three/src/extras/DataUtils.js
generated
vendored
Normal file
216
app/node_modules/three/src/extras/DataUtils.js
generated
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
import { clamp } from '../math/MathUtils.js';
|
||||
|
||||
// Fast Half Float Conversions, http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
|
||||
|
||||
const _tables = /*@__PURE__*/ _generateTables();
|
||||
|
||||
function _generateTables() {
|
||||
|
||||
// float32 to float16 helpers
|
||||
|
||||
const buffer = new ArrayBuffer( 4 );
|
||||
const floatView = new Float32Array( buffer );
|
||||
const uint32View = new Uint32Array( buffer );
|
||||
|
||||
const baseTable = new Uint32Array( 512 );
|
||||
const shiftTable = new Uint32Array( 512 );
|
||||
|
||||
for ( let i = 0; i < 256; ++ i ) {
|
||||
|
||||
const e = i - 127;
|
||||
|
||||
// very small number (0, -0)
|
||||
|
||||
if ( e < - 27 ) {
|
||||
|
||||
baseTable[ i ] = 0x0000;
|
||||
baseTable[ i | 0x100 ] = 0x8000;
|
||||
shiftTable[ i ] = 24;
|
||||
shiftTable[ i | 0x100 ] = 24;
|
||||
|
||||
// small number (denorm)
|
||||
|
||||
} else if ( e < - 14 ) {
|
||||
|
||||
baseTable[ i ] = 0x0400 >> ( - e - 14 );
|
||||
baseTable[ i | 0x100 ] = ( 0x0400 >> ( - e - 14 ) ) | 0x8000;
|
||||
shiftTable[ i ] = - e - 1;
|
||||
shiftTable[ i | 0x100 ] = - e - 1;
|
||||
|
||||
// normal number
|
||||
|
||||
} else if ( e <= 15 ) {
|
||||
|
||||
baseTable[ i ] = ( e + 15 ) << 10;
|
||||
baseTable[ i | 0x100 ] = ( ( e + 15 ) << 10 ) | 0x8000;
|
||||
shiftTable[ i ] = 13;
|
||||
shiftTable[ i | 0x100 ] = 13;
|
||||
|
||||
// large number (Infinity, -Infinity)
|
||||
|
||||
} else if ( e < 128 ) {
|
||||
|
||||
baseTable[ i ] = 0x7c00;
|
||||
baseTable[ i | 0x100 ] = 0xfc00;
|
||||
shiftTable[ i ] = 24;
|
||||
shiftTable[ i | 0x100 ] = 24;
|
||||
|
||||
// stay (NaN, Infinity, -Infinity)
|
||||
|
||||
} else {
|
||||
|
||||
baseTable[ i ] = 0x7c00;
|
||||
baseTable[ i | 0x100 ] = 0xfc00;
|
||||
shiftTable[ i ] = 13;
|
||||
shiftTable[ i | 0x100 ] = 13;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// float16 to float32 helpers
|
||||
|
||||
const mantissaTable = new Uint32Array( 2048 );
|
||||
const exponentTable = new Uint32Array( 64 );
|
||||
const offsetTable = new Uint32Array( 64 );
|
||||
|
||||
for ( let i = 1; i < 1024; ++ i ) {
|
||||
|
||||
let m = i << 13; // zero pad mantissa bits
|
||||
let e = 0; // zero exponent
|
||||
|
||||
// normalized
|
||||
while ( ( m & 0x00800000 ) === 0 ) {
|
||||
|
||||
m <<= 1;
|
||||
e -= 0x00800000; // decrement exponent
|
||||
|
||||
}
|
||||
|
||||
m &= ~ 0x00800000; // clear leading 1 bit
|
||||
e += 0x38800000; // adjust bias
|
||||
|
||||
mantissaTable[ i ] = m | e;
|
||||
|
||||
}
|
||||
|
||||
for ( let i = 1024; i < 2048; ++ i ) {
|
||||
|
||||
mantissaTable[ i ] = 0x38000000 + ( ( i - 1024 ) << 13 );
|
||||
|
||||
}
|
||||
|
||||
for ( let i = 1; i < 31; ++ i ) {
|
||||
|
||||
exponentTable[ i ] = i << 23;
|
||||
|
||||
}
|
||||
|
||||
exponentTable[ 31 ] = 0x47800000;
|
||||
exponentTable[ 32 ] = 0x80000000;
|
||||
|
||||
for ( let i = 33; i < 63; ++ i ) {
|
||||
|
||||
exponentTable[ i ] = 0x80000000 + ( ( i - 32 ) << 23 );
|
||||
|
||||
}
|
||||
|
||||
exponentTable[ 63 ] = 0xc7800000;
|
||||
|
||||
for ( let i = 1; i < 64; ++ i ) {
|
||||
|
||||
if ( i !== 32 ) {
|
||||
|
||||
offsetTable[ i ] = 1024;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
floatView: floatView,
|
||||
uint32View: uint32View,
|
||||
baseTable: baseTable,
|
||||
shiftTable: shiftTable,
|
||||
mantissaTable: mantissaTable,
|
||||
exponentTable: exponentTable,
|
||||
offsetTable: offsetTable
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a half precision floating point value (FP16) from the given single
|
||||
* precision floating point value (FP32).
|
||||
*
|
||||
* @param {number} val - A single precision floating point value.
|
||||
* @return {number} The FP16 value.
|
||||
*/
|
||||
function toHalfFloat( val ) {
|
||||
|
||||
if ( Math.abs( val ) > 65504 ) console.warn( 'THREE.DataUtils.toHalfFloat(): Value out of range.' );
|
||||
|
||||
val = clamp( val, - 65504, 65504 );
|
||||
|
||||
_tables.floatView[ 0 ] = val;
|
||||
const f = _tables.uint32View[ 0 ];
|
||||
const e = ( f >> 23 ) & 0x1ff;
|
||||
return _tables.baseTable[ e ] + ( ( f & 0x007fffff ) >> _tables.shiftTable[ e ] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single precision floating point value (FP32) from the given half
|
||||
* precision floating point value (FP16).
|
||||
*
|
||||
* @param {number} val - A half precision floating point value.
|
||||
* @return {number} The FP32 value.
|
||||
*/
|
||||
function fromHalfFloat( val ) {
|
||||
|
||||
const m = val >> 10;
|
||||
_tables.uint32View[ 0 ] = _tables.mantissaTable[ _tables.offsetTable[ m ] + ( val & 0x3ff ) ] + _tables.exponentTable[ m ];
|
||||
return _tables.floatView[ 0 ];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A class containing utility functions for data.
|
||||
*
|
||||
* @hideconstructor
|
||||
*/
|
||||
class DataUtils {
|
||||
|
||||
/**
|
||||
* Returns a half precision floating point value (FP16) from the given single
|
||||
* precision floating point value (FP32).
|
||||
*
|
||||
* @param {number} val - A single precision floating point value.
|
||||
* @return {number} The FP16 value.
|
||||
*/
|
||||
static toHalfFloat( val ) {
|
||||
|
||||
return toHalfFloat( val );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single precision floating point value (FP32) from the given half
|
||||
* precision floating point value (FP16).
|
||||
*
|
||||
* @param {number} val - A half precision floating point value.
|
||||
* @return {number} The FP32 value.
|
||||
*/
|
||||
static fromHalfFloat( val ) {
|
||||
|
||||
return fromHalfFloat( val );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export {
|
||||
toHalfFloat,
|
||||
fromHalfFloat,
|
||||
DataUtils
|
||||
};
|
||||
22
app/node_modules/three/src/extras/Earcut.js
generated
vendored
Normal file
22
app/node_modules/three/src/extras/Earcut.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import earcut from './lib/earcut.js';
|
||||
|
||||
class Earcut {
|
||||
|
||||
/**
|
||||
* Triangulates the given shape definition by returning an array of triangles.
|
||||
*
|
||||
* @param {Array<number>} data - An array with 2D points.
|
||||
* @param {Array<number>} holeIndices - An array with indices defining holes.
|
||||
* @param {number} [dim=2] - The number of coordinates per vertex in the input array.
|
||||
* @return {Array<number>} An array representing the triangulated faces. Each face is defined by three consecutive numbers
|
||||
* representing vertex indices.
|
||||
*/
|
||||
static triangulate( data, holeIndices, dim = 2 ) {
|
||||
|
||||
return earcut( data, holeIndices, dim );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Earcut };
|
||||
137
app/node_modules/three/src/extras/ImageUtils.js
generated
vendored
Normal file
137
app/node_modules/three/src/extras/ImageUtils.js
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
import { createElementNS } from '../utils.js';
|
||||
import { SRGBToLinear } from '../math/ColorManagement.js';
|
||||
|
||||
let _canvas;
|
||||
|
||||
/**
|
||||
* A class containing utility functions for images.
|
||||
*
|
||||
* @hideconstructor
|
||||
*/
|
||||
class ImageUtils {
|
||||
|
||||
/**
|
||||
* Returns a data URI containing a representation of the given image.
|
||||
*
|
||||
* @param {(HTMLImageElement|HTMLCanvasElement)} image - The image object.
|
||||
* @param {string} [type='image/png'] - Indicates the image format.
|
||||
* @return {string} The data URI.
|
||||
*/
|
||||
static getDataURL( image, type = 'image/png' ) {
|
||||
|
||||
if ( /^data:/i.test( image.src ) ) {
|
||||
|
||||
return image.src;
|
||||
|
||||
}
|
||||
|
||||
if ( typeof HTMLCanvasElement === 'undefined' ) {
|
||||
|
||||
return image.src;
|
||||
|
||||
}
|
||||
|
||||
let canvas;
|
||||
|
||||
if ( image instanceof HTMLCanvasElement ) {
|
||||
|
||||
canvas = image;
|
||||
|
||||
} else {
|
||||
|
||||
if ( _canvas === undefined ) _canvas = createElementNS( 'canvas' );
|
||||
|
||||
_canvas.width = image.width;
|
||||
_canvas.height = image.height;
|
||||
|
||||
const context = _canvas.getContext( '2d' );
|
||||
|
||||
if ( image instanceof ImageData ) {
|
||||
|
||||
context.putImageData( image, 0, 0 );
|
||||
|
||||
} else {
|
||||
|
||||
context.drawImage( image, 0, 0, image.width, image.height );
|
||||
|
||||
}
|
||||
|
||||
canvas = _canvas;
|
||||
|
||||
}
|
||||
|
||||
return canvas.toDataURL( type );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given sRGB image data to linear color space.
|
||||
*
|
||||
* @param {(HTMLImageElement|HTMLCanvasElement|ImageBitmap|Object)} image - The image object.
|
||||
* @return {HTMLCanvasElement|Object} The converted image.
|
||||
*/
|
||||
static sRGBToLinear( image ) {
|
||||
|
||||
if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
|
||||
( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
|
||||
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
|
||||
|
||||
const canvas = createElementNS( 'canvas' );
|
||||
|
||||
canvas.width = image.width;
|
||||
canvas.height = image.height;
|
||||
|
||||
const context = canvas.getContext( '2d' );
|
||||
context.drawImage( image, 0, 0, image.width, image.height );
|
||||
|
||||
const imageData = context.getImageData( 0, 0, image.width, image.height );
|
||||
const data = imageData.data;
|
||||
|
||||
for ( let i = 0; i < data.length; i ++ ) {
|
||||
|
||||
data[ i ] = SRGBToLinear( data[ i ] / 255 ) * 255;
|
||||
|
||||
}
|
||||
|
||||
context.putImageData( imageData, 0, 0 );
|
||||
|
||||
return canvas;
|
||||
|
||||
} else if ( image.data ) {
|
||||
|
||||
const data = image.data.slice( 0 );
|
||||
|
||||
for ( let i = 0; i < data.length; i ++ ) {
|
||||
|
||||
if ( data instanceof Uint8Array || data instanceof Uint8ClampedArray ) {
|
||||
|
||||
data[ i ] = Math.floor( SRGBToLinear( data[ i ] / 255 ) * 255 );
|
||||
|
||||
} else {
|
||||
|
||||
// assuming float
|
||||
|
||||
data[ i ] = SRGBToLinear( data[ i ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
data: data,
|
||||
width: image.width,
|
||||
height: image.height
|
||||
};
|
||||
|
||||
} else {
|
||||
|
||||
console.warn( 'THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.' );
|
||||
return image;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { ImageUtils };
|
||||
954
app/node_modules/three/src/extras/PMREMGenerator.js
generated
vendored
Normal file
954
app/node_modules/three/src/extras/PMREMGenerator.js
generated
vendored
Normal file
@@ -0,0 +1,954 @@
|
||||
import {
|
||||
CubeReflectionMapping,
|
||||
CubeRefractionMapping,
|
||||
CubeUVReflectionMapping,
|
||||
LinearFilter,
|
||||
NoToneMapping,
|
||||
NoBlending,
|
||||
RGBAFormat,
|
||||
HalfFloatType,
|
||||
BackSide,
|
||||
LinearSRGBColorSpace
|
||||
} from '../constants.js';
|
||||
|
||||
import { BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Mesh } from '../objects/Mesh.js';
|
||||
import { OrthographicCamera } from '../cameras/OrthographicCamera.js';
|
||||
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
|
||||
import { ShaderMaterial } from '../materials/ShaderMaterial.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Color } from '../math/Color.js';
|
||||
import { WebGLRenderTarget } from '../renderers/WebGLRenderTarget.js';
|
||||
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
|
||||
import { BoxGeometry } from '../geometries/BoxGeometry.js';
|
||||
|
||||
const LOD_MIN = 4;
|
||||
|
||||
// The standard deviations (radians) associated with the extra mips. These are
|
||||
// chosen to approximate a Trowbridge-Reitz distribution function times the
|
||||
// geometric shadowing function. These sigma values squared must match the
|
||||
// variance #defines in cube_uv_reflection_fragment.glsl.js.
|
||||
const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
|
||||
|
||||
// The maximum length of the blur for loop. Smaller sigmas will use fewer
|
||||
// samples and exit early, but not recompile the shader.
|
||||
const MAX_SAMPLES = 20;
|
||||
|
||||
const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
|
||||
const _clearColor = /*@__PURE__*/ new Color();
|
||||
let _oldTarget = null;
|
||||
let _oldActiveCubeFace = 0;
|
||||
let _oldActiveMipmapLevel = 0;
|
||||
let _oldXrEnabled = false;
|
||||
|
||||
// Golden Ratio
|
||||
const PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
|
||||
const INV_PHI = 1 / PHI;
|
||||
|
||||
// Vertices of a dodecahedron (except the opposites, which represent the
|
||||
// same axis), used as axis directions evenly spread on a sphere.
|
||||
const _axisDirections = [
|
||||
/*@__PURE__*/ new Vector3( - PHI, INV_PHI, 0 ),
|
||||
/*@__PURE__*/ new Vector3( PHI, INV_PHI, 0 ),
|
||||
/*@__PURE__*/ new Vector3( - INV_PHI, 0, PHI ),
|
||||
/*@__PURE__*/ new Vector3( INV_PHI, 0, PHI ),
|
||||
/*@__PURE__*/ new Vector3( 0, PHI, - INV_PHI ),
|
||||
/*@__PURE__*/ new Vector3( 0, PHI, INV_PHI ),
|
||||
/*@__PURE__*/ new Vector3( - 1, 1, - 1 ),
|
||||
/*@__PURE__*/ new Vector3( 1, 1, - 1 ),
|
||||
/*@__PURE__*/ new Vector3( - 1, 1, 1 ),
|
||||
/*@__PURE__*/ new Vector3( 1, 1, 1 ) ];
|
||||
|
||||
const _origin = /*@__PURE__*/ new Vector3();
|
||||
|
||||
/**
|
||||
* This class generates a Prefiltered, Mipmapped Radiance Environment Map
|
||||
* (PMREM) from a cubeMap environment texture. This allows different levels of
|
||||
* blur to be quickly accessed based on material roughness. It is packed into a
|
||||
* special CubeUV format that allows us to perform custom interpolation so that
|
||||
* we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
|
||||
* chain, it only goes down to the LOD_MIN level (above), and then creates extra
|
||||
* even more filtered 'mips' at the same LOD_MIN resolution, associated with
|
||||
* higher roughness levels. In this way we maintain resolution to smoothly
|
||||
* interpolate diffuse lighting while limiting sampling computation.
|
||||
*
|
||||
* Paper: Fast, Accurate Image-Based Lighting:
|
||||
* {@link https://drive.google.com/file/d/15y8r_UpKlU9SvV4ILb0C3qCPecS8pvLz/view}
|
||||
*/
|
||||
class PMREMGenerator {
|
||||
|
||||
/**
|
||||
* Constructs a new PMREM generator.
|
||||
*
|
||||
* @param {WebGLRenderer} renderer - The renderer.
|
||||
*/
|
||||
constructor( renderer ) {
|
||||
|
||||
this._renderer = renderer;
|
||||
this._pingPongRenderTarget = null;
|
||||
|
||||
this._lodMax = 0;
|
||||
this._cubeSize = 0;
|
||||
this._lodPlanes = [];
|
||||
this._sizeLods = [];
|
||||
this._sigmas = [];
|
||||
|
||||
this._blurMaterial = null;
|
||||
this._cubemapMaterial = null;
|
||||
this._equirectMaterial = null;
|
||||
|
||||
this._compileMaterial( this._blurMaterial );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a PMREM from a supplied Scene, which can be faster than using an
|
||||
* image if networking bandwidth is low. Optional sigma specifies a blur radius
|
||||
* in radians to be applied to the scene before PMREM generation. Optional near
|
||||
* and far planes ensure the scene is rendered in its entirety.
|
||||
*
|
||||
* @param {Scene} scene - The scene to be captured.
|
||||
* @param {number} [sigma=0] - The blur radius in radians.
|
||||
* @param {number} [near=0.1] - The near plane distance.
|
||||
* @param {number} [far=100] - The far plane distance.
|
||||
* @param {Object} [options={}] - The configuration options.
|
||||
* @param {number} [options.size=256] - The texture size of the PMREM.
|
||||
* @param {Vector3} [options.renderTarget=origin] - The position of the internal cube camera that renders the scene.
|
||||
* @return {WebGLRenderTarget} The resulting PMREM.
|
||||
*/
|
||||
fromScene( scene, sigma = 0, near = 0.1, far = 100, options = {} ) {
|
||||
|
||||
const {
|
||||
size = 256,
|
||||
position = _origin,
|
||||
} = options;
|
||||
|
||||
_oldTarget = this._renderer.getRenderTarget();
|
||||
_oldActiveCubeFace = this._renderer.getActiveCubeFace();
|
||||
_oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();
|
||||
_oldXrEnabled = this._renderer.xr.enabled;
|
||||
|
||||
this._renderer.xr.enabled = false;
|
||||
|
||||
this._setSize( size );
|
||||
|
||||
const cubeUVRenderTarget = this._allocateTargets();
|
||||
cubeUVRenderTarget.depthBuffer = true;
|
||||
|
||||
this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget, position );
|
||||
|
||||
if ( sigma > 0 ) {
|
||||
|
||||
this._blur( cubeUVRenderTarget, 0, 0, sigma );
|
||||
|
||||
}
|
||||
|
||||
this._applyPMREM( cubeUVRenderTarget );
|
||||
this._cleanup( cubeUVRenderTarget );
|
||||
|
||||
return cubeUVRenderTarget;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a PMREM from an equirectangular texture, which can be either LDR
|
||||
* or HDR. The ideal input image size is 1k (1024 x 512),
|
||||
* as this matches best with the 256 x 256 cubemap output.
|
||||
*
|
||||
* @param {Texture} equirectangular - The equirectangular texture to be converted.
|
||||
* @param {?WebGLRenderTarget} [renderTarget=null] - The render target to use.
|
||||
* @return {WebGLRenderTarget} The resulting PMREM.
|
||||
*/
|
||||
fromEquirectangular( equirectangular, renderTarget = null ) {
|
||||
|
||||
return this._fromTexture( equirectangular, renderTarget );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a PMREM from an cubemap texture, which can be either LDR
|
||||
* or HDR. The ideal input cube size is 256 x 256,
|
||||
* as this matches best with the 256 x 256 cubemap output.
|
||||
*
|
||||
* @param {Texture} cubemap - The cubemap texture to be converted.
|
||||
* @param {?WebGLRenderTarget} [renderTarget=null] - The render target to use.
|
||||
* @return {WebGLRenderTarget} The resulting PMREM.
|
||||
*/
|
||||
fromCubemap( cubemap, renderTarget = null ) {
|
||||
|
||||
return this._fromTexture( cubemap, renderTarget );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
|
||||
* your texture's network fetch for increased concurrency.
|
||||
*/
|
||||
compileCubemapShader() {
|
||||
|
||||
if ( this._cubemapMaterial === null ) {
|
||||
|
||||
this._cubemapMaterial = _getCubemapMaterial();
|
||||
this._compileMaterial( this._cubemapMaterial );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
|
||||
* your texture's network fetch for increased concurrency.
|
||||
*/
|
||||
compileEquirectangularShader() {
|
||||
|
||||
if ( this._equirectMaterial === null ) {
|
||||
|
||||
this._equirectMaterial = _getEquirectMaterial();
|
||||
this._compileMaterial( this._equirectMaterial );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
|
||||
* so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
|
||||
* one of them will cause any others to also become unusable.
|
||||
*/
|
||||
dispose() {
|
||||
|
||||
this._dispose();
|
||||
|
||||
if ( this._cubemapMaterial !== null ) this._cubemapMaterial.dispose();
|
||||
if ( this._equirectMaterial !== null ) this._equirectMaterial.dispose();
|
||||
|
||||
}
|
||||
|
||||
// private interface
|
||||
|
||||
_setSize( cubeSize ) {
|
||||
|
||||
this._lodMax = Math.floor( Math.log2( cubeSize ) );
|
||||
this._cubeSize = Math.pow( 2, this._lodMax );
|
||||
|
||||
}
|
||||
|
||||
_dispose() {
|
||||
|
||||
if ( this._blurMaterial !== null ) this._blurMaterial.dispose();
|
||||
|
||||
if ( this._pingPongRenderTarget !== null ) this._pingPongRenderTarget.dispose();
|
||||
|
||||
for ( let i = 0; i < this._lodPlanes.length; i ++ ) {
|
||||
|
||||
this._lodPlanes[ i ].dispose();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_cleanup( outputTarget ) {
|
||||
|
||||
this._renderer.setRenderTarget( _oldTarget, _oldActiveCubeFace, _oldActiveMipmapLevel );
|
||||
this._renderer.xr.enabled = _oldXrEnabled;
|
||||
|
||||
outputTarget.scissorTest = false;
|
||||
_setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height );
|
||||
|
||||
}
|
||||
|
||||
_fromTexture( texture, renderTarget ) {
|
||||
|
||||
if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
|
||||
|
||||
this._setSize( texture.image.length === 0 ? 16 : ( texture.image[ 0 ].width || texture.image[ 0 ].image.width ) );
|
||||
|
||||
} else { // Equirectangular
|
||||
|
||||
this._setSize( texture.image.width / 4 );
|
||||
|
||||
}
|
||||
|
||||
_oldTarget = this._renderer.getRenderTarget();
|
||||
_oldActiveCubeFace = this._renderer.getActiveCubeFace();
|
||||
_oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();
|
||||
_oldXrEnabled = this._renderer.xr.enabled;
|
||||
|
||||
this._renderer.xr.enabled = false;
|
||||
|
||||
const cubeUVRenderTarget = renderTarget || this._allocateTargets();
|
||||
this._textureToCubeUV( texture, cubeUVRenderTarget );
|
||||
this._applyPMREM( cubeUVRenderTarget );
|
||||
this._cleanup( cubeUVRenderTarget );
|
||||
|
||||
return cubeUVRenderTarget;
|
||||
|
||||
}
|
||||
|
||||
_allocateTargets() {
|
||||
|
||||
const width = 3 * Math.max( this._cubeSize, 16 * 7 );
|
||||
const height = 4 * this._cubeSize;
|
||||
|
||||
const params = {
|
||||
magFilter: LinearFilter,
|
||||
minFilter: LinearFilter,
|
||||
generateMipmaps: false,
|
||||
type: HalfFloatType,
|
||||
format: RGBAFormat,
|
||||
colorSpace: LinearSRGBColorSpace,
|
||||
depthBuffer: false
|
||||
};
|
||||
|
||||
const cubeUVRenderTarget = _createRenderTarget( width, height, params );
|
||||
|
||||
if ( this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width || this._pingPongRenderTarget.height !== height ) {
|
||||
|
||||
if ( this._pingPongRenderTarget !== null ) {
|
||||
|
||||
this._dispose();
|
||||
|
||||
}
|
||||
|
||||
this._pingPongRenderTarget = _createRenderTarget( width, height, params );
|
||||
|
||||
const { _lodMax } = this;
|
||||
( { sizeLods: this._sizeLods, lodPlanes: this._lodPlanes, sigmas: this._sigmas } = _createPlanes( _lodMax ) );
|
||||
|
||||
this._blurMaterial = _getBlurShader( _lodMax, width, height );
|
||||
|
||||
}
|
||||
|
||||
return cubeUVRenderTarget;
|
||||
|
||||
}
|
||||
|
||||
_compileMaterial( material ) {
|
||||
|
||||
const tmpMesh = new Mesh( this._lodPlanes[ 0 ], material );
|
||||
this._renderer.compile( tmpMesh, _flatCamera );
|
||||
|
||||
}
|
||||
|
||||
_sceneToCubeUV( scene, near, far, cubeUVRenderTarget, position ) {
|
||||
|
||||
const fov = 90;
|
||||
const aspect = 1;
|
||||
const cubeCamera = new PerspectiveCamera( fov, aspect, near, far );
|
||||
const upSign = [ 1, - 1, 1, 1, 1, 1 ];
|
||||
const forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ];
|
||||
const renderer = this._renderer;
|
||||
|
||||
const originalAutoClear = renderer.autoClear;
|
||||
const toneMapping = renderer.toneMapping;
|
||||
renderer.getClearColor( _clearColor );
|
||||
|
||||
renderer.toneMapping = NoToneMapping;
|
||||
renderer.autoClear = false;
|
||||
|
||||
const backgroundMaterial = new MeshBasicMaterial( {
|
||||
name: 'PMREM.Background',
|
||||
side: BackSide,
|
||||
depthWrite: false,
|
||||
depthTest: false,
|
||||
} );
|
||||
|
||||
const backgroundBox = new Mesh( new BoxGeometry(), backgroundMaterial );
|
||||
|
||||
let useSolidColor = false;
|
||||
const background = scene.background;
|
||||
|
||||
if ( background ) {
|
||||
|
||||
if ( background.isColor ) {
|
||||
|
||||
backgroundMaterial.color.copy( background );
|
||||
scene.background = null;
|
||||
useSolidColor = true;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
backgroundMaterial.color.copy( _clearColor );
|
||||
useSolidColor = true;
|
||||
|
||||
}
|
||||
|
||||
for ( let i = 0; i < 6; i ++ ) {
|
||||
|
||||
const col = i % 3;
|
||||
|
||||
if ( col === 0 ) {
|
||||
|
||||
cubeCamera.up.set( 0, upSign[ i ], 0 );
|
||||
cubeCamera.position.set( position.x, position.y, position.z );
|
||||
cubeCamera.lookAt( position.x + forwardSign[ i ], position.y, position.z );
|
||||
|
||||
} else if ( col === 1 ) {
|
||||
|
||||
cubeCamera.up.set( 0, 0, upSign[ i ] );
|
||||
cubeCamera.position.set( position.x, position.y, position.z );
|
||||
cubeCamera.lookAt( position.x, position.y + forwardSign[ i ], position.z );
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
cubeCamera.up.set( 0, upSign[ i ], 0 );
|
||||
cubeCamera.position.set( position.x, position.y, position.z );
|
||||
cubeCamera.lookAt( position.x, position.y, position.z + forwardSign[ i ] );
|
||||
|
||||
}
|
||||
|
||||
const size = this._cubeSize;
|
||||
|
||||
_setViewport( cubeUVRenderTarget, col * size, i > 2 ? size : 0, size, size );
|
||||
|
||||
renderer.setRenderTarget( cubeUVRenderTarget );
|
||||
|
||||
if ( useSolidColor ) {
|
||||
|
||||
renderer.render( backgroundBox, cubeCamera );
|
||||
|
||||
}
|
||||
|
||||
renderer.render( scene, cubeCamera );
|
||||
|
||||
}
|
||||
|
||||
backgroundBox.geometry.dispose();
|
||||
backgroundBox.material.dispose();
|
||||
|
||||
renderer.toneMapping = toneMapping;
|
||||
renderer.autoClear = originalAutoClear;
|
||||
scene.background = background;
|
||||
|
||||
}
|
||||
|
||||
_textureToCubeUV( texture, cubeUVRenderTarget ) {
|
||||
|
||||
const renderer = this._renderer;
|
||||
|
||||
const isCubeTexture = ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping );
|
||||
|
||||
if ( isCubeTexture ) {
|
||||
|
||||
if ( this._cubemapMaterial === null ) {
|
||||
|
||||
this._cubemapMaterial = _getCubemapMaterial();
|
||||
|
||||
}
|
||||
|
||||
this._cubemapMaterial.uniforms.flipEnvMap.value = ( texture.isRenderTargetTexture === false ) ? - 1 : 1;
|
||||
|
||||
} else {
|
||||
|
||||
if ( this._equirectMaterial === null ) {
|
||||
|
||||
this._equirectMaterial = _getEquirectMaterial();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const material = isCubeTexture ? this._cubemapMaterial : this._equirectMaterial;
|
||||
const mesh = new Mesh( this._lodPlanes[ 0 ], material );
|
||||
|
||||
const uniforms = material.uniforms;
|
||||
|
||||
uniforms[ 'envMap' ].value = texture;
|
||||
|
||||
const size = this._cubeSize;
|
||||
|
||||
_setViewport( cubeUVRenderTarget, 0, 0, 3 * size, 2 * size );
|
||||
|
||||
renderer.setRenderTarget( cubeUVRenderTarget );
|
||||
renderer.render( mesh, _flatCamera );
|
||||
|
||||
}
|
||||
|
||||
_applyPMREM( cubeUVRenderTarget ) {
|
||||
|
||||
const renderer = this._renderer;
|
||||
const autoClear = renderer.autoClear;
|
||||
renderer.autoClear = false;
|
||||
const n = this._lodPlanes.length;
|
||||
|
||||
for ( let i = 1; i < n; i ++ ) {
|
||||
|
||||
const sigma = Math.sqrt( this._sigmas[ i ] * this._sigmas[ i ] - this._sigmas[ i - 1 ] * this._sigmas[ i - 1 ] );
|
||||
|
||||
const poleAxis = _axisDirections[ ( n - i - 1 ) % _axisDirections.length ];
|
||||
|
||||
this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis );
|
||||
|
||||
}
|
||||
|
||||
renderer.autoClear = autoClear;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a two-pass Gaussian blur for a cubemap. Normally this is done
|
||||
* vertically and horizontally, but this breaks down on a cube. Here we apply
|
||||
* the blur latitudinally (around the poles), and then longitudinally (towards
|
||||
* the poles) to approximate the orthogonally-separable blur. It is least
|
||||
* accurate at the poles, but still does a decent job.
|
||||
*
|
||||
* @private
|
||||
* @param {WebGLRenderTarget} cubeUVRenderTarget
|
||||
* @param {number} lodIn
|
||||
* @param {number} lodOut
|
||||
* @param {number} sigma
|
||||
* @param {Vector3} [poleAxis]
|
||||
*/
|
||||
_blur( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) {
|
||||
|
||||
const pingPongRenderTarget = this._pingPongRenderTarget;
|
||||
|
||||
this._halfBlur(
|
||||
cubeUVRenderTarget,
|
||||
pingPongRenderTarget,
|
||||
lodIn,
|
||||
lodOut,
|
||||
sigma,
|
||||
'latitudinal',
|
||||
poleAxis );
|
||||
|
||||
this._halfBlur(
|
||||
pingPongRenderTarget,
|
||||
cubeUVRenderTarget,
|
||||
lodOut,
|
||||
lodOut,
|
||||
sigma,
|
||||
'longitudinal',
|
||||
poleAxis );
|
||||
|
||||
}
|
||||
|
||||
_halfBlur( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) {
|
||||
|
||||
const renderer = this._renderer;
|
||||
const blurMaterial = this._blurMaterial;
|
||||
|
||||
if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
|
||||
|
||||
console.error(
|
||||
'blur direction must be either latitudinal or longitudinal!' );
|
||||
|
||||
}
|
||||
|
||||
// Number of standard deviations at which to cut off the discrete approximation.
|
||||
const STANDARD_DEVIATIONS = 3;
|
||||
|
||||
const blurMesh = new Mesh( this._lodPlanes[ lodOut ], blurMaterial );
|
||||
const blurUniforms = blurMaterial.uniforms;
|
||||
|
||||
const pixels = this._sizeLods[ lodIn ] - 1;
|
||||
const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
|
||||
const sigmaPixels = sigmaRadians / radiansPerPixel;
|
||||
const samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES;
|
||||
|
||||
if ( samples > MAX_SAMPLES ) {
|
||||
|
||||
console.warn( `sigmaRadians, ${
|
||||
sigmaRadians}, is too large and will clip, as it requested ${
|
||||
samples} samples when the maximum is set to ${MAX_SAMPLES}` );
|
||||
|
||||
}
|
||||
|
||||
const weights = [];
|
||||
let sum = 0;
|
||||
|
||||
for ( let i = 0; i < MAX_SAMPLES; ++ i ) {
|
||||
|
||||
const x = i / sigmaPixels;
|
||||
const weight = Math.exp( - x * x / 2 );
|
||||
weights.push( weight );
|
||||
|
||||
if ( i === 0 ) {
|
||||
|
||||
sum += weight;
|
||||
|
||||
} else if ( i < samples ) {
|
||||
|
||||
sum += 2 * weight;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for ( let i = 0; i < weights.length; i ++ ) {
|
||||
|
||||
weights[ i ] = weights[ i ] / sum;
|
||||
|
||||
}
|
||||
|
||||
blurUniforms[ 'envMap' ].value = targetIn.texture;
|
||||
blurUniforms[ 'samples' ].value = samples;
|
||||
blurUniforms[ 'weights' ].value = weights;
|
||||
blurUniforms[ 'latitudinal' ].value = direction === 'latitudinal';
|
||||
|
||||
if ( poleAxis ) {
|
||||
|
||||
blurUniforms[ 'poleAxis' ].value = poleAxis;
|
||||
|
||||
}
|
||||
|
||||
const { _lodMax } = this;
|
||||
blurUniforms[ 'dTheta' ].value = radiansPerPixel;
|
||||
blurUniforms[ 'mipInt' ].value = _lodMax - lodIn;
|
||||
|
||||
const outputSize = this._sizeLods[ lodOut ];
|
||||
const x = 3 * outputSize * ( lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0 );
|
||||
const y = 4 * ( this._cubeSize - outputSize );
|
||||
|
||||
_setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize );
|
||||
renderer.setRenderTarget( targetOut );
|
||||
renderer.render( blurMesh, _flatCamera );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function _createPlanes( lodMax ) {
|
||||
|
||||
const lodPlanes = [];
|
||||
const sizeLods = [];
|
||||
const sigmas = [];
|
||||
|
||||
let lod = lodMax;
|
||||
|
||||
const totalLods = lodMax - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
|
||||
|
||||
for ( let i = 0; i < totalLods; i ++ ) {
|
||||
|
||||
const sizeLod = Math.pow( 2, lod );
|
||||
sizeLods.push( sizeLod );
|
||||
let sigma = 1.0 / sizeLod;
|
||||
|
||||
if ( i > lodMax - LOD_MIN ) {
|
||||
|
||||
sigma = EXTRA_LOD_SIGMA[ i - lodMax + LOD_MIN - 1 ];
|
||||
|
||||
} else if ( i === 0 ) {
|
||||
|
||||
sigma = 0;
|
||||
|
||||
}
|
||||
|
||||
sigmas.push( sigma );
|
||||
|
||||
const texelSize = 1.0 / ( sizeLod - 2 );
|
||||
const min = - texelSize;
|
||||
const max = 1 + texelSize;
|
||||
const uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ];
|
||||
|
||||
const cubeFaces = 6;
|
||||
const vertices = 6;
|
||||
const positionSize = 3;
|
||||
const uvSize = 2;
|
||||
const faceIndexSize = 1;
|
||||
|
||||
const position = new Float32Array( positionSize * vertices * cubeFaces );
|
||||
const uv = new Float32Array( uvSize * vertices * cubeFaces );
|
||||
const faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces );
|
||||
|
||||
for ( let face = 0; face < cubeFaces; face ++ ) {
|
||||
|
||||
const x = ( face % 3 ) * 2 / 3 - 1;
|
||||
const y = face > 2 ? 0 : - 1;
|
||||
const coordinates = [
|
||||
x, y, 0,
|
||||
x + 2 / 3, y, 0,
|
||||
x + 2 / 3, y + 1, 0,
|
||||
x, y, 0,
|
||||
x + 2 / 3, y + 1, 0,
|
||||
x, y + 1, 0
|
||||
];
|
||||
position.set( coordinates, positionSize * vertices * face );
|
||||
uv.set( uv1, uvSize * vertices * face );
|
||||
const fill = [ face, face, face, face, face, face ];
|
||||
faceIndex.set( fill, faceIndexSize * vertices * face );
|
||||
|
||||
}
|
||||
|
||||
const planes = new BufferGeometry();
|
||||
planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) );
|
||||
planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) );
|
||||
planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) );
|
||||
lodPlanes.push( planes );
|
||||
|
||||
if ( lod > LOD_MIN ) {
|
||||
|
||||
lod --;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return { lodPlanes, sizeLods, sigmas };
|
||||
|
||||
}
|
||||
|
||||
function _createRenderTarget( width, height, params ) {
|
||||
|
||||
const cubeUVRenderTarget = new WebGLRenderTarget( width, height, params );
|
||||
cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
|
||||
cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
|
||||
cubeUVRenderTarget.scissorTest = true;
|
||||
return cubeUVRenderTarget;
|
||||
|
||||
}
|
||||
|
||||
function _setViewport( target, x, y, width, height ) {
|
||||
|
||||
target.viewport.set( x, y, width, height );
|
||||
target.scissor.set( x, y, width, height );
|
||||
|
||||
}
|
||||
|
||||
function _getBlurShader( lodMax, width, height ) {
|
||||
|
||||
const weights = new Float32Array( MAX_SAMPLES );
|
||||
const poleAxis = new Vector3( 0, 1, 0 );
|
||||
const shaderMaterial = new ShaderMaterial( {
|
||||
|
||||
name: 'SphericalGaussianBlur',
|
||||
|
||||
defines: {
|
||||
'n': MAX_SAMPLES,
|
||||
'CUBEUV_TEXEL_WIDTH': 1.0 / width,
|
||||
'CUBEUV_TEXEL_HEIGHT': 1.0 / height,
|
||||
'CUBEUV_MAX_MIP': `${lodMax}.0`,
|
||||
},
|
||||
|
||||
uniforms: {
|
||||
'envMap': { value: null },
|
||||
'samples': { value: 1 },
|
||||
'weights': { value: weights },
|
||||
'latitudinal': { value: false },
|
||||
'dTheta': { value: 0 },
|
||||
'mipInt': { value: 0 },
|
||||
'poleAxis': { value: poleAxis }
|
||||
},
|
||||
|
||||
vertexShader: _getCommonVertexShader(),
|
||||
|
||||
fragmentShader: /* glsl */`
|
||||
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
|
||||
varying vec3 vOutputDirection;
|
||||
|
||||
uniform sampler2D envMap;
|
||||
uniform int samples;
|
||||
uniform float weights[ n ];
|
||||
uniform bool latitudinal;
|
||||
uniform float dTheta;
|
||||
uniform float mipInt;
|
||||
uniform vec3 poleAxis;
|
||||
|
||||
#define ENVMAP_TYPE_CUBE_UV
|
||||
#include <cube_uv_reflection_fragment>
|
||||
|
||||
vec3 getSample( float theta, vec3 axis ) {
|
||||
|
||||
float cosTheta = cos( theta );
|
||||
// Rodrigues' axis-angle rotation
|
||||
vec3 sampleDirection = vOutputDirection * cosTheta
|
||||
+ cross( axis, vOutputDirection ) * sin( theta )
|
||||
+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
|
||||
|
||||
return bilinearCubeUV( envMap, sampleDirection, mipInt );
|
||||
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
|
||||
|
||||
if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
|
||||
|
||||
axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
|
||||
|
||||
}
|
||||
|
||||
axis = normalize( axis );
|
||||
|
||||
gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
|
||||
gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
|
||||
|
||||
for ( int i = 1; i < n; i++ ) {
|
||||
|
||||
if ( i >= samples ) {
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
float theta = dTheta * float( i );
|
||||
gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
|
||||
gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
`,
|
||||
|
||||
blending: NoBlending,
|
||||
depthTest: false,
|
||||
depthWrite: false
|
||||
|
||||
} );
|
||||
|
||||
return shaderMaterial;
|
||||
|
||||
}
|
||||
|
||||
function _getEquirectMaterial() {
|
||||
|
||||
return new ShaderMaterial( {
|
||||
|
||||
name: 'EquirectangularToCubeUV',
|
||||
|
||||
uniforms: {
|
||||
'envMap': { value: null }
|
||||
},
|
||||
|
||||
vertexShader: _getCommonVertexShader(),
|
||||
|
||||
fragmentShader: /* glsl */`
|
||||
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
|
||||
varying vec3 vOutputDirection;
|
||||
|
||||
uniform sampler2D envMap;
|
||||
|
||||
#include <common>
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 outputDirection = normalize( vOutputDirection );
|
||||
vec2 uv = equirectUv( outputDirection );
|
||||
|
||||
gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );
|
||||
|
||||
}
|
||||
`,
|
||||
|
||||
blending: NoBlending,
|
||||
depthTest: false,
|
||||
depthWrite: false
|
||||
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
function _getCubemapMaterial() {
|
||||
|
||||
return new ShaderMaterial( {
|
||||
|
||||
name: 'CubemapToCubeUV',
|
||||
|
||||
uniforms: {
|
||||
'envMap': { value: null },
|
||||
'flipEnvMap': { value: - 1 }
|
||||
},
|
||||
|
||||
vertexShader: _getCommonVertexShader(),
|
||||
|
||||
fragmentShader: /* glsl */`
|
||||
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
|
||||
uniform float flipEnvMap;
|
||||
|
||||
varying vec3 vOutputDirection;
|
||||
|
||||
uniform samplerCube envMap;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );
|
||||
|
||||
}
|
||||
`,
|
||||
|
||||
blending: NoBlending,
|
||||
depthTest: false,
|
||||
depthWrite: false
|
||||
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
function _getCommonVertexShader() {
|
||||
|
||||
return /* glsl */`
|
||||
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
|
||||
attribute float faceIndex;
|
||||
|
||||
varying vec3 vOutputDirection;
|
||||
|
||||
// RH coordinate system; PMREM face-indexing convention
|
||||
vec3 getDirection( vec2 uv, float face ) {
|
||||
|
||||
uv = 2.0 * uv - 1.0;
|
||||
|
||||
vec3 direction = vec3( uv, 1.0 );
|
||||
|
||||
if ( face == 0.0 ) {
|
||||
|
||||
direction = direction.zyx; // ( 1, v, u ) pos x
|
||||
|
||||
} else if ( face == 1.0 ) {
|
||||
|
||||
direction = direction.xzy;
|
||||
direction.xz *= -1.0; // ( -u, 1, -v ) pos y
|
||||
|
||||
} else if ( face == 2.0 ) {
|
||||
|
||||
direction.x *= -1.0; // ( -u, v, 1 ) pos z
|
||||
|
||||
} else if ( face == 3.0 ) {
|
||||
|
||||
direction = direction.zyx;
|
||||
direction.xz *= -1.0; // ( -1, v, -u ) neg x
|
||||
|
||||
} else if ( face == 4.0 ) {
|
||||
|
||||
direction = direction.xzy;
|
||||
direction.xy *= -1.0; // ( -u, -1, v ) neg y
|
||||
|
||||
} else if ( face == 5.0 ) {
|
||||
|
||||
direction.z *= -1.0; // ( u, v, -1 ) neg z
|
||||
|
||||
}
|
||||
|
||||
return direction;
|
||||
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
vOutputDirection = getDirection( uv, faceIndex );
|
||||
gl_Position = vec4( position, 1.0 );
|
||||
|
||||
}
|
||||
`;
|
||||
|
||||
}
|
||||
|
||||
export { PMREMGenerator };
|
||||
114
app/node_modules/three/src/extras/ShapeUtils.js
generated
vendored
Normal file
114
app/node_modules/three/src/extras/ShapeUtils.js
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
import { Earcut } from './Earcut.js';
|
||||
|
||||
/**
|
||||
* A class containing utility functions for shapes.
|
||||
*
|
||||
* @hideconstructor
|
||||
*/
|
||||
class ShapeUtils {
|
||||
|
||||
/**
|
||||
* Calculate area of a ( 2D ) contour polygon.
|
||||
*
|
||||
* @param {Array<Vector2>} contour - An array of 2D points.
|
||||
* @return {number} The area.
|
||||
*/
|
||||
static area( contour ) {
|
||||
|
||||
const n = contour.length;
|
||||
let a = 0.0;
|
||||
|
||||
for ( let 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the given contour uses a clockwise winding order.
|
||||
*
|
||||
* @param {Array<Vector2>} pts - An array of 2D points defining a polygon.
|
||||
* @return {boolean} Whether the given contour uses a clockwise winding order or not.
|
||||
*/
|
||||
static isClockWise( pts ) {
|
||||
|
||||
return ShapeUtils.area( pts ) < 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Triangulates the given shape definition.
|
||||
*
|
||||
* @param {Array<Vector2>} contour - An array of 2D points defining the contour.
|
||||
* @param {Array<Array<Vector2>>} holes - An array that holds arrays of 2D points defining the holes.
|
||||
* @return {Array<Array<number>>} An array that holds for each face definition an array with three indices.
|
||||
*/
|
||||
static triangulateShape( contour, holes ) {
|
||||
|
||||
const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
|
||||
const holeIndices = []; // array of hole indices
|
||||
const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
|
||||
|
||||
removeDupEndPts( contour );
|
||||
addContour( vertices, contour );
|
||||
|
||||
//
|
||||
|
||||
let holeIndex = contour.length;
|
||||
|
||||
holes.forEach( removeDupEndPts );
|
||||
|
||||
for ( let i = 0; i < holes.length; i ++ ) {
|
||||
|
||||
holeIndices.push( holeIndex );
|
||||
holeIndex += holes[ i ].length;
|
||||
addContour( vertices, holes[ i ] );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
const triangles = Earcut.triangulate( vertices, holeIndices );
|
||||
|
||||
//
|
||||
|
||||
for ( let i = 0; i < triangles.length; i += 3 ) {
|
||||
|
||||
faces.push( triangles.slice( i, i + 3 ) );
|
||||
|
||||
}
|
||||
|
||||
return faces;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function removeDupEndPts( points ) {
|
||||
|
||||
const l = points.length;
|
||||
|
||||
if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
|
||||
|
||||
points.pop();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function addContour( vertices, contour ) {
|
||||
|
||||
for ( let i = 0; i < contour.length; i ++ ) {
|
||||
|
||||
vertices.push( contour[ i ].x );
|
||||
vertices.push( contour[ i ].y );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { ShapeUtils };
|
||||
292
app/node_modules/three/src/extras/TextureUtils.js
generated
vendored
Normal file
292
app/node_modules/three/src/extras/TextureUtils.js
generated
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
import { AlphaFormat, RedFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBFormat, RGBAFormat, RGBAIntegerFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, UnsignedByteType, ByteType, UnsignedShortType, ShortType, HalfFloatType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedIntType, IntType, FloatType, UnsignedInt5999Type } from '../constants.js';
|
||||
|
||||
/**
|
||||
* Scales the texture as large as possible within its surface without cropping
|
||||
* or stretching the texture. The method preserves the original aspect ratio of
|
||||
* the texture. Akin to CSS `object-fit: contain`
|
||||
*
|
||||
* @param {Texture} texture - The texture.
|
||||
* @param {number} aspect - The texture's aspect ratio.
|
||||
* @return {Texture} The updated texture.
|
||||
*/
|
||||
function contain( texture, aspect ) {
|
||||
|
||||
const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
|
||||
|
||||
if ( imageAspect > aspect ) {
|
||||
|
||||
texture.repeat.x = 1;
|
||||
texture.repeat.y = imageAspect / aspect;
|
||||
|
||||
texture.offset.x = 0;
|
||||
texture.offset.y = ( 1 - texture.repeat.y ) / 2;
|
||||
|
||||
} else {
|
||||
|
||||
texture.repeat.x = aspect / imageAspect;
|
||||
texture.repeat.y = 1;
|
||||
|
||||
texture.offset.x = ( 1 - texture.repeat.x ) / 2;
|
||||
texture.offset.y = 0;
|
||||
|
||||
}
|
||||
|
||||
return texture;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales the texture to the smallest possible size to fill the surface, leaving
|
||||
* no empty space. The method preserves the original aspect ratio of the texture.
|
||||
* Akin to CSS `object-fit: cover`.
|
||||
*
|
||||
* @param {Texture} texture - The texture.
|
||||
* @param {number} aspect - The texture's aspect ratio.
|
||||
* @return {Texture} The updated texture.
|
||||
*/
|
||||
function cover( texture, aspect ) {
|
||||
|
||||
const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
|
||||
|
||||
if ( imageAspect > aspect ) {
|
||||
|
||||
texture.repeat.x = aspect / imageAspect;
|
||||
texture.repeat.y = 1;
|
||||
|
||||
texture.offset.x = ( 1 - texture.repeat.x ) / 2;
|
||||
texture.offset.y = 0;
|
||||
|
||||
} else {
|
||||
|
||||
texture.repeat.x = 1;
|
||||
texture.repeat.y = imageAspect / aspect;
|
||||
|
||||
texture.offset.x = 0;
|
||||
texture.offset.y = ( 1 - texture.repeat.y ) / 2;
|
||||
|
||||
}
|
||||
|
||||
return texture;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the texture to the default transformation. Akin to CSS `object-fit: fill`.
|
||||
*
|
||||
* @param {Texture} texture - The texture.
|
||||
* @return {Texture} The updated texture.
|
||||
*/
|
||||
function fill( texture ) {
|
||||
|
||||
texture.repeat.x = 1;
|
||||
texture.repeat.y = 1;
|
||||
|
||||
texture.offset.x = 0;
|
||||
texture.offset.y = 0;
|
||||
|
||||
return texture;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines how many bytes must be used to represent the texture.
|
||||
*
|
||||
* @param {number} width - The width of the texture.
|
||||
* @param {number} height - The height of the texture.
|
||||
* @param {number} format - The texture's format.
|
||||
* @param {number} type - The texture's type.
|
||||
* @return {number} The byte length.
|
||||
*/
|
||||
function getByteLength( width, height, format, type ) {
|
||||
|
||||
const typeByteLength = getTextureTypeByteLength( type );
|
||||
|
||||
switch ( format ) {
|
||||
|
||||
// https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml
|
||||
case AlphaFormat:
|
||||
return width * height;
|
||||
case RedFormat:
|
||||
return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
|
||||
case RedIntegerFormat:
|
||||
return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
|
||||
case RGFormat:
|
||||
return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
|
||||
case RGIntegerFormat:
|
||||
return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
|
||||
case RGBFormat:
|
||||
return ( ( width * height * 3 ) / typeByteLength.components ) * typeByteLength.byteLength;
|
||||
case RGBAFormat:
|
||||
return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
|
||||
case RGBAIntegerFormat:
|
||||
return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
|
||||
|
||||
// https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_s3tc_srgb/
|
||||
case RGB_S3TC_DXT1_Format:
|
||||
case RGBA_S3TC_DXT1_Format:
|
||||
return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
|
||||
case RGBA_S3TC_DXT3_Format:
|
||||
case RGBA_S3TC_DXT5_Format:
|
||||
return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
|
||||
|
||||
// https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_pvrtc/
|
||||
case RGB_PVRTC_2BPPV1_Format:
|
||||
case RGBA_PVRTC_2BPPV1_Format:
|
||||
return ( Math.max( width, 16 ) * Math.max( height, 8 ) ) / 4;
|
||||
case RGB_PVRTC_4BPPV1_Format:
|
||||
case RGBA_PVRTC_4BPPV1_Format:
|
||||
return ( Math.max( width, 8 ) * Math.max( height, 8 ) ) / 2;
|
||||
|
||||
// https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_etc/
|
||||
case RGB_ETC1_Format:
|
||||
case RGB_ETC2_Format:
|
||||
return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
|
||||
case RGBA_ETC2_EAC_Format:
|
||||
return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
|
||||
|
||||
// https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/
|
||||
case RGBA_ASTC_4x4_Format:
|
||||
return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
|
||||
case RGBA_ASTC_5x4_Format:
|
||||
return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
|
||||
case RGBA_ASTC_5x5_Format:
|
||||
return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
|
||||
case RGBA_ASTC_6x5_Format:
|
||||
return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
|
||||
case RGBA_ASTC_6x6_Format:
|
||||
return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
|
||||
case RGBA_ASTC_8x5_Format:
|
||||
return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
|
||||
case RGBA_ASTC_8x6_Format:
|
||||
return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
|
||||
case RGBA_ASTC_8x8_Format:
|
||||
return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
|
||||
case RGBA_ASTC_10x5_Format:
|
||||
return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
|
||||
case RGBA_ASTC_10x6_Format:
|
||||
return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
|
||||
case RGBA_ASTC_10x8_Format:
|
||||
return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
|
||||
case RGBA_ASTC_10x10_Format:
|
||||
return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
|
||||
case RGBA_ASTC_12x10_Format:
|
||||
return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
|
||||
case RGBA_ASTC_12x12_Format:
|
||||
return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 11 ) / 12 ) * 16;
|
||||
|
||||
// https://registry.khronos.org/webgl/extensions/EXT_texture_compression_bptc/
|
||||
case RGBA_BPTC_Format:
|
||||
case RGB_BPTC_SIGNED_Format:
|
||||
case RGB_BPTC_UNSIGNED_Format:
|
||||
return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
|
||||
|
||||
// https://registry.khronos.org/webgl/extensions/EXT_texture_compression_rgtc/
|
||||
case RED_RGTC1_Format:
|
||||
case SIGNED_RED_RGTC1_Format:
|
||||
return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 8;
|
||||
case RED_GREEN_RGTC2_Format:
|
||||
case SIGNED_RED_GREEN_RGTC2_Format:
|
||||
return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
|
||||
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Unable to determine texture byte length for ${format} format.`,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function getTextureTypeByteLength( type ) {
|
||||
|
||||
switch ( type ) {
|
||||
|
||||
case UnsignedByteType:
|
||||
case ByteType:
|
||||
return { byteLength: 1, components: 1 };
|
||||
case UnsignedShortType:
|
||||
case ShortType:
|
||||
case HalfFloatType:
|
||||
return { byteLength: 2, components: 1 };
|
||||
case UnsignedShort4444Type:
|
||||
case UnsignedShort5551Type:
|
||||
return { byteLength: 2, components: 4 };
|
||||
case UnsignedIntType:
|
||||
case IntType:
|
||||
case FloatType:
|
||||
return { byteLength: 4, components: 1 };
|
||||
case UnsignedInt5999Type:
|
||||
return { byteLength: 4, components: 3 };
|
||||
|
||||
}
|
||||
|
||||
throw new Error( `Unknown texture type ${type}.` );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A class containing utility functions for textures.
|
||||
*
|
||||
* @hideconstructor
|
||||
*/
|
||||
class TextureUtils {
|
||||
|
||||
/**
|
||||
* Scales the texture as large as possible within its surface without cropping
|
||||
* or stretching the texture. The method preserves the original aspect ratio of
|
||||
* the texture. Akin to CSS `object-fit: contain`
|
||||
*
|
||||
* @param {Texture} texture - The texture.
|
||||
* @param {number} aspect - The texture's aspect ratio.
|
||||
* @return {Texture} The updated texture.
|
||||
*/
|
||||
static contain( texture, aspect ) {
|
||||
|
||||
return contain( texture, aspect );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales the texture to the smallest possible size to fill the surface, leaving
|
||||
* no empty space. The method preserves the original aspect ratio of the texture.
|
||||
* Akin to CSS `object-fit: cover`.
|
||||
*
|
||||
* @param {Texture} texture - The texture.
|
||||
* @param {number} aspect - The texture's aspect ratio.
|
||||
* @return {Texture} The updated texture.
|
||||
*/
|
||||
static cover( texture, aspect ) {
|
||||
|
||||
return cover( texture, aspect );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the texture to the default transformation. Akin to CSS `object-fit: fill`.
|
||||
*
|
||||
* @param {Texture} texture - The texture.
|
||||
* @return {Texture} The updated texture.
|
||||
*/
|
||||
static fill( texture ) {
|
||||
|
||||
return fill( texture );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines how many bytes must be used to represent the texture.
|
||||
*
|
||||
* @param {number} width - The width of the texture.
|
||||
* @param {number} height - The height of the texture.
|
||||
* @param {number} format - The texture's format.
|
||||
* @param {number} type - The texture's type.
|
||||
* @return {number} The byte length.
|
||||
*/
|
||||
static getByteLength( width, height, format, type ) {
|
||||
|
||||
return getByteLength( width, height, format, type );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { contain, cover, fill, getByteLength, TextureUtils };
|
||||
516
app/node_modules/three/src/extras/core/Curve.js
generated
vendored
Normal file
516
app/node_modules/three/src/extras/core/Curve.js
generated
vendored
Normal file
@@ -0,0 +1,516 @@
|
||||
import { clamp } from '../../math/MathUtils.js';
|
||||
import { Vector2 } from '../../math/Vector2.js';
|
||||
import { Vector3 } from '../../math/Vector3.js';
|
||||
import { Matrix4 } from '../../math/Matrix4.js';
|
||||
|
||||
/**
|
||||
* An abstract base class for creating an analytic curve object that contains methods
|
||||
* for interpolation.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
class Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new curve.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
/**
|
||||
* The type property is used for detecting the object type
|
||||
* in context of serialization/deserialization.
|
||||
*
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.type = 'Curve';
|
||||
|
||||
/**
|
||||
* This value determines the amount of divisions when calculating the
|
||||
* cumulative segment lengths of a curve via {@link Curve#getLengths}. To ensure
|
||||
* precision when using methods like {@link Curve#getSpacedPoints}, it is
|
||||
* recommended to increase the value of this property if the curve is very large.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 200
|
||||
*/
|
||||
this.arcLengthDivisions = 200;
|
||||
|
||||
/**
|
||||
* Must be set to `true` if the curve parameters have changed.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.needsUpdate = false;
|
||||
|
||||
/**
|
||||
* An internal cache that holds precomputed curve length values.
|
||||
*
|
||||
* @private
|
||||
* @type {?Array<number>}
|
||||
* @default null
|
||||
*/
|
||||
this.cacheArcLengths = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a vector in 2D or 3D space (depending on the curve definition)
|
||||
* for the given interpolation factor.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {(Vector2|Vector3)} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {(Vector2|Vector3)} The position on the curve. It can be a 2D or 3D vector depending on the curve definition.
|
||||
*/
|
||||
getPoint( /* t, optionalTarget */ ) {
|
||||
|
||||
console.warn( 'THREE.Curve: .getPoint() not implemented.' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a vector in 2D or 3D space (depending on the curve definition)
|
||||
* for the given interpolation factor. Unlike {@link Curve#getPoint}, this method honors the length
|
||||
* of the curve which equidistant samples.
|
||||
*
|
||||
* @param {number} u - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {(Vector2|Vector3)} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {(Vector2|Vector3)} The position on the curve. It can be a 2D or 3D vector depending on the curve definition.
|
||||
*/
|
||||
getPointAt( u, optionalTarget ) {
|
||||
|
||||
const t = this.getUtoTmapping( u );
|
||||
return this.getPoint( t, optionalTarget );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method samples the curve via {@link Curve#getPoint} and returns an array of points representing
|
||||
* the curve shape.
|
||||
*
|
||||
* @param {number} [divisions=5] - The number of divisions.
|
||||
* @return {Array<(Vector2|Vector3)>} An array holding the sampled curve values. The number of points is `divisions + 1`.
|
||||
*/
|
||||
getPoints( divisions = 5 ) {
|
||||
|
||||
const points = [];
|
||||
|
||||
for ( let d = 0; d <= divisions; d ++ ) {
|
||||
|
||||
points.push( this.getPoint( d / divisions ) );
|
||||
|
||||
}
|
||||
|
||||
return points;
|
||||
|
||||
}
|
||||
|
||||
// Get sequence of points using getPointAt( u )
|
||||
|
||||
/**
|
||||
* This method samples the curve via {@link Curve#getPointAt} and returns an array of points representing
|
||||
* the curve shape. Unlike {@link Curve#getPoints}, this method returns equi-spaced points across the entire
|
||||
* curve.
|
||||
*
|
||||
* @param {number} [divisions=5] - The number of divisions.
|
||||
* @return {Array<(Vector2|Vector3)>} An array holding the sampled curve values. The number of points is `divisions + 1`.
|
||||
*/
|
||||
getSpacedPoints( divisions = 5 ) {
|
||||
|
||||
const points = [];
|
||||
|
||||
for ( let d = 0; d <= divisions; d ++ ) {
|
||||
|
||||
points.push( this.getPointAt( d / divisions ) );
|
||||
|
||||
}
|
||||
|
||||
return points;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total arc length of the curve.
|
||||
*
|
||||
* @return {number} The length of the curve.
|
||||
*/
|
||||
getLength() {
|
||||
|
||||
const lengths = this.getLengths();
|
||||
return lengths[ lengths.length - 1 ];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of cumulative segment lengths of the curve.
|
||||
*
|
||||
* @param {number} [divisions=this.arcLengthDivisions] - The number of divisions.
|
||||
* @return {Array<number>} An array holding the cumulative segment lengths.
|
||||
*/
|
||||
getLengths( divisions = this.arcLengthDivisions ) {
|
||||
|
||||
if ( this.cacheArcLengths &&
|
||||
( this.cacheArcLengths.length === divisions + 1 ) &&
|
||||
! this.needsUpdate ) {
|
||||
|
||||
return this.cacheArcLengths;
|
||||
|
||||
}
|
||||
|
||||
this.needsUpdate = false;
|
||||
|
||||
const cache = [];
|
||||
let current, last = this.getPoint( 0 );
|
||||
let sum = 0;
|
||||
|
||||
cache.push( 0 );
|
||||
|
||||
for ( let 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.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the cumulative segment distance cache. The method must be called
|
||||
* every time curve parameters are changed. If an updated curve is part of a
|
||||
* composed curve like {@link CurvePath}, this method must be called on the
|
||||
* composed curve, too.
|
||||
*/
|
||||
updateArcLengths() {
|
||||
|
||||
this.needsUpdate = true;
|
||||
this.getLengths();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an interpolation factor in the range `[0,1]`, this method returns an updated
|
||||
* interpolation factor in the same range that can be ued to sample equidistant points
|
||||
* from a curve.
|
||||
*
|
||||
* @param {number} u - The interpolation factor.
|
||||
* @param {?number} distance - An optional distance on the curve.
|
||||
* @return {number} The updated interpolation factor.
|
||||
*/
|
||||
getUtoTmapping( u, distance = null ) {
|
||||
|
||||
const arcLengths = this.getLengths();
|
||||
|
||||
let i = 0;
|
||||
const il = arcLengths.length;
|
||||
|
||||
let targetArcLength; // The targeted u distance value to get
|
||||
|
||||
if ( distance ) {
|
||||
|
||||
targetArcLength = distance;
|
||||
|
||||
} else {
|
||||
|
||||
targetArcLength = u * arcLengths[ il - 1 ];
|
||||
|
||||
}
|
||||
|
||||
// binary search for the index with largest value smaller than target u distance
|
||||
|
||||
let 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;
|
||||
|
||||
if ( arcLengths[ i ] === targetArcLength ) {
|
||||
|
||||
return i / ( il - 1 );
|
||||
|
||||
}
|
||||
|
||||
// we could get finer grain at lengths, or use simple interpolation between two points
|
||||
|
||||
const lengthBefore = arcLengths[ i ];
|
||||
const lengthAfter = arcLengths[ i + 1 ];
|
||||
|
||||
const segmentLength = lengthAfter - lengthBefore;
|
||||
|
||||
// determine where we are between the 'before' and 'after' points
|
||||
|
||||
const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
|
||||
|
||||
// add that fractional amount to t
|
||||
|
||||
const t = ( i + segmentFraction ) / ( il - 1 );
|
||||
|
||||
return t;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a unit vector tangent for the given interpolation factor.
|
||||
* If the derived curve does not implement its tangent derivation,
|
||||
* two points a small delta apart will be used to find its gradient
|
||||
* which seems to give a reasonable approximation.
|
||||
*
|
||||
* @param {number} t - The interpolation factor.
|
||||
* @param {(Vector2|Vector3)} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {(Vector2|Vector3)} The tangent vector.
|
||||
*/
|
||||
getTangent( t, optionalTarget ) {
|
||||
|
||||
const delta = 0.0001;
|
||||
let t1 = t - delta;
|
||||
let t2 = t + delta;
|
||||
|
||||
// Capping in case of danger
|
||||
|
||||
if ( t1 < 0 ) t1 = 0;
|
||||
if ( t2 > 1 ) t2 = 1;
|
||||
|
||||
const pt1 = this.getPoint( t1 );
|
||||
const pt2 = this.getPoint( t2 );
|
||||
|
||||
const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
|
||||
|
||||
tangent.copy( pt2 ).sub( pt1 ).normalize();
|
||||
|
||||
return tangent;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link Curve#getTangent} but with equidistant samples.
|
||||
*
|
||||
* @param {number} u - The interpolation factor.
|
||||
* @param {(Vector2|Vector3)} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {(Vector2|Vector3)} The tangent vector.
|
||||
* @see {@link Curve#getPointAt}
|
||||
*/
|
||||
getTangentAt( u, optionalTarget ) {
|
||||
|
||||
const t = this.getUtoTmapping( u );
|
||||
return this.getTangent( t, optionalTarget );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the Frenet Frames. Requires a curve definition in 3D space. Used
|
||||
* in geometries like {@link TubeGeometry} or {@link ExtrudeGeometry}.
|
||||
*
|
||||
* @param {number} segments - The number of segments.
|
||||
* @param {boolean} [closed=false] - Whether the curve is closed or not.
|
||||
* @return {{tangents: Array<Vector3>, normals: Array<Vector3>, binormals: Array<Vector3>}} The Frenet Frames.
|
||||
*/
|
||||
computeFrenetFrames( segments, closed = false ) {
|
||||
|
||||
// see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
|
||||
|
||||
const normal = new Vector3();
|
||||
|
||||
const tangents = [];
|
||||
const normals = [];
|
||||
const binormals = [];
|
||||
|
||||
const vec = new Vector3();
|
||||
const mat = new Matrix4();
|
||||
|
||||
// compute the tangent vectors for each segment on the curve
|
||||
|
||||
for ( let i = 0; i <= segments; i ++ ) {
|
||||
|
||||
const u = i / segments;
|
||||
|
||||
tangents[ i ] = this.getTangentAt( u, new Vector3() );
|
||||
|
||||
}
|
||||
|
||||
// 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();
|
||||
let min = Number.MAX_VALUE;
|
||||
const tx = Math.abs( tangents[ 0 ].x );
|
||||
const ty = Math.abs( tangents[ 0 ].y );
|
||||
const 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 ( let 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();
|
||||
|
||||
const theta = Math.acos( 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 ) {
|
||||
|
||||
let theta = Math.acos( clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
|
||||
theta /= segments;
|
||||
|
||||
if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
|
||||
|
||||
theta = - theta;
|
||||
|
||||
}
|
||||
|
||||
for ( let 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
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new curve with copied values from this instance.
|
||||
*
|
||||
* @return {Curve} A clone of this instance.
|
||||
*/
|
||||
clone() {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the values of the given curve to this instance.
|
||||
*
|
||||
* @param {Curve} source - The curve to copy.
|
||||
* @return {Curve} A reference to this curve.
|
||||
*/
|
||||
copy( source ) {
|
||||
|
||||
this.arcLengthDivisions = source.arcLengthDivisions;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the curve into JSON.
|
||||
*
|
||||
* @return {Object} A JSON object representing the serialized curve.
|
||||
* @see {@link ObjectLoader#parse}
|
||||
*/
|
||||
toJSON() {
|
||||
|
||||
const data = {
|
||||
metadata: {
|
||||
version: 4.7,
|
||||
type: 'Curve',
|
||||
generator: 'Curve.toJSON'
|
||||
}
|
||||
};
|
||||
|
||||
data.arcLengthDivisions = this.arcLengthDivisions;
|
||||
data.type = this.type;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the curve from the given JSON.
|
||||
*
|
||||
* @param {Object} json - The JSON holding the serialized curve.
|
||||
* @return {Curve} A reference to this curve.
|
||||
*/
|
||||
fromJSON( json ) {
|
||||
|
||||
this.arcLengthDivisions = json.arcLengthDivisions;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { Curve };
|
||||
296
app/node_modules/three/src/extras/core/CurvePath.js
generated
vendored
Normal file
296
app/node_modules/three/src/extras/core/CurvePath.js
generated
vendored
Normal file
@@ -0,0 +1,296 @@
|
||||
import { Curve } from './Curve.js';
|
||||
import * as Curves from '../curves/Curves.js';
|
||||
|
||||
/**
|
||||
* A base class extending {@link Curve}. `CurvePath` is simply an
|
||||
* array of connected curves, but retains the API of a curve.
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class CurvePath extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new curve path.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'CurvePath';
|
||||
|
||||
/**
|
||||
* An array of curves defining the
|
||||
* path.
|
||||
*
|
||||
* @type {Array<Curve>}
|
||||
*/
|
||||
this.curves = [];
|
||||
|
||||
/**
|
||||
* Whether the path should automatically be closed
|
||||
* by a line curve.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.autoClose = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a curve to this curve path.
|
||||
*
|
||||
* @param {Curve} curve - The curve to add.
|
||||
*/
|
||||
add( curve ) {
|
||||
|
||||
this.curves.push( curve );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a line curve to close the path.
|
||||
*
|
||||
* @return {CurvePath} A reference to this curve path.
|
||||
*/
|
||||
closePath() {
|
||||
|
||||
// Add a line curve if start and end of lines are not connected
|
||||
const startPoint = this.curves[ 0 ].getPoint( 0 );
|
||||
const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
|
||||
|
||||
if ( ! startPoint.equals( endPoint ) ) {
|
||||
|
||||
const lineType = ( startPoint.isVector2 === true ) ? 'LineCurve' : 'LineCurve3';
|
||||
this.curves.push( new Curves[ lineType ]( endPoint, startPoint ) );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a vector in 2D or 3D space (depending on the curve definitions)
|
||||
* for the given interpolation factor.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {(Vector2|Vector3)} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {?(Vector2|Vector3)} The position on the curve. It can be a 2D or 3D vector depending on the curve definition.
|
||||
*/
|
||||
getPoint( t, optionalTarget ) {
|
||||
|
||||
// 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')
|
||||
|
||||
const d = t * this.getLength();
|
||||
const curveLengths = this.getCurveLengths();
|
||||
let i = 0;
|
||||
|
||||
// To think about boundaries points.
|
||||
|
||||
while ( i < curveLengths.length ) {
|
||||
|
||||
if ( curveLengths[ i ] >= d ) {
|
||||
|
||||
const diff = curveLengths[ i ] - d;
|
||||
const curve = this.curves[ i ];
|
||||
|
||||
const segmentLength = curve.getLength();
|
||||
const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
|
||||
|
||||
return curve.getPointAt( u, optionalTarget );
|
||||
|
||||
}
|
||||
|
||||
i ++;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
// loop where sum != 0, sum > d , sum+1 <d
|
||||
|
||||
}
|
||||
|
||||
getLength() {
|
||||
|
||||
// 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
|
||||
|
||||
const lens = this.getCurveLengths();
|
||||
return lens[ lens.length - 1 ];
|
||||
|
||||
}
|
||||
|
||||
updateArcLengths() {
|
||||
|
||||
// cacheLengths must be recalculated.
|
||||
|
||||
this.needsUpdate = true;
|
||||
this.cacheLengths = null;
|
||||
this.getCurveLengths();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of cumulative curve lengths of the defined curves.
|
||||
*
|
||||
* @return {Array<number>} The curve lengths.
|
||||
*/
|
||||
getCurveLengths() {
|
||||
|
||||
// Compute lengths and cache them
|
||||
// We cannot overwrite getLengths() because UtoT mapping uses it.
|
||||
// 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
|
||||
|
||||
const lengths = [];
|
||||
let sums = 0;
|
||||
|
||||
for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
|
||||
|
||||
sums += this.curves[ i ].getLength();
|
||||
lengths.push( sums );
|
||||
|
||||
}
|
||||
|
||||
this.cacheLengths = lengths;
|
||||
|
||||
return lengths;
|
||||
|
||||
}
|
||||
|
||||
getSpacedPoints( divisions = 40 ) {
|
||||
|
||||
const points = [];
|
||||
|
||||
for ( let i = 0; i <= divisions; i ++ ) {
|
||||
|
||||
points.push( this.getPoint( i / divisions ) );
|
||||
|
||||
}
|
||||
|
||||
if ( this.autoClose ) {
|
||||
|
||||
points.push( points[ 0 ] );
|
||||
|
||||
}
|
||||
|
||||
return points;
|
||||
|
||||
}
|
||||
|
||||
getPoints( divisions = 12 ) {
|
||||
|
||||
const points = [];
|
||||
let last;
|
||||
|
||||
for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
|
||||
|
||||
const curve = curves[ i ];
|
||||
const resolution = curve.isEllipseCurve ? divisions * 2
|
||||
: ( curve.isLineCurve || curve.isLineCurve3 ) ? 1
|
||||
: curve.isSplineCurve ? divisions * curve.points.length
|
||||
: divisions;
|
||||
|
||||
const pts = curve.getPoints( resolution );
|
||||
|
||||
for ( let j = 0; j < pts.length; j ++ ) {
|
||||
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.curves = [];
|
||||
|
||||
for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
|
||||
|
||||
const curve = source.curves[ i ];
|
||||
|
||||
this.curves.push( curve.clone() );
|
||||
|
||||
}
|
||||
|
||||
this.autoClose = source.autoClose;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.autoClose = this.autoClose;
|
||||
data.curves = [];
|
||||
|
||||
for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
|
||||
|
||||
const curve = this.curves[ i ];
|
||||
data.curves.push( curve.toJSON() );
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.autoClose = json.autoClose;
|
||||
this.curves = [];
|
||||
|
||||
for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
|
||||
|
||||
const curve = json.curves[ i ];
|
||||
this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { CurvePath };
|
||||
105
app/node_modules/three/src/extras/core/Interpolations.js
generated
vendored
Normal file
105
app/node_modules/three/src/extras/core/Interpolations.js
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
// Bezier Curves formulas obtained from: https://en.wikipedia.org/wiki/B%C3%A9zier_curve
|
||||
|
||||
/**
|
||||
* Computes a point on a Catmull-Rom spline.
|
||||
*
|
||||
* @param {number} t - The interpolation factor.
|
||||
* @param {number} p0 - The first control point.
|
||||
* @param {number} p1 - The second control point.
|
||||
* @param {number} p2 - The third control point.
|
||||
* @param {number} p3 - The fourth control point.
|
||||
* @return {number} The calculated point on a Catmull-Rom spline.
|
||||
*/
|
||||
function CatmullRom( t, p0, p1, p2, p3 ) {
|
||||
|
||||
const v0 = ( p2 - p0 ) * 0.5;
|
||||
const v1 = ( p3 - p1 ) * 0.5;
|
||||
const t2 = t * t;
|
||||
const 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 ) {
|
||||
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a point on a Quadratic Bezier curve.
|
||||
*
|
||||
* @param {number} t - The interpolation factor.
|
||||
* @param {number} p0 - The first control point.
|
||||
* @param {number} p1 - The second control point.
|
||||
* @param {number} p2 - The third control point.
|
||||
* @return {number} The calculated point on a Quadratic Bezier curve.
|
||||
*/
|
||||
function QuadraticBezier( t, p0, p1, p2 ) {
|
||||
|
||||
return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
|
||||
QuadraticBezierP2( t, p2 );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
function CubicBezierP0( t, p ) {
|
||||
|
||||
const k = 1 - t;
|
||||
return k * k * k * p;
|
||||
|
||||
}
|
||||
|
||||
function CubicBezierP1( t, p ) {
|
||||
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a point on a Cubic Bezier curve.
|
||||
*
|
||||
* @param {number} t - The interpolation factor.
|
||||
* @param {number} p0 - The first control point.
|
||||
* @param {number} p1 - The second control point.
|
||||
* @param {number} p2 - The third control point.
|
||||
* @param {number} p3 - The fourth control point.
|
||||
* @return {number} The calculated point on a Cubic Bezier curve.
|
||||
*/
|
||||
function CubicBezier( t, p0, p1, p2, p3 ) {
|
||||
|
||||
return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
|
||||
CubicBezierP3( t, p3 );
|
||||
|
||||
}
|
||||
|
||||
export { CatmullRom, QuadraticBezier, CubicBezier };
|
||||
329
app/node_modules/three/src/extras/core/Path.js
generated
vendored
Normal file
329
app/node_modules/three/src/extras/core/Path.js
generated
vendored
Normal file
@@ -0,0 +1,329 @@
|
||||
import { Vector2 } from '../../math/Vector2.js';
|
||||
import { CurvePath } from './CurvePath.js';
|
||||
import { EllipseCurve } from '../curves/EllipseCurve.js';
|
||||
import { SplineCurve } from '../curves/SplineCurve.js';
|
||||
import { CubicBezierCurve } from '../curves/CubicBezierCurve.js';
|
||||
import { QuadraticBezierCurve } from '../curves/QuadraticBezierCurve.js';
|
||||
import { LineCurve } from '../curves/LineCurve.js';
|
||||
|
||||
/**
|
||||
* A 2D path representation. The class provides methods for creating paths
|
||||
* and contours of 2D shapes similar to the 2D Canvas API.
|
||||
*
|
||||
* ```js
|
||||
* const path = new THREE.Path();
|
||||
*
|
||||
* path.lineTo( 0, 0.8 );
|
||||
* path.quadraticCurveTo( 0, 1, 0.2, 1 );
|
||||
* path.lineTo( 1, 1 );
|
||||
*
|
||||
* const points = path.getPoints();
|
||||
*
|
||||
* const geometry = new THREE.BufferGeometry().setFromPoints( points );
|
||||
* const material = new THREE.LineBasicMaterial( { color: 0xffffff } );
|
||||
*
|
||||
* const line = new THREE.Line( geometry, material );
|
||||
* scene.add( line );
|
||||
* ```
|
||||
*
|
||||
* @augments CurvePath
|
||||
*/
|
||||
class Path extends CurvePath {
|
||||
|
||||
/**
|
||||
* Constructs a new path.
|
||||
*
|
||||
* @param {Array<Vector2>} [points] - An array of 2D points defining the path.
|
||||
*/
|
||||
constructor( points ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'Path';
|
||||
|
||||
/**
|
||||
* The current offset of the path. Any new curve added will start here.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.currentPoint = new Vector2();
|
||||
|
||||
if ( points ) {
|
||||
|
||||
this.setFromPoints( points );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a path from the given list of points. The points are added
|
||||
* to the path as instances of {@link LineCurve}.
|
||||
*
|
||||
* @param {Array<Vector2>} points - An array of 2D points.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
setFromPoints( points ) {
|
||||
|
||||
this.moveTo( points[ 0 ].x, points[ 0 ].y );
|
||||
|
||||
for ( let i = 1, l = points.length; i < l; i ++ ) {
|
||||
|
||||
this.lineTo( points[ i ].x, points[ i ].y );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves {@link Path#currentPoint} to the given point.
|
||||
*
|
||||
* @param {number} x - The x coordinate.
|
||||
* @param {number} y - The y coordinate.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
moveTo( x, y ) {
|
||||
|
||||
this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an instance of {@link LineCurve} to the path by connecting
|
||||
* the current point with the given one.
|
||||
*
|
||||
* @param {number} x - The x coordinate of the end point.
|
||||
* @param {number} y - The y coordinate of the end point.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
lineTo( x, y ) {
|
||||
|
||||
const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
|
||||
this.curves.push( curve );
|
||||
|
||||
this.currentPoint.set( x, y );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an instance of {@link QuadraticBezierCurve} to the path by connecting
|
||||
* the current point with the given one.
|
||||
*
|
||||
* @param {number} aCPx - The x coordinate of the control point.
|
||||
* @param {number} aCPy - The y coordinate of the control point.
|
||||
* @param {number} aX - The x coordinate of the end point.
|
||||
* @param {number} aY - The y coordinate of the end point.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
quadraticCurveTo( aCPx, aCPy, aX, aY ) {
|
||||
|
||||
const curve = new QuadraticBezierCurve(
|
||||
this.currentPoint.clone(),
|
||||
new Vector2( aCPx, aCPy ),
|
||||
new Vector2( aX, aY )
|
||||
);
|
||||
|
||||
this.curves.push( curve );
|
||||
|
||||
this.currentPoint.set( aX, aY );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an instance of {@link CubicBezierCurve} to the path by connecting
|
||||
* the current point with the given one.
|
||||
*
|
||||
* @param {number} aCP1x - The x coordinate of the first control point.
|
||||
* @param {number} aCP1y - The y coordinate of the first control point.
|
||||
* @param {number} aCP2x - The x coordinate of the second control point.
|
||||
* @param {number} aCP2y - The y coordinate of the second control point.
|
||||
* @param {number} aX - The x coordinate of the end point.
|
||||
* @param {number} aY - The y coordinate of the end point.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
|
||||
|
||||
const 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 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an instance of {@link SplineCurve} to the path by connecting
|
||||
* the current point with the given list of points.
|
||||
*
|
||||
* @param {Array<Vector2>} pts - An array of points in 2D space.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
splineThru( pts ) {
|
||||
|
||||
const npts = [ this.currentPoint.clone() ].concat( pts );
|
||||
|
||||
const curve = new SplineCurve( npts );
|
||||
this.curves.push( curve );
|
||||
|
||||
this.currentPoint.copy( pts[ pts.length - 1 ] );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an arc as an instance of {@link EllipseCurve} to the path, positioned relative
|
||||
* to the current point.
|
||||
*
|
||||
* @param {number} [aX=0] - The x coordinate of the center of the arc offsetted from the previous curve.
|
||||
* @param {number} [aY=0] - The y coordinate of the center of the arc offsetted from the previous curve.
|
||||
* @param {number} [aRadius=1] - The radius of the arc.
|
||||
* @param {number} [aStartAngle=0] - The start angle in radians.
|
||||
* @param {number} [aEndAngle=Math.PI*2] - The end angle in radians.
|
||||
* @param {boolean} [aClockwise=false] - Whether to sweep the arc clockwise or not.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
||||
|
||||
const x0 = this.currentPoint.x;
|
||||
const y0 = this.currentPoint.y;
|
||||
|
||||
this.absarc( aX + x0, aY + y0, aRadius,
|
||||
aStartAngle, aEndAngle, aClockwise );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an absolutely positioned arc as an instance of {@link EllipseCurve} to the path.
|
||||
*
|
||||
* @param {number} [aX=0] - The x coordinate of the center of the arc.
|
||||
* @param {number} [aY=0] - The y coordinate of the center of the arc.
|
||||
* @param {number} [aRadius=1] - The radius of the arc.
|
||||
* @param {number} [aStartAngle=0] - The start angle in radians.
|
||||
* @param {number} [aEndAngle=Math.PI*2] - The end angle in radians.
|
||||
* @param {boolean} [aClockwise=false] - Whether to sweep the arc clockwise or not.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
||||
|
||||
this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an ellipse as an instance of {@link EllipseCurve} to the path, positioned relative
|
||||
* to the current point
|
||||
*
|
||||
* @param {number} [aX=0] - The x coordinate of the center of the ellipse offsetted from the previous curve.
|
||||
* @param {number} [aY=0] - The y coordinate of the center of the ellipse offsetted from the previous curve.
|
||||
* @param {number} [xRadius=1] - The radius of the ellipse in the x axis.
|
||||
* @param {number} [yRadius=1] - The radius of the ellipse in the y axis.
|
||||
* @param {number} [aStartAngle=0] - The start angle in radians.
|
||||
* @param {number} [aEndAngle=Math.PI*2] - The end angle in radians.
|
||||
* @param {boolean} [aClockwise=false] - Whether to sweep the ellipse clockwise or not.
|
||||
* @param {number} [aRotation=0] - The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
||||
|
||||
const x0 = this.currentPoint.x;
|
||||
const y0 = this.currentPoint.y;
|
||||
|
||||
this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an absolutely positioned ellipse as an instance of {@link EllipseCurve} to the path.
|
||||
*
|
||||
* @param {number} [aX=0] - The x coordinate of the absolute center of the ellipse.
|
||||
* @param {number} [aY=0] - The y coordinate of the absolute center of the ellipse.
|
||||
* @param {number} [xRadius=1] - The radius of the ellipse in the x axis.
|
||||
* @param {number} [yRadius=1] - The radius of the ellipse in the y axis.
|
||||
* @param {number} [aStartAngle=0] - The start angle in radians.
|
||||
* @param {number} [aEndAngle=Math.PI*2] - The end angle in radians.
|
||||
* @param {boolean} [aClockwise=false] - Whether to sweep the ellipse clockwise or not.
|
||||
* @param {number} [aRotation=0] - The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.
|
||||
* @return {Path} A reference to this path.
|
||||
*/
|
||||
absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
|
||||
|
||||
const 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
|
||||
const firstPoint = curve.getPoint( 0 );
|
||||
|
||||
if ( ! firstPoint.equals( this.currentPoint ) ) {
|
||||
|
||||
this.lineTo( firstPoint.x, firstPoint.y );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.curves.push( curve );
|
||||
|
||||
const lastPoint = curve.getPoint( 1 );
|
||||
this.currentPoint.copy( lastPoint );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.currentPoint.copy( source.currentPoint );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.currentPoint = this.currentPoint.toArray();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.currentPoint.fromArray( json.currentPoint );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { Path };
|
||||
165
app/node_modules/three/src/extras/core/Shape.js
generated
vendored
Normal file
165
app/node_modules/three/src/extras/core/Shape.js
generated
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
import { Path } from './Path.js';
|
||||
import { generateUUID } from '../../math/MathUtils.js';
|
||||
|
||||
/**
|
||||
* Defines an arbitrary 2d shape plane using paths with optional holes. It
|
||||
* can be used with {@link ExtrudeGeometry}, {@link ShapeGeometry}, to get
|
||||
* points, or to get triangulated faces.
|
||||
*
|
||||
* ```js
|
||||
* const heartShape = new THREE.Shape();
|
||||
*
|
||||
* heartShape.moveTo( 25, 25 );
|
||||
* heartShape.bezierCurveTo( 25, 25, 20, 0, 0, 0 );
|
||||
* heartShape.bezierCurveTo( - 30, 0, - 30, 35, - 30, 35 );
|
||||
* heartShape.bezierCurveTo( - 30, 55, - 10, 77, 25, 95 );
|
||||
* heartShape.bezierCurveTo( 60, 77, 80, 55, 80, 35 );
|
||||
* heartShape.bezierCurveTo( 80, 35, 80, 0, 50, 0 );
|
||||
* heartShape.bezierCurveTo( 35, 0, 25, 25, 25, 25 );
|
||||
*
|
||||
* const extrudeSettings = {
|
||||
* depth: 8,
|
||||
* bevelEnabled: true,
|
||||
* bevelSegments: 2,
|
||||
* steps: 2,
|
||||
* bevelSize: 1,
|
||||
* bevelThickness: 1
|
||||
* };
|
||||
*
|
||||
* const geometry = new THREE.ExtrudeGeometry( heartShape, extrudeSettings );
|
||||
* const mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial() );
|
||||
* ```
|
||||
*
|
||||
* @augments Path
|
||||
*/
|
||||
class Shape extends Path {
|
||||
|
||||
/**
|
||||
* Constructs a new shape.
|
||||
*
|
||||
* @param {Array<Vector2>} [points] - An array of 2D points defining the shape.
|
||||
*/
|
||||
constructor( points ) {
|
||||
|
||||
super( points );
|
||||
|
||||
/**
|
||||
* The UUID of the shape.
|
||||
*
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.uuid = generateUUID();
|
||||
|
||||
this.type = 'Shape';
|
||||
|
||||
/**
|
||||
* Defines the holes in the shape. Hole definitions must use the
|
||||
* opposite winding order (CW/CCW) than the outer shape.
|
||||
*
|
||||
* @type {Array<Path>}
|
||||
* @readonly
|
||||
*/
|
||||
this.holes = [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representing each contour of the holes
|
||||
* as a list of 2D points.
|
||||
*
|
||||
* @param {number} divisions - The fineness of the result.
|
||||
* @return {Array<Array<Vector2>>} The holes as a series of 2D points.
|
||||
*/
|
||||
getPointsHoles( divisions ) {
|
||||
|
||||
const holesPts = [];
|
||||
|
||||
for ( let 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)
|
||||
|
||||
/**
|
||||
* Returns an object that holds contour data for the shape and its holes as
|
||||
* arrays of 2D points.
|
||||
*
|
||||
* @param {number} divisions - The fineness of the result.
|
||||
* @return {{shape:Array<Vector2>,holes:Array<Array<Vector2>>}} An object with contour data.
|
||||
*/
|
||||
extractPoints( divisions ) {
|
||||
|
||||
return {
|
||||
|
||||
shape: this.getPoints( divisions ),
|
||||
holes: this.getPointsHoles( divisions )
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.holes = [];
|
||||
|
||||
for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
|
||||
|
||||
const hole = source.holes[ i ];
|
||||
|
||||
this.holes.push( hole.clone() );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.uuid = this.uuid;
|
||||
data.holes = [];
|
||||
|
||||
for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
|
||||
|
||||
const hole = this.holes[ i ];
|
||||
data.holes.push( hole.toJSON() );
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.uuid = json.uuid;
|
||||
this.holes = [];
|
||||
|
||||
for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
|
||||
|
||||
const hole = json.holes[ i ];
|
||||
this.holes.push( new Path().fromJSON( hole ) );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { Shape };
|
||||
367
app/node_modules/three/src/extras/core/ShapePath.js
generated
vendored
Normal file
367
app/node_modules/three/src/extras/core/ShapePath.js
generated
vendored
Normal file
@@ -0,0 +1,367 @@
|
||||
import { Color } from '../../math/Color.js';
|
||||
import { Path } from './Path.js';
|
||||
import { Shape } from './Shape.js';
|
||||
import { ShapeUtils } from '../ShapeUtils.js';
|
||||
|
||||
/**
|
||||
* This class is used to convert a series of paths to an array of
|
||||
* shapes. It is specifically used in context of fonts and SVG.
|
||||
*/
|
||||
class ShapePath {
|
||||
|
||||
/**
|
||||
* Constructs a new shape path.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
this.type = 'ShapePath';
|
||||
|
||||
/**
|
||||
* The color of the shape.
|
||||
*
|
||||
* @type {Color}
|
||||
*/
|
||||
this.color = new Color();
|
||||
|
||||
/**
|
||||
* The paths that have been generated for this shape.
|
||||
*
|
||||
* @type {Array<Path>}
|
||||
* @default null
|
||||
*/
|
||||
this.subPaths = [];
|
||||
|
||||
/**
|
||||
* The current path that is being generated.
|
||||
*
|
||||
* @type {?Path}
|
||||
* @default null
|
||||
*/
|
||||
this.currentPath = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new path and moves it current point to the given one.
|
||||
*
|
||||
* @param {number} x - The x coordinate.
|
||||
* @param {number} y - The y coordinate.
|
||||
* @return {ShapePath} A reference to this shape path.
|
||||
*/
|
||||
moveTo( x, y ) {
|
||||
|
||||
this.currentPath = new Path();
|
||||
this.subPaths.push( this.currentPath );
|
||||
this.currentPath.moveTo( x, y );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an instance of {@link LineCurve} to the path by connecting
|
||||
* the current point with the given one.
|
||||
*
|
||||
* @param {number} x - The x coordinate of the end point.
|
||||
* @param {number} y - The y coordinate of the end point.
|
||||
* @return {ShapePath} A reference to this shape path.
|
||||
*/
|
||||
lineTo( x, y ) {
|
||||
|
||||
this.currentPath.lineTo( x, y );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an instance of {@link QuadraticBezierCurve} to the path by connecting
|
||||
* the current point with the given one.
|
||||
*
|
||||
* @param {number} aCPx - The x coordinate of the control point.
|
||||
* @param {number} aCPy - The y coordinate of the control point.
|
||||
* @param {number} aX - The x coordinate of the end point.
|
||||
* @param {number} aY - The y coordinate of the end point.
|
||||
* @return {ShapePath} A reference to this shape path.
|
||||
*/
|
||||
quadraticCurveTo( aCPx, aCPy, aX, aY ) {
|
||||
|
||||
this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an instance of {@link CubicBezierCurve} to the path by connecting
|
||||
* the current point with the given one.
|
||||
*
|
||||
* @param {number} aCP1x - The x coordinate of the first control point.
|
||||
* @param {number} aCP1y - The y coordinate of the first control point.
|
||||
* @param {number} aCP2x - The x coordinate of the second control point.
|
||||
* @param {number} aCP2y - The y coordinate of the second control point.
|
||||
* @param {number} aX - The x coordinate of the end point.
|
||||
* @param {number} aY - The y coordinate of the end point.
|
||||
* @return {ShapePath} A reference to this shape path.
|
||||
*/
|
||||
bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
|
||||
|
||||
this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an instance of {@link SplineCurve} to the path by connecting
|
||||
* the current point with the given list of points.
|
||||
*
|
||||
* @param {Array<Vector2>} pts - An array of points in 2D space.
|
||||
* @return {ShapePath} A reference to this shape path.
|
||||
*/
|
||||
splineThru( pts ) {
|
||||
|
||||
this.currentPath.splineThru( pts );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the paths into an array of shapes.
|
||||
*
|
||||
* @param {boolean} isCCW - By default solid shapes are defined clockwise (CW) and holes are defined counterclockwise (CCW).
|
||||
* If this flag is set to `true`, then those are flipped.
|
||||
* @return {Array<Shape>} An array of shapes.
|
||||
*/
|
||||
toShapes( isCCW ) {
|
||||
|
||||
function toShapesNoHoles( inSubpaths ) {
|
||||
|
||||
const shapes = [];
|
||||
|
||||
for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
|
||||
|
||||
const tmpPath = inSubpaths[ i ];
|
||||
|
||||
const tmpShape = new Shape();
|
||||
tmpShape.curves = tmpPath.curves;
|
||||
|
||||
shapes.push( tmpShape );
|
||||
|
||||
}
|
||||
|
||||
return shapes;
|
||||
|
||||
}
|
||||
|
||||
function isPointInsidePolygon( inPt, inPolygon ) {
|
||||
|
||||
const 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
|
||||
let inside = false;
|
||||
for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
|
||||
|
||||
let edgeLowPt = inPolygon[ p ];
|
||||
let edgeHighPt = inPolygon[ q ];
|
||||
|
||||
let edgeDx = edgeHighPt.x - edgeLowPt.x;
|
||||
let 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 {
|
||||
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
const isClockWise = ShapeUtils.isClockWise;
|
||||
|
||||
const subPaths = this.subPaths;
|
||||
if ( subPaths.length === 0 ) return [];
|
||||
|
||||
let solid, tmpPath, tmpShape;
|
||||
const shapes = [];
|
||||
|
||||
if ( subPaths.length === 1 ) {
|
||||
|
||||
tmpPath = subPaths[ 0 ];
|
||||
tmpShape = new Shape();
|
||||
tmpShape.curves = tmpPath.curves;
|
||||
shapes.push( tmpShape );
|
||||
return shapes;
|
||||
|
||||
}
|
||||
|
||||
let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
|
||||
holesFirst = isCCW ? ! holesFirst : holesFirst;
|
||||
|
||||
// console.log("Holes first", holesFirst);
|
||||
|
||||
const betterShapeHoles = [];
|
||||
const newShapes = [];
|
||||
let newShapeHoles = [];
|
||||
let mainIdx = 0;
|
||||
let tmpPoints;
|
||||
|
||||
newShapes[ mainIdx ] = undefined;
|
||||
newShapeHoles[ mainIdx ] = [];
|
||||
|
||||
for ( let 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 ) {
|
||||
|
||||
let ambiguous = false;
|
||||
let toChange = 0;
|
||||
|
||||
for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
|
||||
|
||||
betterShapeHoles[ sIdx ] = [];
|
||||
|
||||
}
|
||||
|
||||
for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
|
||||
|
||||
const sho = newShapeHoles[ sIdx ];
|
||||
|
||||
for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
|
||||
|
||||
const ho = sho[ hIdx ];
|
||||
let hole_unassigned = true;
|
||||
|
||||
for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
|
||||
|
||||
if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
|
||||
|
||||
if ( sIdx !== s2Idx ) toChange ++;
|
||||
|
||||
if ( hole_unassigned ) {
|
||||
|
||||
hole_unassigned = false;
|
||||
betterShapeHoles[ s2Idx ].push( ho );
|
||||
|
||||
} else {
|
||||
|
||||
ambiguous = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( hole_unassigned ) {
|
||||
|
||||
betterShapeHoles[ sIdx ].push( ho );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( toChange > 0 && ambiguous === false ) {
|
||||
|
||||
newShapeHoles = betterShapeHoles;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let tmpHoles;
|
||||
|
||||
for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
|
||||
|
||||
tmpShape = newShapes[ i ].s;
|
||||
shapes.push( tmpShape );
|
||||
tmpHoles = newShapeHoles[ i ];
|
||||
|
||||
for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
|
||||
|
||||
tmpShape.holes.push( tmpHoles[ j ].h );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//console.log("shape", shapes);
|
||||
|
||||
return shapes;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { ShapePath };
|
||||
39
app/node_modules/three/src/extras/curves/ArcCurve.js
generated
vendored
Normal file
39
app/node_modules/three/src/extras/curves/ArcCurve.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { EllipseCurve } from './EllipseCurve.js';
|
||||
|
||||
/**
|
||||
* A curve representing an arc.
|
||||
*
|
||||
* @augments EllipseCurve
|
||||
*/
|
||||
class ArcCurve extends EllipseCurve {
|
||||
|
||||
/**
|
||||
* Constructs a new arc curve.
|
||||
*
|
||||
* @param {number} [aX=0] - The X center of the ellipse.
|
||||
* @param {number} [aY=0] - The Y center of the ellipse.
|
||||
* @param {number} [aRadius=1] - The radius of the ellipse in the x direction.
|
||||
* @param {number} [aStartAngle=0] - The start angle of the curve in radians starting from the positive X axis.
|
||||
* @param {number} [aEndAngle=Math.PI*2] - The end angle of the curve in radians starting from the positive X axis.
|
||||
* @param {boolean} [aClockwise=false] - Whether the ellipse is drawn clockwise or not.
|
||||
*/
|
||||
constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
|
||||
|
||||
super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isArcCurve = true;
|
||||
|
||||
this.type = 'ArcCurve';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { ArcCurve };
|
||||
326
app/node_modules/three/src/extras/curves/CatmullRomCurve3.js
generated
vendored
Normal file
326
app/node_modules/three/src/extras/curves/CatmullRomCurve3.js
generated
vendored
Normal file
@@ -0,0 +1,326 @@
|
||||
import { Vector3 } from '../../math/Vector3.js';
|
||||
import { Curve } from '../core/Curve.js';
|
||||
|
||||
function CubicPoly() {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
let 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]
|
||||
let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
|
||||
let 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 ) {
|
||||
|
||||
const t2 = t * t;
|
||||
const t3 = t2 * t;
|
||||
return c0 + c1 * t + c2 * t2 + c3 * t3;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
const tmp = /*@__PURE__*/ new Vector3();
|
||||
const px = /*@__PURE__*/ new CubicPoly();
|
||||
const py = /*@__PURE__*/ new CubicPoly();
|
||||
const pz = /*@__PURE__*/ new CubicPoly();
|
||||
|
||||
/**
|
||||
* A curve representing a Catmull-Rom spline.
|
||||
*
|
||||
* ```js
|
||||
* //Create a closed wavey loop
|
||||
* const curve = new THREE.CatmullRomCurve3( [
|
||||
* new THREE.Vector3( -10, 0, 10 ),
|
||||
* new THREE.Vector3( -5, 5, 5 ),
|
||||
* new THREE.Vector3( 0, 0, 0 ),
|
||||
* new THREE.Vector3( 5, -5, 5 ),
|
||||
* new THREE.Vector3( 10, 0, 10 )
|
||||
* ] );
|
||||
*
|
||||
* const points = curve.getPoints( 50 );
|
||||
* const geometry = new THREE.BufferGeometry().setFromPoints( points );
|
||||
*
|
||||
* const material = new THREE.LineBasicMaterial( { color: 0xff0000 } );
|
||||
*
|
||||
* // Create the final object to add to the scene
|
||||
* const curveObject = new THREE.Line( geometry, material );
|
||||
* ```
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class CatmullRomCurve3 extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new Catmull-Rom curve.
|
||||
*
|
||||
* @param {Array<Vector3>} [points] - An array of 3D points defining the curve.
|
||||
* @param {boolean} [closed=false] - Whether the curve is closed or not.
|
||||
* @param {('centripetal'|'chordal'|'catmullrom')} [curveType='centripetal'] - The curve type.
|
||||
* @param {number} [tension=0.5] - Tension of the curve.
|
||||
*/
|
||||
constructor( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isCatmullRomCurve3 = true;
|
||||
|
||||
this.type = 'CatmullRomCurve3';
|
||||
|
||||
/**
|
||||
* An array of 3D points defining the curve.
|
||||
*
|
||||
* @type {Array<Vector3>}
|
||||
*/
|
||||
this.points = points;
|
||||
|
||||
/**
|
||||
* Whether the curve is closed or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.closed = closed;
|
||||
|
||||
/**
|
||||
* The curve type.
|
||||
*
|
||||
* @type {('centripetal'|'chordal'|'catmullrom')}
|
||||
* @default 'centripetal'
|
||||
*/
|
||||
this.curveType = curveType;
|
||||
|
||||
/**
|
||||
* Tension of the curve.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0.5
|
||||
*/
|
||||
this.tension = tension;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point on the curve.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {Vector3} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {Vector3} The position on the curve.
|
||||
*/
|
||||
getPoint( t, optionalTarget = new Vector3() ) {
|
||||
|
||||
const point = optionalTarget;
|
||||
|
||||
const points = this.points;
|
||||
const l = points.length;
|
||||
|
||||
const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
|
||||
let intPoint = Math.floor( p );
|
||||
let weight = p - intPoint;
|
||||
|
||||
if ( this.closed ) {
|
||||
|
||||
intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
|
||||
|
||||
} else if ( weight === 0 && intPoint === l - 1 ) {
|
||||
|
||||
intPoint = l - 2;
|
||||
weight = 1;
|
||||
|
||||
}
|
||||
|
||||
let p0, p3; // 4 points (p1 & p2 defined below)
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
const p1 = points[ intPoint % l ];
|
||||
const 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.curveType === 'centripetal' || this.curveType === 'chordal' ) {
|
||||
|
||||
// init Centripetal / Chordal Catmull-Rom
|
||||
const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
|
||||
let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
|
||||
let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
|
||||
let 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.curveType === 'catmullrom' ) {
|
||||
|
||||
px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
|
||||
py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
|
||||
pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
|
||||
|
||||
}
|
||||
|
||||
point.set(
|
||||
px.calc( weight ),
|
||||
py.calc( weight ),
|
||||
pz.calc( weight )
|
||||
);
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.points = [];
|
||||
|
||||
for ( let i = 0, l = source.points.length; i < l; i ++ ) {
|
||||
|
||||
const point = source.points[ i ];
|
||||
|
||||
this.points.push( point.clone() );
|
||||
|
||||
}
|
||||
|
||||
this.closed = source.closed;
|
||||
this.curveType = source.curveType;
|
||||
this.tension = source.tension;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.points = [];
|
||||
|
||||
for ( let i = 0, l = this.points.length; i < l; i ++ ) {
|
||||
|
||||
const point = this.points[ i ];
|
||||
data.points.push( point.toArray() );
|
||||
|
||||
}
|
||||
|
||||
data.closed = this.closed;
|
||||
data.curveType = this.curveType;
|
||||
data.tension = this.tension;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.points = [];
|
||||
|
||||
for ( let i = 0, l = json.points.length; i < l; i ++ ) {
|
||||
|
||||
const point = json.points[ i ];
|
||||
this.points.push( new Vector3().fromArray( point ) );
|
||||
|
||||
}
|
||||
|
||||
this.closed = json.closed;
|
||||
this.curveType = json.curveType;
|
||||
this.tension = json.tension;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { CatmullRomCurve3 };
|
||||
145
app/node_modules/three/src/extras/curves/CubicBezierCurve.js
generated
vendored
Normal file
145
app/node_modules/three/src/extras/curves/CubicBezierCurve.js
generated
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
import { Curve } from '../core/Curve.js';
|
||||
import { CubicBezier } from '../core/Interpolations.js';
|
||||
import { Vector2 } from '../../math/Vector2.js';
|
||||
|
||||
/**
|
||||
* A curve representing a 2D Cubic Bezier curve.
|
||||
*
|
||||
* ```js
|
||||
* const curve = new THREE.CubicBezierCurve(
|
||||
* new THREE.Vector2( - 0, 0 ),
|
||||
* new THREE.Vector2( - 5, 15 ),
|
||||
* new THREE.Vector2( 20, 15 ),
|
||||
* new THREE.Vector2( 10, 0 )
|
||||
* );
|
||||
*
|
||||
* const points = curve.getPoints( 50 );
|
||||
* const geometry = new THREE.BufferGeometry().setFromPoints( points );
|
||||
*
|
||||
* const material = new THREE.LineBasicMaterial( { color: 0xff0000 } );
|
||||
*
|
||||
* // Create the final object to add to the scene
|
||||
* const curveObject = new THREE.Line( geometry, material );
|
||||
* ```
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class CubicBezierCurve extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new Cubic Bezier curve.
|
||||
*
|
||||
* @param {Vector2} [v0] - The start point.
|
||||
* @param {Vector2} [v1] - The first control point.
|
||||
* @param {Vector2} [v2] - The second control point.
|
||||
* @param {Vector2} [v3] - The end point.
|
||||
*/
|
||||
constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isCubicBezierCurve = true;
|
||||
|
||||
this.type = 'CubicBezierCurve';
|
||||
|
||||
/**
|
||||
* The start point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v0 = v0;
|
||||
|
||||
/**
|
||||
* The first control point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v1 = v1;
|
||||
|
||||
/**
|
||||
* The second control point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v2 = v2;
|
||||
|
||||
/**
|
||||
* The end point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v3 = v3;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point on the curve.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {Vector2} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {Vector2} The position on the curve.
|
||||
*/
|
||||
getPoint( t, optionalTarget = new Vector2() ) {
|
||||
|
||||
const point = optionalTarget;
|
||||
|
||||
const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
|
||||
|
||||
point.set(
|
||||
CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
|
||||
CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
|
||||
);
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.v0.copy( source.v0 );
|
||||
this.v1.copy( source.v1 );
|
||||
this.v2.copy( source.v2 );
|
||||
this.v3.copy( source.v3 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.v0 = this.v0.toArray();
|
||||
data.v1 = this.v1.toArray();
|
||||
data.v2 = this.v2.toArray();
|
||||
data.v3 = this.v3.toArray();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.v0.fromArray( json.v0 );
|
||||
this.v1.fromArray( json.v1 );
|
||||
this.v2.fromArray( json.v2 );
|
||||
this.v3.fromArray( json.v3 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { CubicBezierCurve };
|
||||
129
app/node_modules/three/src/extras/curves/CubicBezierCurve3.js
generated
vendored
Normal file
129
app/node_modules/three/src/extras/curves/CubicBezierCurve3.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
import { Curve } from '../core/Curve.js';
|
||||
import { CubicBezier } from '../core/Interpolations.js';
|
||||
import { Vector3 } from '../../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* A curve representing a 3D Cubic Bezier curve.
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class CubicBezierCurve3 extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new Cubic Bezier curve.
|
||||
*
|
||||
* @param {Vector3} [v0] - The start point.
|
||||
* @param {Vector3} [v1] - The first control point.
|
||||
* @param {Vector3} [v2] - The second control point.
|
||||
* @param {Vector3} [v3] - The end point.
|
||||
*/
|
||||
constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isCubicBezierCurve3 = true;
|
||||
|
||||
this.type = 'CubicBezierCurve3';
|
||||
|
||||
/**
|
||||
* The start point.
|
||||
*
|
||||
* @type {Vector3}
|
||||
*/
|
||||
this.v0 = v0;
|
||||
|
||||
/**
|
||||
* The first control point.
|
||||
*
|
||||
* @type {Vector3}
|
||||
*/
|
||||
this.v1 = v1;
|
||||
|
||||
/**
|
||||
* The second control point.
|
||||
*
|
||||
* @type {Vector3}
|
||||
*/
|
||||
this.v2 = v2;
|
||||
|
||||
/**
|
||||
* The end point.
|
||||
*
|
||||
* @type {Vector3}
|
||||
*/
|
||||
this.v3 = v3;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point on the curve.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {Vector3} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {Vector3} The position on the curve.
|
||||
*/
|
||||
getPoint( t, optionalTarget = new Vector3() ) {
|
||||
|
||||
const point = optionalTarget;
|
||||
|
||||
const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
|
||||
|
||||
point.set(
|
||||
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 )
|
||||
);
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.v0.copy( source.v0 );
|
||||
this.v1.copy( source.v1 );
|
||||
this.v2.copy( source.v2 );
|
||||
this.v3.copy( source.v3 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.v0 = this.v0.toArray();
|
||||
data.v1 = this.v1.toArray();
|
||||
data.v2 = this.v2.toArray();
|
||||
data.v3 = this.v3.toArray();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.v0.fromArray( json.v0 );
|
||||
this.v1.fromArray( json.v1 );
|
||||
this.v2.fromArray( json.v2 );
|
||||
this.v3.fromArray( json.v3 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { CubicBezierCurve3 };
|
||||
10
app/node_modules/three/src/extras/curves/Curves.js
generated
vendored
Normal file
10
app/node_modules/three/src/extras/curves/Curves.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export { ArcCurve } from './ArcCurve.js';
|
||||
export { CatmullRomCurve3 } from './CatmullRomCurve3.js';
|
||||
export { CubicBezierCurve } from './CubicBezierCurve.js';
|
||||
export { CubicBezierCurve3 } from './CubicBezierCurve3.js';
|
||||
export { EllipseCurve } from './EllipseCurve.js';
|
||||
export { LineCurve } from './LineCurve.js';
|
||||
export { LineCurve3 } from './LineCurve3.js';
|
||||
export { QuadraticBezierCurve } from './QuadraticBezierCurve.js';
|
||||
export { QuadraticBezierCurve3 } from './QuadraticBezierCurve3.js';
|
||||
export { SplineCurve } from './SplineCurve.js';
|
||||
258
app/node_modules/three/src/extras/curves/EllipseCurve.js
generated
vendored
Normal file
258
app/node_modules/three/src/extras/curves/EllipseCurve.js
generated
vendored
Normal file
@@ -0,0 +1,258 @@
|
||||
import { Curve } from '../core/Curve.js';
|
||||
import { Vector2 } from '../../math/Vector2.js';
|
||||
|
||||
/**
|
||||
* A curve representing an ellipse.
|
||||
*
|
||||
* ```js
|
||||
* const curve = new THREE.EllipseCurve(
|
||||
* 0, 0,
|
||||
* 10, 10,
|
||||
* 0, 2 * Math.PI,
|
||||
* false,
|
||||
* 0
|
||||
* );
|
||||
*
|
||||
* const points = curve.getPoints( 50 );
|
||||
* const geometry = new THREE.BufferGeometry().setFromPoints( points );
|
||||
*
|
||||
* const material = new THREE.LineBasicMaterial( { color: 0xff0000 } );
|
||||
*
|
||||
* // Create the final object to add to the scene
|
||||
* const ellipse = new THREE.Line( geometry, material );
|
||||
* ```
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class EllipseCurve extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new ellipse curve.
|
||||
*
|
||||
* @param {number} [aX=0] - The X center of the ellipse.
|
||||
* @param {number} [aY=0] - The Y center of the ellipse.
|
||||
* @param {number} [xRadius=1] - The radius of the ellipse in the x direction.
|
||||
* @param {number} [yRadius=1] - The radius of the ellipse in the y direction.
|
||||
* @param {number} [aStartAngle=0] - The start angle of the curve in radians starting from the positive X axis.
|
||||
* @param {number} [aEndAngle=Math.PI*2] - The end angle of the curve in radians starting from the positive X axis.
|
||||
* @param {boolean} [aClockwise=false] - Whether the ellipse is drawn clockwise or not.
|
||||
* @param {number} [aRotation=0] - The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.
|
||||
*/
|
||||
constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isEllipseCurve = true;
|
||||
|
||||
this.type = 'EllipseCurve';
|
||||
|
||||
/**
|
||||
* The X center of the ellipse.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.aX = aX;
|
||||
|
||||
/**
|
||||
* The Y center of the ellipse.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.aY = aY;
|
||||
|
||||
/**
|
||||
* The radius of the ellipse in the x direction.
|
||||
* Setting the this value equal to the {@link EllipseCurve#yRadius} will result in a circle.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.xRadius = xRadius;
|
||||
|
||||
/**
|
||||
* The radius of the ellipse in the y direction.
|
||||
* Setting the this value equal to the {@link EllipseCurve#xRadius} will result in a circle.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 1
|
||||
*/
|
||||
this.yRadius = yRadius;
|
||||
|
||||
/**
|
||||
* The start angle of the curve in radians starting from the positive X axis.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.aStartAngle = aStartAngle;
|
||||
|
||||
/**
|
||||
* The end angle of the curve in radians starting from the positive X axis.
|
||||
*
|
||||
* @type {number}
|
||||
* @default Math.PI*2
|
||||
*/
|
||||
this.aEndAngle = aEndAngle;
|
||||
|
||||
/**
|
||||
* Whether the ellipse is drawn clockwise or not.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.aClockwise = aClockwise;
|
||||
|
||||
/**
|
||||
* The rotation angle of the ellipse in radians, counterclockwise from the positive X axis.
|
||||
*
|
||||
* @type {number}
|
||||
* @default 0
|
||||
*/
|
||||
this.aRotation = aRotation;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point on the curve.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {Vector2} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {Vector2} The position on the curve.
|
||||
*/
|
||||
getPoint( t, optionalTarget = new Vector2() ) {
|
||||
|
||||
const point = optionalTarget;
|
||||
|
||||
const twoPi = Math.PI * 2;
|
||||
let deltaAngle = this.aEndAngle - this.aStartAngle;
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const angle = this.aStartAngle + t * deltaAngle;
|
||||
let x = this.aX + this.xRadius * Math.cos( angle );
|
||||
let y = this.aY + this.yRadius * Math.sin( angle );
|
||||
|
||||
if ( this.aRotation !== 0 ) {
|
||||
|
||||
const cos = Math.cos( this.aRotation );
|
||||
const sin = Math.sin( this.aRotation );
|
||||
|
||||
const tx = x - this.aX;
|
||||
const 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 point.set( x, y );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.aX = source.aX;
|
||||
this.aY = source.aY;
|
||||
|
||||
this.xRadius = source.xRadius;
|
||||
this.yRadius = source.yRadius;
|
||||
|
||||
this.aStartAngle = source.aStartAngle;
|
||||
this.aEndAngle = source.aEndAngle;
|
||||
|
||||
this.aClockwise = source.aClockwise;
|
||||
|
||||
this.aRotation = source.aRotation;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.aX = this.aX;
|
||||
data.aY = this.aY;
|
||||
|
||||
data.xRadius = this.xRadius;
|
||||
data.yRadius = this.yRadius;
|
||||
|
||||
data.aStartAngle = this.aStartAngle;
|
||||
data.aEndAngle = this.aEndAngle;
|
||||
|
||||
data.aClockwise = this.aClockwise;
|
||||
|
||||
data.aRotation = this.aRotation;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.aX = json.aX;
|
||||
this.aY = json.aY;
|
||||
|
||||
this.xRadius = json.xRadius;
|
||||
this.yRadius = json.yRadius;
|
||||
|
||||
this.aStartAngle = json.aStartAngle;
|
||||
this.aEndAngle = json.aEndAngle;
|
||||
|
||||
this.aClockwise = json.aClockwise;
|
||||
|
||||
this.aRotation = json.aRotation;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { EllipseCurve };
|
||||
128
app/node_modules/three/src/extras/curves/LineCurve.js
generated
vendored
Normal file
128
app/node_modules/three/src/extras/curves/LineCurve.js
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
import { Vector2 } from '../../math/Vector2.js';
|
||||
import { Curve } from '../core/Curve.js';
|
||||
|
||||
/**
|
||||
* A curve representing a 2D line segment.
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class LineCurve extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new line curve.
|
||||
*
|
||||
* @param {Vector2} [v1] - The start point.
|
||||
* @param {Vector2} [v2] - The end point.
|
||||
*/
|
||||
constructor( v1 = new Vector2(), v2 = new Vector2() ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isLineCurve = true;
|
||||
|
||||
this.type = 'LineCurve';
|
||||
|
||||
/**
|
||||
* The start point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v1 = v1;
|
||||
|
||||
/**
|
||||
* The end point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v2 = v2;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point on the line.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the line. Must be in the range `[0,1]`.
|
||||
* @param {Vector2} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {Vector2} The position on the line.
|
||||
*/
|
||||
getPoint( t, optionalTarget = new Vector2() ) {
|
||||
|
||||
const point = optionalTarget;
|
||||
|
||||
if ( t === 1 ) {
|
||||
|
||||
point.copy( this.v2 );
|
||||
|
||||
} else {
|
||||
|
||||
point.copy( this.v2 ).sub( this.v1 );
|
||||
point.multiplyScalar( t ).add( this.v1 );
|
||||
|
||||
}
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
// Line curve is linear, so we can overwrite default getPointAt
|
||||
getPointAt( u, optionalTarget ) {
|
||||
|
||||
return this.getPoint( u, optionalTarget );
|
||||
|
||||
}
|
||||
|
||||
getTangent( t, optionalTarget = new Vector2() ) {
|
||||
|
||||
return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
|
||||
|
||||
}
|
||||
|
||||
getTangentAt( u, optionalTarget ) {
|
||||
|
||||
return this.getTangent( u, optionalTarget );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.v1.copy( source.v1 );
|
||||
this.v2.copy( source.v2 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.v1 = this.v1.toArray();
|
||||
data.v2 = this.v2.toArray();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.v1.fromArray( json.v1 );
|
||||
this.v2.fromArray( json.v2 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { LineCurve };
|
||||
128
app/node_modules/three/src/extras/curves/LineCurve3.js
generated
vendored
Normal file
128
app/node_modules/three/src/extras/curves/LineCurve3.js
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
import { Vector3 } from '../../math/Vector3.js';
|
||||
import { Curve } from '../core/Curve.js';
|
||||
|
||||
/**
|
||||
* A curve representing a 3D line segment.
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class LineCurve3 extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new line curve.
|
||||
*
|
||||
* @param {Vector3} [v1] - The start point.
|
||||
* @param {Vector3} [v2] - The end point.
|
||||
*/
|
||||
constructor( v1 = new Vector3(), v2 = new Vector3() ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isLineCurve3 = true;
|
||||
|
||||
this.type = 'LineCurve3';
|
||||
|
||||
/**
|
||||
* The start point.
|
||||
*
|
||||
* @type {Vector3}
|
||||
*/
|
||||
this.v1 = v1;
|
||||
|
||||
/**
|
||||
* The end point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v2 = v2;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point on the line.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the line. Must be in the range `[0,1]`.
|
||||
* @param {Vector3} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {Vector3} The position on the line.
|
||||
*/
|
||||
getPoint( t, optionalTarget = new Vector3() ) {
|
||||
|
||||
const point = optionalTarget;
|
||||
|
||||
if ( t === 1 ) {
|
||||
|
||||
point.copy( this.v2 );
|
||||
|
||||
} else {
|
||||
|
||||
point.copy( this.v2 ).sub( this.v1 );
|
||||
point.multiplyScalar( t ).add( this.v1 );
|
||||
|
||||
}
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
// Line curve is linear, so we can overwrite default getPointAt
|
||||
getPointAt( u, optionalTarget ) {
|
||||
|
||||
return this.getPoint( u, optionalTarget );
|
||||
|
||||
}
|
||||
|
||||
getTangent( t, optionalTarget = new Vector3() ) {
|
||||
|
||||
return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
|
||||
|
||||
}
|
||||
|
||||
getTangentAt( u, optionalTarget ) {
|
||||
|
||||
return this.getTangent( u, optionalTarget );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.v1.copy( source.v1 );
|
||||
this.v2.copy( source.v2 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.v1 = this.v1.toArray();
|
||||
data.v2 = this.v2.toArray();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.v1.fromArray( json.v1 );
|
||||
this.v2.fromArray( json.v2 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { LineCurve3 };
|
||||
133
app/node_modules/three/src/extras/curves/QuadraticBezierCurve.js
generated
vendored
Normal file
133
app/node_modules/three/src/extras/curves/QuadraticBezierCurve.js
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
import { Curve } from '../core/Curve.js';
|
||||
import { QuadraticBezier } from '../core/Interpolations.js';
|
||||
import { Vector2 } from '../../math/Vector2.js';
|
||||
|
||||
/**
|
||||
* A curve representing a 2D Quadratic Bezier curve.
|
||||
*
|
||||
* ```js
|
||||
* const curve = new THREE.QuadraticBezierCurve(
|
||||
* new THREE.Vector2( - 10, 0 ),
|
||||
* new THREE.Vector2( 20, 15 ),
|
||||
* new THREE.Vector2( 10, 0 )
|
||||
* )
|
||||
*
|
||||
* const points = curve.getPoints( 50 );
|
||||
* const geometry = new THREE.BufferGeometry().setFromPoints( points );
|
||||
*
|
||||
* const material = new THREE.LineBasicMaterial( { color: 0xff0000 } );
|
||||
*
|
||||
* // Create the final object to add to the scene
|
||||
* const curveObject = new THREE.Line( geometry, material );
|
||||
* ```
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class QuadraticBezierCurve extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new Quadratic Bezier curve.
|
||||
*
|
||||
* @param {Vector2} [v0] - The start point.
|
||||
* @param {Vector2} [v1] - The control point.
|
||||
* @param {Vector2} [v2] - The end point.
|
||||
*/
|
||||
constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isQuadraticBezierCurve = true;
|
||||
|
||||
this.type = 'QuadraticBezierCurve';
|
||||
|
||||
/**
|
||||
* The start point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v0 = v0;
|
||||
|
||||
/**
|
||||
* The control point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v1 = v1;
|
||||
|
||||
/**
|
||||
* The end point.
|
||||
*
|
||||
* @type {Vector2}
|
||||
*/
|
||||
this.v2 = v2;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point on the curve.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {Vector2} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {Vector2} The position on the curve.
|
||||
*/
|
||||
getPoint( t, optionalTarget = new Vector2() ) {
|
||||
|
||||
const point = optionalTarget;
|
||||
|
||||
const v0 = this.v0, v1 = this.v1, v2 = this.v2;
|
||||
|
||||
point.set(
|
||||
QuadraticBezier( t, v0.x, v1.x, v2.x ),
|
||||
QuadraticBezier( t, v0.y, v1.y, v2.y )
|
||||
);
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.v0.copy( source.v0 );
|
||||
this.v1.copy( source.v1 );
|
||||
this.v2.copy( source.v2 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.v0 = this.v0.toArray();
|
||||
data.v1 = this.v1.toArray();
|
||||
data.v2 = this.v2.toArray();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.v0.fromArray( json.v0 );
|
||||
this.v1.fromArray( json.v1 );
|
||||
this.v2.fromArray( json.v2 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { QuadraticBezierCurve };
|
||||
118
app/node_modules/three/src/extras/curves/QuadraticBezierCurve3.js
generated
vendored
Normal file
118
app/node_modules/three/src/extras/curves/QuadraticBezierCurve3.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
import { Curve } from '../core/Curve.js';
|
||||
import { QuadraticBezier } from '../core/Interpolations.js';
|
||||
import { Vector3 } from '../../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* A curve representing a 3D Quadratic Bezier curve.
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class QuadraticBezierCurve3 extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new Quadratic Bezier curve.
|
||||
*
|
||||
* @param {Vector3} [v0] - The start point.
|
||||
* @param {Vector3} [v1] - The control point.
|
||||
* @param {Vector3} [v2] - The end point.
|
||||
*/
|
||||
constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isQuadraticBezierCurve3 = true;
|
||||
|
||||
this.type = 'QuadraticBezierCurve3';
|
||||
|
||||
/**
|
||||
* The start point.
|
||||
*
|
||||
* @type {Vector3}
|
||||
*/
|
||||
this.v0 = v0;
|
||||
|
||||
/**
|
||||
* The control point.
|
||||
*
|
||||
* @type {Vector3}
|
||||
*/
|
||||
this.v1 = v1;
|
||||
|
||||
/**
|
||||
* The end point.
|
||||
*
|
||||
* @type {Vector3}
|
||||
*/
|
||||
this.v2 = v2;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point on the curve.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {Vector3} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {Vector3} The position on the curve.
|
||||
*/
|
||||
getPoint( t, optionalTarget = new Vector3() ) {
|
||||
|
||||
const point = optionalTarget;
|
||||
|
||||
const v0 = this.v0, v1 = this.v1, v2 = this.v2;
|
||||
|
||||
point.set(
|
||||
QuadraticBezier( t, v0.x, v1.x, v2.x ),
|
||||
QuadraticBezier( t, v0.y, v1.y, v2.y ),
|
||||
QuadraticBezier( t, v0.z, v1.z, v2.z )
|
||||
);
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.v0.copy( source.v0 );
|
||||
this.v1.copy( source.v1 );
|
||||
this.v2.copy( source.v2 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.v0 = this.v0.toArray();
|
||||
data.v1 = this.v1.toArray();
|
||||
data.v2 = this.v2.toArray();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.v0.fromArray( json.v0 );
|
||||
this.v1.fromArray( json.v1 );
|
||||
this.v2.fromArray( json.v2 );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { QuadraticBezierCurve3 };
|
||||
145
app/node_modules/three/src/extras/curves/SplineCurve.js
generated
vendored
Normal file
145
app/node_modules/three/src/extras/curves/SplineCurve.js
generated
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
import { Curve } from '../core/Curve.js';
|
||||
import { CatmullRom } from '../core/Interpolations.js';
|
||||
import { Vector2 } from '../../math/Vector2.js';
|
||||
|
||||
/**
|
||||
* A curve representing a 2D spline curve.
|
||||
*
|
||||
* ```js
|
||||
* // Create a sine-like wave
|
||||
* const curve = new THREE.SplineCurve( [
|
||||
* new THREE.Vector2( -10, 0 ),
|
||||
* new THREE.Vector2( -5, 5 ),
|
||||
* new THREE.Vector2( 0, 0 ),
|
||||
* new THREE.Vector2( 5, -5 ),
|
||||
* new THREE.Vector2( 10, 0 )
|
||||
* ] );
|
||||
*
|
||||
* const points = curve.getPoints( 50 );
|
||||
* const geometry = new THREE.BufferGeometry().setFromPoints( points );
|
||||
*
|
||||
* const material = new THREE.LineBasicMaterial( { color: 0xff0000 } );
|
||||
*
|
||||
* // Create the final object to add to the scene
|
||||
* const splineObject = new THREE.Line( geometry, material );
|
||||
* ```
|
||||
*
|
||||
* @augments Curve
|
||||
*/
|
||||
class SplineCurve extends Curve {
|
||||
|
||||
/**
|
||||
* Constructs a new 2D spline curve.
|
||||
*
|
||||
* @param {Array<Vector2>} [points] - An array of 2D points defining the curve.
|
||||
*/
|
||||
constructor( points = [] ) {
|
||||
|
||||
super();
|
||||
|
||||
/**
|
||||
* This flag can be used for type testing.
|
||||
*
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
this.isSplineCurve = true;
|
||||
|
||||
this.type = 'SplineCurve';
|
||||
|
||||
/**
|
||||
* An array of 2D points defining the curve.
|
||||
*
|
||||
* @type {Array<Vector2>}
|
||||
*/
|
||||
this.points = points;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point on the curve.
|
||||
*
|
||||
* @param {number} t - A interpolation factor representing a position on the curve. Must be in the range `[0,1]`.
|
||||
* @param {Vector2} [optionalTarget] - The optional target vector the result is written to.
|
||||
* @return {Vector2} The position on the curve.
|
||||
*/
|
||||
getPoint( t, optionalTarget = new Vector2() ) {
|
||||
|
||||
const point = optionalTarget;
|
||||
|
||||
const points = this.points;
|
||||
const p = ( points.length - 1 ) * t;
|
||||
|
||||
const intPoint = Math.floor( p );
|
||||
const weight = p - intPoint;
|
||||
|
||||
const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
|
||||
const p1 = points[ intPoint ];
|
||||
const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
|
||||
const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
|
||||
|
||||
point.set(
|
||||
CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
|
||||
CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
|
||||
);
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.points = [];
|
||||
|
||||
for ( let i = 0, l = source.points.length; i < l; i ++ ) {
|
||||
|
||||
const point = source.points[ i ];
|
||||
|
||||
this.points.push( point.clone() );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.points = [];
|
||||
|
||||
for ( let i = 0, l = this.points.length; i < l; i ++ ) {
|
||||
|
||||
const point = this.points[ i ];
|
||||
data.points.push( point.toArray() );
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
fromJSON( json ) {
|
||||
|
||||
super.fromJSON( json );
|
||||
|
||||
this.points = [];
|
||||
|
||||
for ( let i = 0, l = json.points.length; i < l; i ++ ) {
|
||||
|
||||
const point = json.points[ i ];
|
||||
this.points.push( new Vector2().fromArray( point ) );
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { SplineCurve };
|
||||
685
app/node_modules/three/src/extras/lib/earcut.js
generated
vendored
Normal file
685
app/node_modules/three/src/extras/lib/earcut.js
generated
vendored
Normal file
@@ -0,0 +1,685 @@
|
||||
/* eslint-disable */
|
||||
// copy of mapbox/earcut version 3.0.1
|
||||
// https://github.com/mapbox/earcut/tree/v3.0.1
|
||||
|
||||
export default function earcut(data, holeIndices, dim = 2) {
|
||||
|
||||
const hasHoles = holeIndices && holeIndices.length;
|
||||
const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
||||
let outerNode = linkedList(data, 0, outerLen, dim, true);
|
||||
const triangles = [];
|
||||
|
||||
if (!outerNode || outerNode.next === outerNode.prev) return triangles;
|
||||
|
||||
let minX, minY, invSize;
|
||||
|
||||
if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
|
||||
|
||||
// if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
|
||||
if (data.length > 80 * dim) {
|
||||
minX = Infinity;
|
||||
minY = Infinity;
|
||||
let maxX = -Infinity;
|
||||
let maxY = -Infinity;
|
||||
|
||||
for (let i = dim; i < outerLen; i += dim) {
|
||||
const x = data[i];
|
||||
const y = data[i + 1];
|
||||
if (x < minX) minX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y > maxY) maxY = y;
|
||||
}
|
||||
|
||||
// minX, minY and invSize are later used to transform coords into integers for z-order calculation
|
||||
invSize = Math.max(maxX - minX, maxY - minY);
|
||||
invSize = invSize !== 0 ? 32767 / invSize : 0;
|
||||
}
|
||||
|
||||
earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
|
||||
|
||||
return triangles;
|
||||
}
|
||||
|
||||
// create a circular doubly linked list from polygon points in the specified winding order
|
||||
function linkedList(data, start, end, dim, clockwise) {
|
||||
let last;
|
||||
|
||||
if (clockwise === (signedArea(data, start, end, dim) > 0)) {
|
||||
for (let i = start; i < end; i += dim) last = insertNode(i / dim | 0, data[i], data[i + 1], last);
|
||||
} else {
|
||||
for (let i = end - dim; i >= start; i -= dim) last = insertNode(i / dim | 0, data[i], data[i + 1], last);
|
||||
}
|
||||
|
||||
if (last && equals(last, last.next)) {
|
||||
removeNode(last);
|
||||
last = last.next;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
// eliminate colinear or duplicate points
|
||||
function filterPoints(start, end) {
|
||||
if (!start) return start;
|
||||
if (!end) end = start;
|
||||
|
||||
let p = start,
|
||||
again;
|
||||
do {
|
||||
again = false;
|
||||
|
||||
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
||||
removeNode(p);
|
||||
p = end = p.prev;
|
||||
if (p === p.next) break;
|
||||
again = true;
|
||||
|
||||
} else {
|
||||
p = p.next;
|
||||
}
|
||||
} while (again || p !== end);
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
// main ear slicing loop which triangulates a polygon (given as a linked list)
|
||||
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
||||
if (!ear) return;
|
||||
|
||||
// interlink polygon nodes in z-order
|
||||
if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
|
||||
|
||||
let stop = ear;
|
||||
|
||||
// iterate through ears, slicing them one by one
|
||||
while (ear.prev !== ear.next) {
|
||||
const prev = ear.prev;
|
||||
const next = ear.next;
|
||||
|
||||
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
||||
triangles.push(prev.i, ear.i, next.i); // cut off the triangle
|
||||
|
||||
removeNode(ear);
|
||||
|
||||
// skipping the next vertex leads to less sliver triangles
|
||||
ear = next.next;
|
||||
stop = next.next;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
ear = next;
|
||||
|
||||
// if we looped through the whole remaining polygon and can't find any more ears
|
||||
if (ear === stop) {
|
||||
// try filtering points and slicing again
|
||||
if (!pass) {
|
||||
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
||||
|
||||
// if this didn't work, try curing all small self-intersections locally
|
||||
} else if (pass === 1) {
|
||||
ear = cureLocalIntersections(filterPoints(ear), triangles);
|
||||
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
||||
|
||||
// as a last resort, try splitting the remaining polygon into two
|
||||
} else if (pass === 2) {
|
||||
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check whether a polygon node forms a valid ear with adjacent nodes
|
||||
function isEar(ear) {
|
||||
const a = ear.prev,
|
||||
b = ear,
|
||||
c = ear.next;
|
||||
|
||||
if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
|
||||
|
||||
// now make sure we don't have other points inside the potential ear
|
||||
const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
|
||||
|
||||
// triangle bbox
|
||||
const x0 = Math.min(ax, bx, cx),
|
||||
y0 = Math.min(ay, by, cy),
|
||||
x1 = Math.max(ax, bx, cx),
|
||||
y1 = Math.max(ay, by, cy);
|
||||
|
||||
let p = c.next;
|
||||
while (p !== a) {
|
||||
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&
|
||||
pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) &&
|
||||
area(p.prev, p, p.next) >= 0) return false;
|
||||
p = p.next;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function isEarHashed(ear, minX, minY, invSize) {
|
||||
const a = ear.prev,
|
||||
b = ear,
|
||||
c = ear.next;
|
||||
|
||||
if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
|
||||
|
||||
const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
|
||||
|
||||
// triangle bbox
|
||||
const x0 = Math.min(ax, bx, cx),
|
||||
y0 = Math.min(ay, by, cy),
|
||||
x1 = Math.max(ax, bx, cx),
|
||||
y1 = Math.max(ay, by, cy);
|
||||
|
||||
// z-order range for the current triangle bbox;
|
||||
const minZ = zOrder(x0, y0, minX, minY, invSize),
|
||||
maxZ = zOrder(x1, y1, minX, minY, invSize);
|
||||
|
||||
let p = ear.prevZ,
|
||||
n = ear.nextZ;
|
||||
|
||||
// look for points inside the triangle in both directions
|
||||
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
||||
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
|
||||
pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
|
||||
p = p.prevZ;
|
||||
|
||||
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
|
||||
pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
|
||||
n = n.nextZ;
|
||||
}
|
||||
|
||||
// look for remaining points in decreasing z-order
|
||||
while (p && p.z >= minZ) {
|
||||
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
|
||||
pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
|
||||
p = p.prevZ;
|
||||
}
|
||||
|
||||
// look for remaining points in increasing z-order
|
||||
while (n && n.z <= maxZ) {
|
||||
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
|
||||
pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
|
||||
n = n.nextZ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// go through all polygon nodes and cure small local self-intersections
|
||||
function cureLocalIntersections(start, triangles) {
|
||||
let p = start;
|
||||
do {
|
||||
const a = p.prev,
|
||||
b = p.next.next;
|
||||
|
||||
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
||||
|
||||
triangles.push(a.i, p.i, b.i);
|
||||
|
||||
// remove two nodes involved
|
||||
removeNode(p);
|
||||
removeNode(p.next);
|
||||
|
||||
p = start = b;
|
||||
}
|
||||
p = p.next;
|
||||
} while (p !== start);
|
||||
|
||||
return filterPoints(p);
|
||||
}
|
||||
|
||||
// try splitting polygon into two and triangulate them independently
|
||||
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
||||
// look for a valid diagonal that divides the polygon into two
|
||||
let a = start;
|
||||
do {
|
||||
let b = a.next.next;
|
||||
while (b !== a.prev) {
|
||||
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
||||
// split the polygon in two by the diagonal
|
||||
let c = splitPolygon(a, b);
|
||||
|
||||
// filter colinear points around the cuts
|
||||
a = filterPoints(a, a.next);
|
||||
c = filterPoints(c, c.next);
|
||||
|
||||
// run earcut on each half
|
||||
earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
|
||||
earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
|
||||
return;
|
||||
}
|
||||
b = b.next;
|
||||
}
|
||||
a = a.next;
|
||||
} while (a !== start);
|
||||
}
|
||||
|
||||
// link every hole into the outer loop, producing a single-ring polygon without holes
|
||||
function eliminateHoles(data, holeIndices, outerNode, dim) {
|
||||
const queue = [];
|
||||
|
||||
for (let i = 0, len = holeIndices.length; i < len; i++) {
|
||||
const start = holeIndices[i] * dim;
|
||||
const end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
||||
const list = linkedList(data, start, end, dim, false);
|
||||
if (list === list.next) list.steiner = true;
|
||||
queue.push(getLeftmost(list));
|
||||
}
|
||||
|
||||
queue.sort(compareXYSlope);
|
||||
|
||||
// process holes from left to right
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
outerNode = eliminateHole(queue[i], outerNode);
|
||||
}
|
||||
|
||||
return outerNode;
|
||||
}
|
||||
|
||||
function compareXYSlope(a, b) {
|
||||
let result = a.x - b.x;
|
||||
// when the left-most point of 2 holes meet at a vertex, sort the holes counterclockwise so that when we find
|
||||
// the bridge to the outer shell is always the point that they meet at.
|
||||
if (result === 0) {
|
||||
result = a.y - b.y;
|
||||
if (result === 0) {
|
||||
const aSlope = (a.next.y - a.y) / (a.next.x - a.x);
|
||||
const bSlope = (b.next.y - b.y) / (b.next.x - b.x);
|
||||
result = aSlope - bSlope;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// find a bridge between vertices that connects hole with an outer ring and and link it
|
||||
function eliminateHole(hole, outerNode) {
|
||||
const bridge = findHoleBridge(hole, outerNode);
|
||||
if (!bridge) {
|
||||
return outerNode;
|
||||
}
|
||||
|
||||
const bridgeReverse = splitPolygon(bridge, hole);
|
||||
|
||||
// filter collinear points around the cuts
|
||||
filterPoints(bridgeReverse, bridgeReverse.next);
|
||||
return filterPoints(bridge, bridge.next);
|
||||
}
|
||||
|
||||
// David Eberly's algorithm for finding a bridge between hole and outer polygon
|
||||
function findHoleBridge(hole, outerNode) {
|
||||
let p = outerNode;
|
||||
const hx = hole.x;
|
||||
const hy = hole.y;
|
||||
let qx = -Infinity;
|
||||
let m;
|
||||
|
||||
// find a segment intersected by a ray from the hole's leftmost point to the left;
|
||||
// segment's endpoint with lesser x will be potential connection point
|
||||
// unless they intersect at a vertex, then choose the vertex
|
||||
if (equals(hole, p)) return p;
|
||||
do {
|
||||
if (equals(hole, p.next)) return p.next;
|
||||
else if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
||||
const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
||||
if (x <= hx && x > qx) {
|
||||
qx = x;
|
||||
m = p.x < p.next.x ? p : p.next;
|
||||
if (x === hx) return m; // hole touches outer segment; pick leftmost endpoint
|
||||
}
|
||||
}
|
||||
p = p.next;
|
||||
} while (p !== outerNode);
|
||||
|
||||
if (!m) return null;
|
||||
|
||||
// look for points inside the triangle of hole point, segment intersection and endpoint;
|
||||
// if there are no points found, we have a valid connection;
|
||||
// otherwise choose the point of the minimum angle with the ray as connection point
|
||||
|
||||
const stop = m;
|
||||
const mx = m.x;
|
||||
const my = m.y;
|
||||
let tanMin = Infinity;
|
||||
|
||||
p = m;
|
||||
|
||||
do {
|
||||
if (hx >= p.x && p.x >= mx && hx !== p.x &&
|
||||
pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
||||
|
||||
const tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
|
||||
|
||||
if (locallyInside(p, hole) &&
|
||||
(tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) {
|
||||
m = p;
|
||||
tanMin = tan;
|
||||
}
|
||||
}
|
||||
|
||||
p = p.next;
|
||||
} while (p !== stop);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
// whether sector in vertex m contains sector in vertex p in the same coordinates
|
||||
function sectorContainsSector(m, p) {
|
||||
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
||||
}
|
||||
|
||||
// interlink polygon nodes in z-order
|
||||
function indexCurve(start, minX, minY, invSize) {
|
||||
let p = start;
|
||||
do {
|
||||
if (p.z === 0) p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
||||
p.prevZ = p.prev;
|
||||
p.nextZ = p.next;
|
||||
p = p.next;
|
||||
} while (p !== start);
|
||||
|
||||
p.prevZ.nextZ = null;
|
||||
p.prevZ = null;
|
||||
|
||||
sortLinked(p);
|
||||
}
|
||||
|
||||
// Simon Tatham's linked list merge sort algorithm
|
||||
// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
|
||||
function sortLinked(list) {
|
||||
let numMerges;
|
||||
let inSize = 1;
|
||||
|
||||
do {
|
||||
let p = list;
|
||||
let e;
|
||||
list = null;
|
||||
let tail = null;
|
||||
numMerges = 0;
|
||||
|
||||
while (p) {
|
||||
numMerges++;
|
||||
let q = p;
|
||||
let pSize = 0;
|
||||
for (let i = 0; i < inSize; i++) {
|
||||
pSize++;
|
||||
q = q.nextZ;
|
||||
if (!q) break;
|
||||
}
|
||||
let qSize = inSize;
|
||||
|
||||
while (pSize > 0 || (qSize > 0 && q)) {
|
||||
|
||||
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
||||
e = p;
|
||||
p = p.nextZ;
|
||||
pSize--;
|
||||
} else {
|
||||
e = q;
|
||||
q = q.nextZ;
|
||||
qSize--;
|
||||
}
|
||||
|
||||
if (tail) tail.nextZ = e;
|
||||
else list = e;
|
||||
|
||||
e.prevZ = tail;
|
||||
tail = e;
|
||||
}
|
||||
|
||||
p = q;
|
||||
}
|
||||
|
||||
tail.nextZ = null;
|
||||
inSize *= 2;
|
||||
|
||||
} while (numMerges > 1);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// z-order of a point given coords and inverse of the longer side of data bbox
|
||||
function zOrder(x, y, minX, minY, invSize) {
|
||||
// coords are transformed into non-negative 15-bit integer range
|
||||
x = (x - minX) * invSize | 0;
|
||||
y = (y - minY) * invSize | 0;
|
||||
|
||||
x = (x | (x << 8)) & 0x00FF00FF;
|
||||
x = (x | (x << 4)) & 0x0F0F0F0F;
|
||||
x = (x | (x << 2)) & 0x33333333;
|
||||
x = (x | (x << 1)) & 0x55555555;
|
||||
|
||||
y = (y | (y << 8)) & 0x00FF00FF;
|
||||
y = (y | (y << 4)) & 0x0F0F0F0F;
|
||||
y = (y | (y << 2)) & 0x33333333;
|
||||
y = (y | (y << 1)) & 0x55555555;
|
||||
|
||||
return x | (y << 1);
|
||||
}
|
||||
|
||||
// find the leftmost node of a polygon ring
|
||||
function getLeftmost(start) {
|
||||
let p = start,
|
||||
leftmost = start;
|
||||
do {
|
||||
if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) leftmost = p;
|
||||
p = p.next;
|
||||
} while (p !== start);
|
||||
|
||||
return leftmost;
|
||||
}
|
||||
|
||||
// check if a point lies within a convex triangle
|
||||
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
||||
return (cx - px) * (ay - py) >= (ax - px) * (cy - py) &&
|
||||
(ax - px) * (by - py) >= (bx - px) * (ay - py) &&
|
||||
(bx - px) * (cy - py) >= (cx - px) * (by - py);
|
||||
}
|
||||
|
||||
// check if a point lies within a convex triangle but false if its equal to the first point of the triangle
|
||||
function pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, px, py) {
|
||||
return !(ax === px && ay === py) && pointInTriangle(ax, ay, bx, by, cx, cy, px, py);
|
||||
}
|
||||
|
||||
// check if a diagonal between two polygon nodes is valid (lies in polygon interior)
|
||||
function isValidDiagonal(a, b) {
|
||||
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges
|
||||
(locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible
|
||||
(area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
|
||||
equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
|
||||
}
|
||||
|
||||
// signed area of a triangle
|
||||
function area(p, q, r) {
|
||||
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
||||
}
|
||||
|
||||
// check if two points are equal
|
||||
function equals(p1, p2) {
|
||||
return p1.x === p2.x && p1.y === p2.y;
|
||||
}
|
||||
|
||||
// check if two segments intersect
|
||||
function intersects(p1, q1, p2, q2) {
|
||||
const o1 = sign(area(p1, q1, p2));
|
||||
const o2 = sign(area(p1, q1, q2));
|
||||
const o3 = sign(area(p2, q2, p1));
|
||||
const o4 = sign(area(p2, q2, q1));
|
||||
|
||||
if (o1 !== o2 && o3 !== o4) return true; // general case
|
||||
|
||||
if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
|
||||
if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
|
||||
if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
|
||||
if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// for collinear points p, q, r, check if point q lies on segment pr
|
||||
function onSegment(p, q, r) {
|
||||
return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
|
||||
}
|
||||
|
||||
function sign(num) {
|
||||
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
// check if a polygon diagonal intersects any polygon segments
|
||||
function intersectsPolygon(a, b) {
|
||||
let p = a;
|
||||
do {
|
||||
if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
|
||||
intersects(p, p.next, a, b)) return true;
|
||||
p = p.next;
|
||||
} while (p !== a);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if a polygon diagonal is locally inside the polygon
|
||||
function locallyInside(a, b) {
|
||||
return area(a.prev, a, a.next) < 0 ?
|
||||
area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :
|
||||
area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
|
||||
}
|
||||
|
||||
// check if the middle point of a polygon diagonal is inside the polygon
|
||||
function middleInside(a, b) {
|
||||
let p = a;
|
||||
let inside = false;
|
||||
const px = (a.x + b.x) / 2;
|
||||
const py = (a.y + b.y) / 2;
|
||||
do {
|
||||
if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
|
||||
(px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
|
||||
inside = !inside;
|
||||
p = p.next;
|
||||
} while (p !== a);
|
||||
|
||||
return inside;
|
||||
}
|
||||
|
||||
// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
|
||||
// if one belongs to the outer ring and another to a hole, it merges it into a single ring
|
||||
function splitPolygon(a, b) {
|
||||
const a2 = createNode(a.i, a.x, a.y),
|
||||
b2 = createNode(b.i, b.x, b.y),
|
||||
an = a.next,
|
||||
bp = b.prev;
|
||||
|
||||
a.next = b;
|
||||
b.prev = a;
|
||||
|
||||
a2.next = an;
|
||||
an.prev = a2;
|
||||
|
||||
b2.next = a2;
|
||||
a2.prev = b2;
|
||||
|
||||
bp.next = b2;
|
||||
b2.prev = bp;
|
||||
|
||||
return b2;
|
||||
}
|
||||
|
||||
// create a node and optionally link it with previous one (in a circular doubly linked list)
|
||||
function insertNode(i, x, y, last) {
|
||||
const p = createNode(i, x, y);
|
||||
|
||||
if (!last) {
|
||||
p.prev = p;
|
||||
p.next = p;
|
||||
|
||||
} else {
|
||||
p.next = last.next;
|
||||
p.prev = last;
|
||||
last.next.prev = p;
|
||||
last.next = p;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
function removeNode(p) {
|
||||
p.next.prev = p.prev;
|
||||
p.prev.next = p.next;
|
||||
|
||||
if (p.prevZ) p.prevZ.nextZ = p.nextZ;
|
||||
if (p.nextZ) p.nextZ.prevZ = p.prevZ;
|
||||
}
|
||||
|
||||
function createNode(i, x, y) {
|
||||
return {
|
||||
i, // vertex index in coordinates array
|
||||
x, y, // vertex coordinates
|
||||
prev: null, // previous and next vertex nodes in a polygon ring
|
||||
next: null,
|
||||
z: 0, // z-order curve value
|
||||
prevZ: null, // previous and next nodes in z-order
|
||||
nextZ: null,
|
||||
steiner: false // indicates whether this is a steiner point
|
||||
};
|
||||
}
|
||||
|
||||
// return a percentage difference between the polygon area and its triangulation area;
|
||||
// used to verify correctness of triangulation
|
||||
export function deviation(data, holeIndices, dim, triangles) {
|
||||
const hasHoles = holeIndices && holeIndices.length;
|
||||
const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
||||
|
||||
let polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
|
||||
if (hasHoles) {
|
||||
for (let i = 0, len = holeIndices.length; i < len; i++) {
|
||||
const start = holeIndices[i] * dim;
|
||||
const end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
||||
polygonArea -= Math.abs(signedArea(data, start, end, dim));
|
||||
}
|
||||
}
|
||||
|
||||
let trianglesArea = 0;
|
||||
for (let i = 0; i < triangles.length; i += 3) {
|
||||
const a = triangles[i] * dim;
|
||||
const b = triangles[i + 1] * dim;
|
||||
const c = triangles[i + 2] * dim;
|
||||
trianglesArea += Math.abs(
|
||||
(data[a] - data[c]) * (data[b + 1] - data[a + 1]) -
|
||||
(data[a] - data[b]) * (data[c + 1] - data[a + 1]));
|
||||
}
|
||||
|
||||
return polygonArea === 0 && trianglesArea === 0 ? 0 :
|
||||
Math.abs((trianglesArea - polygonArea) / polygonArea);
|
||||
}
|
||||
|
||||
function signedArea(data, start, end, dim) {
|
||||
let sum = 0;
|
||||
for (let i = start, j = end - dim; i < end; i += dim) {
|
||||
sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
|
||||
j = i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
|
||||
export function flatten(data) {
|
||||
const vertices = [];
|
||||
const holes = [];
|
||||
const dimensions = data[0][0].length;
|
||||
let holeIndex = 0;
|
||||
let prevLen = 0;
|
||||
|
||||
for (const ring of data) {
|
||||
for (const p of ring) {
|
||||
for (let d = 0; d < dimensions; d++) vertices.push(p[d]);
|
||||
}
|
||||
if (prevLen) {
|
||||
holeIndex += prevLen;
|
||||
holes.push(holeIndex);
|
||||
}
|
||||
prevLen = ring.length;
|
||||
}
|
||||
return {vertices, holes, dimensions};
|
||||
}
|
||||
218
app/node_modules/three/src/geometries/BoxGeometry.js
generated
vendored
Normal file
218
app/node_modules/three/src/geometries/BoxGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* A geometry class for a rectangular cuboid with a given width, height, and depth.
|
||||
* On creation, the cuboid is centred on the origin, with each edge parallel to one
|
||||
* of the axes.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.BoxGeometry( 1, 1, 1 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
|
||||
* const cube = new THREE.Mesh( geometry, material );
|
||||
* scene.add( cube );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class BoxGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new box geometry.
|
||||
*
|
||||
* @param {number} [width=1] - The width. That is, the length of the edges parallel to the X axis.
|
||||
* @param {number} [height=1] - The height. That is, the length of the edges parallel to the Y axis.
|
||||
* @param {number} [depth=1] - The depth. That is, the length of the edges parallel to the Z axis.
|
||||
* @param {number} [widthSegments=1] - Number of segmented rectangular faces along the width of the sides.
|
||||
* @param {number} [heightSegments=1] - Number of segmented rectangular faces along the height of the sides.
|
||||
* @param {number} [depthSegments=1] - Number of segmented rectangular faces along the depth of the sides.
|
||||
*/
|
||||
constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'BoxGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
width: width,
|
||||
height: height,
|
||||
depth: depth,
|
||||
widthSegments: widthSegments,
|
||||
heightSegments: heightSegments,
|
||||
depthSegments: depthSegments
|
||||
};
|
||||
|
||||
const scope = this;
|
||||
|
||||
// segments
|
||||
|
||||
widthSegments = Math.floor( widthSegments );
|
||||
heightSegments = Math.floor( heightSegments );
|
||||
depthSegments = Math.floor( depthSegments );
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
let numberOfVertices = 0;
|
||||
let 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.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
|
||||
|
||||
const segmentWidth = width / gridX;
|
||||
const segmentHeight = height / gridY;
|
||||
|
||||
const widthHalf = width / 2;
|
||||
const heightHalf = height / 2;
|
||||
const depthHalf = depth / 2;
|
||||
|
||||
const gridX1 = gridX + 1;
|
||||
const gridY1 = gridY + 1;
|
||||
|
||||
let vertexCounter = 0;
|
||||
let groupCount = 0;
|
||||
|
||||
const vector = new Vector3();
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( let iy = 0; iy < gridY1; iy ++ ) {
|
||||
|
||||
const y = iy * segmentHeight - heightHalf;
|
||||
|
||||
for ( let ix = 0; ix < gridX1; ix ++ ) {
|
||||
|
||||
const 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 ( let iy = 0; iy < gridY; iy ++ ) {
|
||||
|
||||
for ( let ix = 0; ix < gridX; ix ++ ) {
|
||||
|
||||
const a = numberOfVertices + ix + gridX1 * iy;
|
||||
const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
|
||||
const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {BoxGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { BoxGeometry };
|
||||
217
app/node_modules/three/src/geometries/CapsuleGeometry.js
generated
vendored
Normal file
217
app/node_modules/three/src/geometries/CapsuleGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* A geometry class for representing a capsule.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.CapsuleGeometry( 1, 1, 4, 8, 1 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
|
||||
* const capsule = new THREE.Mesh( geometry, material );
|
||||
* scene.add( capsule );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class CapsuleGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new capsule geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - Radius of the capsule.
|
||||
* @param {number} [height=1] - Height of the middle section.
|
||||
* @param {number} [capSegments=4] - Number of curve segments used to build each cap.
|
||||
* @param {number} [radialSegments=8] - Number of segmented faces around the circumference of the capsule. Must be an integer >= 3.
|
||||
* @param {number} [heightSegments=1] - Number of rows of faces along the height of the middle section. Must be an integer >= 1.
|
||||
*/
|
||||
constructor( radius = 1, height = 1, capSegments = 4, radialSegments = 8, heightSegments = 1 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'CapsuleGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
height: height,
|
||||
capSegments: capSegments,
|
||||
radialSegments: radialSegments,
|
||||
heightSegments: heightSegments,
|
||||
};
|
||||
|
||||
height = Math.max( 0, height );
|
||||
capSegments = Math.max( 1, Math.floor( capSegments ) );
|
||||
radialSegments = Math.max( 3, Math.floor( radialSegments ) );
|
||||
heightSegments = Math.max( 1, Math.floor( heightSegments ) );
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
const halfHeight = height / 2;
|
||||
const capArcLength = ( Math.PI / 2 ) * radius;
|
||||
const cylinderPartLength = height;
|
||||
const totalArcLength = 2 * capArcLength + cylinderPartLength;
|
||||
|
||||
const numVerticalSegments = capSegments * 2 + heightSegments;
|
||||
const verticesPerRow = radialSegments + 1;
|
||||
|
||||
const normal = new Vector3();
|
||||
const vertex = new Vector3();
|
||||
|
||||
// generate vertices, normals, and uvs
|
||||
|
||||
for ( let iy = 0; iy <= numVerticalSegments; iy ++ ) {
|
||||
|
||||
let currentArcLength = 0;
|
||||
let profileY = 0;
|
||||
let profileRadius = 0;
|
||||
let normalYComponent = 0;
|
||||
|
||||
if ( iy <= capSegments ) {
|
||||
|
||||
// bottom cap
|
||||
const segmentProgress = iy / capSegments;
|
||||
const angle = ( segmentProgress * Math.PI ) / 2;
|
||||
profileY = - halfHeight - radius * Math.cos( angle );
|
||||
profileRadius = radius * Math.sin( angle );
|
||||
normalYComponent = - radius * Math.cos( angle );
|
||||
currentArcLength = segmentProgress * capArcLength;
|
||||
|
||||
} else if ( iy <= capSegments + heightSegments ) {
|
||||
|
||||
// middle section
|
||||
const segmentProgress = ( iy - capSegments ) / heightSegments;
|
||||
profileY = - halfHeight + segmentProgress * height;
|
||||
profileRadius = radius;
|
||||
normalYComponent = 0;
|
||||
currentArcLength = capArcLength + segmentProgress * cylinderPartLength;
|
||||
|
||||
} else {
|
||||
|
||||
// top cap
|
||||
const segmentProgress =
|
||||
( iy - capSegments - heightSegments ) / capSegments;
|
||||
const angle = ( segmentProgress * Math.PI ) / 2;
|
||||
profileY = halfHeight + radius * Math.sin( angle );
|
||||
profileRadius = radius * Math.cos( angle );
|
||||
normalYComponent = radius * Math.sin( angle );
|
||||
currentArcLength =
|
||||
capArcLength + cylinderPartLength + segmentProgress * capArcLength;
|
||||
|
||||
}
|
||||
|
||||
const v = Math.max( 0, Math.min( 1, currentArcLength / totalArcLength ) );
|
||||
|
||||
|
||||
// special case for the poles
|
||||
|
||||
let uOffset = 0;
|
||||
|
||||
if ( iy === 0 ) {
|
||||
|
||||
uOffset = 0.5 / radialSegments;
|
||||
|
||||
} else if ( iy === numVerticalSegments ) {
|
||||
|
||||
uOffset = - 0.5 / radialSegments;
|
||||
|
||||
}
|
||||
|
||||
for ( let ix = 0; ix <= radialSegments; ix ++ ) {
|
||||
|
||||
const u = ix / radialSegments;
|
||||
const theta = u * Math.PI * 2;
|
||||
|
||||
const sinTheta = Math.sin( theta );
|
||||
const cosTheta = Math.cos( theta );
|
||||
|
||||
// vertex
|
||||
|
||||
vertex.x = - profileRadius * cosTheta;
|
||||
vertex.y = profileY;
|
||||
vertex.z = profileRadius * sinTheta;
|
||||
vertices.push( vertex.x, vertex.y, vertex.z );
|
||||
|
||||
// normal
|
||||
|
||||
normal.set(
|
||||
- profileRadius * cosTheta,
|
||||
normalYComponent,
|
||||
profileRadius * sinTheta
|
||||
);
|
||||
normal.normalize();
|
||||
normals.push( normal.x, normal.y, normal.z );
|
||||
|
||||
// uv
|
||||
|
||||
uvs.push( u + uOffset, v );
|
||||
|
||||
}
|
||||
|
||||
if ( iy > 0 ) {
|
||||
|
||||
const prevIndexRow = ( iy - 1 ) * verticesPerRow;
|
||||
for ( let ix = 0; ix < radialSegments; ix ++ ) {
|
||||
|
||||
const i1 = prevIndexRow + ix;
|
||||
const i2 = prevIndexRow + ix + 1;
|
||||
const i3 = iy * verticesPerRow + ix;
|
||||
const i4 = iy * verticesPerRow + ix + 1;
|
||||
|
||||
indices.push( i1, i2, i3 );
|
||||
indices.push( i2, i4, i3 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {CapsuleGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new CapsuleGeometry( data.radius, data.height, data.capSegments, data.radialSegments, data.heightSegments );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { CapsuleGeometry };
|
||||
141
app/node_modules/three/src/geometries/CircleGeometry.js
generated
vendored
Normal file
141
app/node_modules/three/src/geometries/CircleGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
|
||||
/**
|
||||
* A simple shape of Euclidean geometry. It is constructed from a
|
||||
* number of triangular segments that are oriented around a central point and
|
||||
* extend as far out as a given radius. It is built counter-clockwise from a
|
||||
* start angle and a given central angle. It can also be used to create
|
||||
* regular polygons, where the number of segments determines the number of
|
||||
* sides.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.CircleGeometry( 5, 32 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const circle = new THREE.Mesh( geometry, material );
|
||||
* scene.add( circle )
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class CircleGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new circle geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - Radius of the circle.
|
||||
* @param {number} [segments=32] - Number of segments (triangles), minimum = `3`.
|
||||
* @param {number} [thetaStart=0] - Start angle for first segment in radians.
|
||||
* @param {number} [thetaLength=Math.PI*2] - The central angle, often called theta,
|
||||
* of the circular sector in radians. The default value results in a complete circle.
|
||||
*/
|
||||
constructor( radius = 1, segments = 32, thetaStart = 0, thetaLength = Math.PI * 2 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'CircleGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
segments: segments,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
segments = Math.max( 3, segments );
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
const vertex = new Vector3();
|
||||
const uv = new Vector2();
|
||||
|
||||
// center point
|
||||
|
||||
vertices.push( 0, 0, 0 );
|
||||
normals.push( 0, 0, 1 );
|
||||
uvs.push( 0.5, 0.5 );
|
||||
|
||||
for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
|
||||
|
||||
const 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 ( let i = 1; i <= segments; i ++ ) {
|
||||
|
||||
indices.push( i, i + 1, 0 );
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {CircleGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { CircleGeometry };
|
||||
69
app/node_modules/three/src/geometries/ConeGeometry.js
generated
vendored
Normal file
69
app/node_modules/three/src/geometries/ConeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import { CylinderGeometry } from './CylinderGeometry.js';
|
||||
|
||||
/**
|
||||
* A geometry class for representing a cone.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.ConeGeometry( 5, 20, 32 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const cone = new THREE.Mesh(geometry, material );
|
||||
* scene.add( cone );
|
||||
* ```
|
||||
*
|
||||
* @augments CylinderGeometry
|
||||
*/
|
||||
class ConeGeometry extends CylinderGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new cone geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - Radius of the cone base.
|
||||
* @param {number} [height=1] - Height of the cone.
|
||||
* @param {number} [radialSegments=32] - Number of segmented faces around the circumference of the cone.
|
||||
* @param {number} [heightSegments=1] - Number of rows of faces along the height of the cone.
|
||||
* @param {boolean} [openEnded=false] - Whether the base of the cone is open or capped.
|
||||
* @param {number} [thetaStart=0] - Start angle for first segment, in radians.
|
||||
* @param {number} [thetaLength=Math.PI*2] - The central angle, often called theta, of the circular sector, in radians.
|
||||
* The default value results in a complete cone.
|
||||
*/
|
||||
constructor( radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
|
||||
|
||||
super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
|
||||
|
||||
this.type = 'ConeGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
height: height,
|
||||
radialSegments: radialSegments,
|
||||
heightSegments: heightSegments,
|
||||
openEnded: openEnded,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {ConeGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { ConeGeometry };
|
||||
332
app/node_modules/three/src/geometries/CylinderGeometry.js
generated
vendored
Normal file
332
app/node_modules/three/src/geometries/CylinderGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,332 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
|
||||
/**
|
||||
* A geometry class for representing a cylinder.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.CylinderGeometry( 5, 5, 20, 32 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const cylinder = new THREE.Mesh( geometry, material );
|
||||
* scene.add( cylinder );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class CylinderGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new cylinder geometry.
|
||||
*
|
||||
* @param {number} [radiusTop=1] - Radius of the cylinder at the top.
|
||||
* @param {number} [radiusBottom=1] - Radius of the cylinder at the bottom.
|
||||
* @param {number} [height=1] - Height of the cylinder.
|
||||
* @param {number} [radialSegments=32] - Number of segmented faces around the circumference of the cylinder.
|
||||
* @param {number} [heightSegments=1] - Number of rows of faces along the height of the cylinder.
|
||||
* @param {boolean} [openEnded=false] - Whether the base of the cylinder is open or capped.
|
||||
* @param {number} [thetaStart=0] - Start angle for first segment, in radians.
|
||||
* @param {number} [thetaLength=Math.PI*2] - The central angle, often called theta, of the circular sector, in radians.
|
||||
* The default value results in a complete cylinder.
|
||||
*/
|
||||
constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'CylinderGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radiusTop: radiusTop,
|
||||
radiusBottom: radiusBottom,
|
||||
height: height,
|
||||
radialSegments: radialSegments,
|
||||
heightSegments: heightSegments,
|
||||
openEnded: openEnded,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
const scope = this;
|
||||
|
||||
radialSegments = Math.floor( radialSegments );
|
||||
heightSegments = Math.floor( heightSegments );
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
let index = 0;
|
||||
const indexArray = [];
|
||||
const halfHeight = height / 2;
|
||||
let groupStart = 0;
|
||||
|
||||
// generate geometry
|
||||
|
||||
generateTorso();
|
||||
|
||||
if ( openEnded === false ) {
|
||||
|
||||
if ( radiusTop > 0 ) generateCap( true );
|
||||
if ( radiusBottom > 0 ) generateCap( false );
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
function generateTorso() {
|
||||
|
||||
const normal = new Vector3();
|
||||
const vertex = new Vector3();
|
||||
|
||||
let groupCount = 0;
|
||||
|
||||
// this will be used to calculate the normal
|
||||
const slope = ( radiusBottom - radiusTop ) / height;
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( let y = 0; y <= heightSegments; y ++ ) {
|
||||
|
||||
const indexRow = [];
|
||||
|
||||
const v = y / heightSegments;
|
||||
|
||||
// calculate the radius of the current row
|
||||
|
||||
const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
|
||||
|
||||
for ( let x = 0; x <= radialSegments; x ++ ) {
|
||||
|
||||
const u = x / radialSegments;
|
||||
|
||||
const theta = u * thetaLength + thetaStart;
|
||||
|
||||
const sinTheta = Math.sin( theta );
|
||||
const 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 ( let x = 0; x < radialSegments; x ++ ) {
|
||||
|
||||
for ( let y = 0; y < heightSegments; y ++ ) {
|
||||
|
||||
// we use the index array to access the correct indices
|
||||
|
||||
const a = indexArray[ y ][ x ];
|
||||
const b = indexArray[ y + 1 ][ x ];
|
||||
const c = indexArray[ y + 1 ][ x + 1 ];
|
||||
const d = indexArray[ y ][ x + 1 ];
|
||||
|
||||
// faces
|
||||
|
||||
if ( radiusTop > 0 || y !== 0 ) {
|
||||
|
||||
indices.push( a, b, d );
|
||||
groupCount += 3;
|
||||
|
||||
}
|
||||
|
||||
if ( radiusBottom > 0 || y !== heightSegments - 1 ) {
|
||||
|
||||
indices.push( b, c, d );
|
||||
groupCount += 3;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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 ) {
|
||||
|
||||
// save the index of the first center vertex
|
||||
const centerIndexStart = index;
|
||||
|
||||
const uv = new Vector2();
|
||||
const vertex = new Vector3();
|
||||
|
||||
let groupCount = 0;
|
||||
|
||||
const radius = ( top === true ) ? radiusTop : radiusBottom;
|
||||
const sign = ( top === true ) ? 1 : - 1;
|
||||
|
||||
// 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 ( let 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
|
||||
const centerIndexEnd = index;
|
||||
|
||||
// now we generate the surrounding vertices, normals and uvs
|
||||
|
||||
for ( let x = 0; x <= radialSegments; x ++ ) {
|
||||
|
||||
const u = x / radialSegments;
|
||||
const theta = u * thetaLength + thetaStart;
|
||||
|
||||
const cosTheta = Math.cos( theta );
|
||||
const 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 ( let x = 0; x < radialSegments; x ++ ) {
|
||||
|
||||
const c = centerIndexStart + x;
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {CylinderGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { CylinderGeometry };
|
||||
98
app/node_modules/three/src/geometries/DodecahedronGeometry.js
generated
vendored
Normal file
98
app/node_modules/three/src/geometries/DodecahedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
import { PolyhedronGeometry } from './PolyhedronGeometry.js';
|
||||
|
||||
/**
|
||||
* A geometry class for representing a dodecahedron.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.DodecahedronGeometry();
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const dodecahedron = new THREE.Mesh( geometry, material );
|
||||
* scene.add( dodecahedron );
|
||||
* ```
|
||||
*
|
||||
* @augments PolyhedronGeometry
|
||||
*/
|
||||
class DodecahedronGeometry extends PolyhedronGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new dodecahedron geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - Radius of the dodecahedron.
|
||||
* @param {number} [detail=0] - Setting this to a value greater than `0` adds vertices making it no longer a dodecahedron.
|
||||
*/
|
||||
constructor( radius = 1, detail = 0 ) {
|
||||
|
||||
const t = ( 1 + Math.sqrt( 5 ) ) / 2;
|
||||
const r = 1 / t;
|
||||
|
||||
const 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
|
||||
];
|
||||
|
||||
const 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
|
||||
];
|
||||
|
||||
super( vertices, indices, radius, detail );
|
||||
|
||||
this.type = 'DodecahedronGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {DodecahedronGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new DodecahedronGeometry( data.radius, data.detail );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { DodecahedronGeometry };
|
||||
180
app/node_modules/three/src/geometries/EdgesGeometry.js
generated
vendored
Normal file
180
app/node_modules/three/src/geometries/EdgesGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { DEG2RAD } from '../math/MathUtils.js';
|
||||
import { Triangle } from '../math/Triangle.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
const _v0 = /*@__PURE__*/ new Vector3();
|
||||
const _v1 = /*@__PURE__*/ new Vector3();
|
||||
const _normal = /*@__PURE__*/ new Vector3();
|
||||
const _triangle = /*@__PURE__*/ new Triangle();
|
||||
|
||||
/**
|
||||
* Can be used as a helper object to view the edges of a geometry.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.BoxGeometry();
|
||||
* const edges = new THREE.EdgesGeometry( geometry );
|
||||
* const line = new THREE.LineSegments( edges );
|
||||
* scene.add( line );
|
||||
* ```
|
||||
*
|
||||
* Note: It is not yet possible to serialize/deserialize instances of this class.
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class EdgesGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new edges geometry.
|
||||
*
|
||||
* @param {?BufferGeometry} [geometry=null] - The geometry.
|
||||
* @param {number} [thresholdAngle=1] - An edge is only rendered if the angle (in degrees)
|
||||
* between the face normals of the adjoining faces exceeds this value.
|
||||
*/
|
||||
constructor( geometry = null, thresholdAngle = 1 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'EdgesGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
geometry: geometry,
|
||||
thresholdAngle: thresholdAngle
|
||||
};
|
||||
|
||||
if ( geometry !== null ) {
|
||||
|
||||
const precisionPoints = 4;
|
||||
const precision = Math.pow( 10, precisionPoints );
|
||||
const thresholdDot = Math.cos( DEG2RAD * thresholdAngle );
|
||||
|
||||
const indexAttr = geometry.getIndex();
|
||||
const positionAttr = geometry.getAttribute( 'position' );
|
||||
const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
|
||||
|
||||
const indexArr = [ 0, 0, 0 ];
|
||||
const vertKeys = [ 'a', 'b', 'c' ];
|
||||
const hashes = new Array( 3 );
|
||||
|
||||
const edgeData = {};
|
||||
const vertices = [];
|
||||
for ( let i = 0; i < indexCount; i += 3 ) {
|
||||
|
||||
if ( indexAttr ) {
|
||||
|
||||
indexArr[ 0 ] = indexAttr.getX( i );
|
||||
indexArr[ 1 ] = indexAttr.getX( i + 1 );
|
||||
indexArr[ 2 ] = indexAttr.getX( i + 2 );
|
||||
|
||||
} else {
|
||||
|
||||
indexArr[ 0 ] = i;
|
||||
indexArr[ 1 ] = i + 1;
|
||||
indexArr[ 2 ] = i + 2;
|
||||
|
||||
}
|
||||
|
||||
const { a, b, c } = _triangle;
|
||||
a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
|
||||
b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
|
||||
c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
|
||||
_triangle.getNormal( _normal );
|
||||
|
||||
// create hashes for the edge from the vertices
|
||||
hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
|
||||
hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
|
||||
hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
|
||||
|
||||
// skip degenerate triangles
|
||||
if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
// iterate over every edge
|
||||
for ( let j = 0; j < 3; j ++ ) {
|
||||
|
||||
// get the first and next vertex making up the edge
|
||||
const jNext = ( j + 1 ) % 3;
|
||||
const vecHash0 = hashes[ j ];
|
||||
const vecHash1 = hashes[ jNext ];
|
||||
const v0 = _triangle[ vertKeys[ j ] ];
|
||||
const v1 = _triangle[ vertKeys[ jNext ] ];
|
||||
|
||||
const hash = `${ vecHash0 }_${ vecHash1 }`;
|
||||
const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
|
||||
|
||||
if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
|
||||
|
||||
// if we found a sibling edge add it into the vertex array if
|
||||
// it meets the angle threshold and delete the edge from the map.
|
||||
if ( _normal.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
|
||||
|
||||
vertices.push( v0.x, v0.y, v0.z );
|
||||
vertices.push( v1.x, v1.y, v1.z );
|
||||
|
||||
}
|
||||
|
||||
edgeData[ reverseHash ] = null;
|
||||
|
||||
} else if ( ! ( hash in edgeData ) ) {
|
||||
|
||||
// if we've already got an edge here then skip adding a new one
|
||||
edgeData[ hash ] = {
|
||||
|
||||
index0: indexArr[ j ],
|
||||
index1: indexArr[ jNext ],
|
||||
normal: _normal.clone(),
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// iterate over all remaining, unmatched edges and add them to the vertex array
|
||||
for ( const key in edgeData ) {
|
||||
|
||||
if ( edgeData[ key ] ) {
|
||||
|
||||
const { index0, index1 } = edgeData[ key ];
|
||||
_v0.fromBufferAttribute( positionAttr, index0 );
|
||||
_v1.fromBufferAttribute( positionAttr, index1 );
|
||||
|
||||
vertices.push( _v0.x, _v0.y, _v0.z );
|
||||
vertices.push( _v1.x, _v1.y, _v1.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { EdgesGeometry };
|
||||
908
app/node_modules/three/src/geometries/ExtrudeGeometry.js
generated
vendored
Normal file
908
app/node_modules/three/src/geometries/ExtrudeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,908 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import * as Curves from '../extras/curves/Curves.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Shape } from '../extras/core/Shape.js';
|
||||
import { ShapeUtils } from '../extras/ShapeUtils.js';
|
||||
|
||||
/**
|
||||
* Creates extruded geometry from a path shape.
|
||||
*
|
||||
* ```js
|
||||
* const length = 12, width = 8;
|
||||
*
|
||||
* const shape = new THREE.Shape();
|
||||
* shape.moveTo( 0,0 );
|
||||
* shape.lineTo( 0, width );
|
||||
* shape.lineTo( length, width );
|
||||
* shape.lineTo( length, 0 );
|
||||
* shape.lineTo( 0, 0 );
|
||||
*
|
||||
* const geometry = new THREE.ExtrudeGeometry( shape );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
|
||||
* const mesh = new THREE.Mesh( geometry, material ) ;
|
||||
* scene.add( mesh );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class ExtrudeGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new extrude geometry.
|
||||
*
|
||||
* @param {Shape|Array<Shape>} [shapes] - A shape or an array of shapes.
|
||||
* @param {ExtrudeGeometry~Options} [options] - The extrude settings.
|
||||
*/
|
||||
constructor( shapes = new Shape( [ new Vector2( 0.5, 0.5 ), new Vector2( - 0.5, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), options = {} ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'ExtrudeGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
shapes: shapes,
|
||||
options: options
|
||||
};
|
||||
|
||||
shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
|
||||
|
||||
const scope = this;
|
||||
|
||||
const verticesArray = [];
|
||||
const uvArray = [];
|
||||
|
||||
for ( let i = 0, l = shapes.length; i < l; i ++ ) {
|
||||
|
||||
const shape = shapes[ i ];
|
||||
addShape( shape );
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
|
||||
|
||||
this.computeVertexNormals();
|
||||
|
||||
// functions
|
||||
|
||||
function addShape( shape ) {
|
||||
|
||||
const placeholder = [];
|
||||
|
||||
// options
|
||||
|
||||
const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
|
||||
const steps = options.steps !== undefined ? options.steps : 1;
|
||||
const depth = options.depth !== undefined ? options.depth : 1;
|
||||
|
||||
let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
|
||||
let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 0.2;
|
||||
let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 0.1;
|
||||
let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
|
||||
let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
|
||||
|
||||
const extrudePath = options.extrudePath;
|
||||
|
||||
const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
|
||||
|
||||
//
|
||||
|
||||
let extrudePts, extrudeByPath = false;
|
||||
let 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 = 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;
|
||||
bevelOffset = 0;
|
||||
|
||||
}
|
||||
|
||||
// Variables initialization
|
||||
|
||||
const shapePoints = shape.extractPoints( curveSegments );
|
||||
|
||||
let vertices = shapePoints.shape;
|
||||
const holes = shapePoints.holes;
|
||||
|
||||
const 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 ( let h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
const ahole = holes[ h ];
|
||||
|
||||
if ( ShapeUtils.isClockWise( ahole ) ) {
|
||||
|
||||
holes[ h ] = ahole.reverse();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**Merges index-adjacent points that are within a threshold distance of each other. Array is modified in-place. Threshold distance is empirical, and scaled based on the magnitude of point coordinates.
|
||||
* @param {Array<Vector2>} points
|
||||
*/
|
||||
function mergeOverlappingPoints( points ) {
|
||||
|
||||
const THRESHOLD = 1e-10;
|
||||
const THRESHOLD_SQ = THRESHOLD * THRESHOLD;
|
||||
let prevPos = points[ 0 ];
|
||||
for ( let i = 1; i <= points.length; i ++ ) {
|
||||
|
||||
const currentIndex = i % points.length;
|
||||
const currentPos = points[ currentIndex ];
|
||||
const dx = currentPos.x - prevPos.x;
|
||||
const dy = currentPos.y - prevPos.y;
|
||||
const distSq = dx * dx + dy * dy;
|
||||
|
||||
const scalingFactorSqrt = Math.max(
|
||||
Math.abs( currentPos.x ),
|
||||
Math.abs( currentPos.y ),
|
||||
Math.abs( prevPos.x ),
|
||||
Math.abs( prevPos.y )
|
||||
);
|
||||
const thresholdSqScaled = THRESHOLD_SQ * scalingFactorSqrt * scalingFactorSqrt;
|
||||
if ( distSq <= thresholdSqScaled ) {
|
||||
|
||||
points.splice( currentIndex, 1 );
|
||||
i --;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
prevPos = currentPos;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mergeOverlappingPoints( vertices );
|
||||
holes.forEach( mergeOverlappingPoints );
|
||||
|
||||
const numHoles = holes.length;
|
||||
|
||||
/* Vertices */
|
||||
|
||||
const contour = vertices; // vertices has all points but contour has only points of circumference
|
||||
|
||||
for ( let h = 0; h < numHoles; h ++ ) {
|
||||
|
||||
const ahole = holes[ h ];
|
||||
|
||||
vertices = vertices.concat( ahole );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function scalePt2( pt, vec, size ) {
|
||||
|
||||
if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
|
||||
|
||||
return pt.clone().addScaledVector( vec, size );
|
||||
|
||||
}
|
||||
|
||||
const vlen = vertices.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.
|
||||
|
||||
let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
|
||||
|
||||
// good reading for geometry algorithms (here: line-line intersection)
|
||||
// http://geomalgorithms.com/a05-_intersect-1.html
|
||||
|
||||
const v_prev_x = inPt.x - inPrev.x,
|
||||
v_prev_y = inPt.y - inPrev.y;
|
||||
const v_next_x = inNext.x - inPt.x,
|
||||
v_next_y = inNext.y - inPt.y;
|
||||
|
||||
const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
|
||||
|
||||
// check for collinear edges
|
||||
const 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
|
||||
|
||||
const v_prev_len = Math.sqrt( v_prev_lensq );
|
||||
const 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
|
||||
|
||||
const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
|
||||
const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
|
||||
|
||||
const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
|
||||
const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
|
||||
|
||||
// scaling factor for v_prev to intersection point
|
||||
|
||||
const 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
|
||||
const 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
|
||||
|
||||
let 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 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
const contourMovements = [];
|
||||
|
||||
for ( let 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 ] );
|
||||
|
||||
}
|
||||
|
||||
const holesMovements = [];
|
||||
let oneHoleMovements, verticesMovements = contourMovements.concat();
|
||||
|
||||
for ( let h = 0, hl = numHoles; h < hl; h ++ ) {
|
||||
|
||||
const ahole = holes[ h ];
|
||||
|
||||
oneHoleMovements = [];
|
||||
|
||||
for ( let 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 );
|
||||
|
||||
}
|
||||
|
||||
let faces;
|
||||
|
||||
if ( bevelSegments === 0 ) {
|
||||
|
||||
faces = ShapeUtils.triangulateShape( contour, holes );
|
||||
|
||||
} else {
|
||||
|
||||
const contractedContourVertices = [];
|
||||
const expandedHoleVertices = [];
|
||||
|
||||
// Loop bevelSegments, 1 for the front, 1 for the back
|
||||
|
||||
for ( let b = 0; b < bevelSegments; b ++ ) {
|
||||
|
||||
//for ( b = bevelSegments; b > 0; b -- ) {
|
||||
|
||||
const t = b / bevelSegments;
|
||||
const z = bevelThickness * Math.cos( t * Math.PI / 2 );
|
||||
const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
|
||||
|
||||
// contract shape
|
||||
|
||||
for ( let i = 0, il = contour.length; i < il; i ++ ) {
|
||||
|
||||
const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
|
||||
|
||||
v( vert.x, vert.y, - z );
|
||||
if ( t === 0 ) contractedContourVertices.push( vert );
|
||||
|
||||
}
|
||||
|
||||
// expand holes
|
||||
|
||||
for ( let h = 0, hl = numHoles; h < hl; h ++ ) {
|
||||
|
||||
const ahole = holes[ h ];
|
||||
oneHoleMovements = holesMovements[ h ];
|
||||
const oneHoleVertices = [];
|
||||
for ( let i = 0, il = ahole.length; i < il; i ++ ) {
|
||||
|
||||
const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
|
||||
|
||||
v( vert.x, vert.y, - z );
|
||||
if ( t === 0 ) oneHoleVertices.push( vert );
|
||||
|
||||
}
|
||||
|
||||
if ( t === 0 ) expandedHoleVertices.push( oneHoleVertices );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
faces = ShapeUtils.triangulateShape( contractedContourVertices, expandedHoleVertices );
|
||||
|
||||
}
|
||||
|
||||
const flen = faces.length;
|
||||
|
||||
const bs = bevelSize + bevelOffset;
|
||||
|
||||
// Back facing vertices
|
||||
|
||||
for ( let i = 0; i < vlen; i ++ ) {
|
||||
|
||||
const 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
|
||||
|
||||
for ( let s = 1; s <= steps; s ++ ) {
|
||||
|
||||
for ( let i = 0; i < vlen; i ++ ) {
|
||||
|
||||
const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
|
||||
|
||||
if ( ! extrudeByPath ) {
|
||||
|
||||
v( vert.x, vert.y, depth / 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 ( let b = bevelSegments - 1; b >= 0; b -- ) {
|
||||
|
||||
const t = b / bevelSegments;
|
||||
const z = bevelThickness * Math.cos( t * Math.PI / 2 );
|
||||
const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
|
||||
|
||||
// contract shape
|
||||
|
||||
for ( let i = 0, il = contour.length; i < il; i ++ ) {
|
||||
|
||||
const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
|
||||
v( vert.x, vert.y, depth + z );
|
||||
|
||||
}
|
||||
|
||||
// expand holes
|
||||
|
||||
for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
const ahole = holes[ h ];
|
||||
oneHoleMovements = holesMovements[ h ];
|
||||
|
||||
for ( let i = 0, il = ahole.length; i < il; i ++ ) {
|
||||
|
||||
const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
|
||||
|
||||
if ( ! extrudeByPath ) {
|
||||
|
||||
v( vert.x, vert.y, depth + 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() {
|
||||
|
||||
const start = verticesArray.length / 3;
|
||||
|
||||
if ( bevelEnabled ) {
|
||||
|
||||
let layer = 0; // steps + 1
|
||||
let offset = vlen * layer;
|
||||
|
||||
// Bottom faces
|
||||
|
||||
for ( let i = 0; i < flen; i ++ ) {
|
||||
|
||||
const face = faces[ i ];
|
||||
f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
|
||||
|
||||
}
|
||||
|
||||
layer = steps + bevelSegments * 2;
|
||||
offset = vlen * layer;
|
||||
|
||||
// Top faces
|
||||
|
||||
for ( let i = 0; i < flen; i ++ ) {
|
||||
|
||||
const face = faces[ i ];
|
||||
f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Bottom faces
|
||||
|
||||
for ( let i = 0; i < flen; i ++ ) {
|
||||
|
||||
const face = faces[ i ];
|
||||
f3( face[ 2 ], face[ 1 ], face[ 0 ] );
|
||||
|
||||
}
|
||||
|
||||
// Top faces
|
||||
|
||||
for ( let i = 0; i < flen; i ++ ) {
|
||||
|
||||
const face = faces[ i ];
|
||||
f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
scope.addGroup( start, verticesArray.length / 3 - start, 0 );
|
||||
|
||||
}
|
||||
|
||||
// Create faces for the z-sides of the shape
|
||||
|
||||
function buildSideFaces() {
|
||||
|
||||
const start = verticesArray.length / 3;
|
||||
let layeroffset = 0;
|
||||
sidewalls( contour, layeroffset );
|
||||
layeroffset += contour.length;
|
||||
|
||||
for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
|
||||
|
||||
const ahole = holes[ h ];
|
||||
sidewalls( ahole, layeroffset );
|
||||
|
||||
//, true
|
||||
layeroffset += ahole.length;
|
||||
|
||||
}
|
||||
|
||||
|
||||
scope.addGroup( start, verticesArray.length / 3 - start, 1 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
function sidewalls( contour, layeroffset ) {
|
||||
|
||||
let i = contour.length;
|
||||
|
||||
while ( -- i >= 0 ) {
|
||||
|
||||
const j = i;
|
||||
let k = i - 1;
|
||||
if ( k < 0 ) k = contour.length - 1;
|
||||
|
||||
//console.log('b', i,j, i-1, k,vertices.length);
|
||||
|
||||
for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
|
||||
|
||||
const slen1 = vlen * s;
|
||||
const slen2 = vlen * ( s + 1 );
|
||||
|
||||
const a = layeroffset + j + slen1,
|
||||
b = layeroffset + k + slen1,
|
||||
c = layeroffset + k + slen2,
|
||||
d = layeroffset + j + slen2;
|
||||
|
||||
f4( a, b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function v( x, y, z ) {
|
||||
|
||||
placeholder.push( x );
|
||||
placeholder.push( y );
|
||||
placeholder.push( z );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function f3( a, b, c ) {
|
||||
|
||||
addVertex( a );
|
||||
addVertex( b );
|
||||
addVertex( c );
|
||||
|
||||
const nextIndex = verticesArray.length / 3;
|
||||
const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
|
||||
|
||||
addUV( uvs[ 0 ] );
|
||||
addUV( uvs[ 1 ] );
|
||||
addUV( uvs[ 2 ] );
|
||||
|
||||
}
|
||||
|
||||
function f4( a, b, c, d ) {
|
||||
|
||||
addVertex( a );
|
||||
addVertex( b );
|
||||
addVertex( d );
|
||||
|
||||
addVertex( b );
|
||||
addVertex( c );
|
||||
addVertex( d );
|
||||
|
||||
|
||||
const nextIndex = verticesArray.length / 3;
|
||||
const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
|
||||
|
||||
addUV( uvs[ 0 ] );
|
||||
addUV( uvs[ 1 ] );
|
||||
addUV( uvs[ 3 ] );
|
||||
|
||||
addUV( uvs[ 1 ] );
|
||||
addUV( uvs[ 2 ] );
|
||||
addUV( uvs[ 3 ] );
|
||||
|
||||
}
|
||||
|
||||
function addVertex( index ) {
|
||||
|
||||
verticesArray.push( placeholder[ index * 3 + 0 ] );
|
||||
verticesArray.push( placeholder[ index * 3 + 1 ] );
|
||||
verticesArray.push( placeholder[ index * 3 + 2 ] );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function addUV( vector2 ) {
|
||||
|
||||
uvArray.push( vector2.x );
|
||||
uvArray.push( vector2.y );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
const shapes = this.parameters.shapes;
|
||||
const options = this.parameters.options;
|
||||
|
||||
return toJSON( shapes, options, data );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @param {Array<Shape>} shapes - An array of shapes.
|
||||
* @return {ExtrudeGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data, shapes ) {
|
||||
|
||||
const geometryShapes = [];
|
||||
|
||||
for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
|
||||
|
||||
const shape = shapes[ data.shapes[ j ] ];
|
||||
|
||||
geometryShapes.push( shape );
|
||||
|
||||
}
|
||||
|
||||
const extrudePath = data.options.extrudePath;
|
||||
|
||||
if ( extrudePath !== undefined ) {
|
||||
|
||||
data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
|
||||
|
||||
}
|
||||
|
||||
return new ExtrudeGeometry( geometryShapes, data.options );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const WorldUVGenerator = {
|
||||
|
||||
generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
|
||||
|
||||
const a_x = vertices[ indexA * 3 ];
|
||||
const a_y = vertices[ indexA * 3 + 1 ];
|
||||
const b_x = vertices[ indexB * 3 ];
|
||||
const b_y = vertices[ indexB * 3 + 1 ];
|
||||
const c_x = vertices[ indexC * 3 ];
|
||||
const c_y = vertices[ indexC * 3 + 1 ];
|
||||
|
||||
return [
|
||||
new Vector2( a_x, a_y ),
|
||||
new Vector2( b_x, b_y ),
|
||||
new Vector2( c_x, c_y )
|
||||
];
|
||||
|
||||
},
|
||||
|
||||
generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
|
||||
|
||||
const a_x = vertices[ indexA * 3 ];
|
||||
const a_y = vertices[ indexA * 3 + 1 ];
|
||||
const a_z = vertices[ indexA * 3 + 2 ];
|
||||
const b_x = vertices[ indexB * 3 ];
|
||||
const b_y = vertices[ indexB * 3 + 1 ];
|
||||
const b_z = vertices[ indexB * 3 + 2 ];
|
||||
const c_x = vertices[ indexC * 3 ];
|
||||
const c_y = vertices[ indexC * 3 + 1 ];
|
||||
const c_z = vertices[ indexC * 3 + 2 ];
|
||||
const d_x = vertices[ indexD * 3 ];
|
||||
const d_y = vertices[ indexD * 3 + 1 ];
|
||||
const d_z = vertices[ indexD * 3 + 2 ];
|
||||
|
||||
if ( Math.abs( a_y - b_y ) < Math.abs( a_x - b_x ) ) {
|
||||
|
||||
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 )
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function toJSON( shapes, options, data ) {
|
||||
|
||||
data.shapes = [];
|
||||
|
||||
if ( Array.isArray( shapes ) ) {
|
||||
|
||||
for ( let i = 0, l = shapes.length; i < l; i ++ ) {
|
||||
|
||||
const shape = shapes[ i ];
|
||||
|
||||
data.shapes.push( shape.uuid );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
data.shapes.push( shapes.uuid );
|
||||
|
||||
}
|
||||
|
||||
data.options = Object.assign( {}, options );
|
||||
|
||||
if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the `options` type of the geometry's constructor.
|
||||
*
|
||||
* @typedef {Object} ExtrudeGeometry~Options
|
||||
* @property {number} [curveSegments=12] - Number of points on the curves.
|
||||
* @property {number} [steps=1] - Number of points used for subdividing segments along the depth of the extruded spline.
|
||||
* @property {number} [depth=1] - Depth to extrude the shape.
|
||||
* @property {boolean} [bevelEnabled=true] - Whether to beveling to the shape or not.
|
||||
* @property {number} [bevelThickness=0.2] - How deep into the original shape the bevel goes.
|
||||
* @property {number} [bevelSize=bevelThickness-0.1] - Distance from the shape outline that the bevel extends.
|
||||
* @property {number} [bevelOffset=0] - Distance from the shape outline that the bevel starts.
|
||||
* @property {number} [bevelSegments=3] - Number of bevel layers.
|
||||
* @property {?Curve} [extrudePath=null] - A 3D spline path along which the shape should be extruded. Bevels not supported for path extrusion.
|
||||
* @property {Object} [UVGenerator] - An object that provides UV generator functions for custom UV generation.
|
||||
**/
|
||||
|
||||
export { ExtrudeGeometry };
|
||||
21
app/node_modules/three/src/geometries/Geometries.js
generated
vendored
Normal file
21
app/node_modules/three/src/geometries/Geometries.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
export * from './BoxGeometry.js';
|
||||
export * from './CapsuleGeometry.js';
|
||||
export * from './CircleGeometry.js';
|
||||
export * from './ConeGeometry.js';
|
||||
export * from './CylinderGeometry.js';
|
||||
export * from './DodecahedronGeometry.js';
|
||||
export * from './EdgesGeometry.js';
|
||||
export * from './ExtrudeGeometry.js';
|
||||
export * from './IcosahedronGeometry.js';
|
||||
export * from './LatheGeometry.js';
|
||||
export * from './OctahedronGeometry.js';
|
||||
export * from './PlaneGeometry.js';
|
||||
export * from './PolyhedronGeometry.js';
|
||||
export * from './RingGeometry.js';
|
||||
export * from './ShapeGeometry.js';
|
||||
export * from './SphereGeometry.js';
|
||||
export * from './TetrahedronGeometry.js';
|
||||
export * from './TorusGeometry.js';
|
||||
export * from './TorusKnotGeometry.js';
|
||||
export * from './TubeGeometry.js';
|
||||
export * from './WireframeGeometry.js';
|
||||
74
app/node_modules/three/src/geometries/IcosahedronGeometry.js
generated
vendored
Normal file
74
app/node_modules/three/src/geometries/IcosahedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
import { PolyhedronGeometry } from './PolyhedronGeometry.js';
|
||||
|
||||
/**
|
||||
* A geometry class for representing an icosahedron.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.IcosahedronGeometry();
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const icosahedron = new THREE.Mesh( geometry, material );
|
||||
* scene.add( icosahedron );
|
||||
* ```
|
||||
*
|
||||
* @augments PolyhedronGeometry
|
||||
*/
|
||||
class IcosahedronGeometry extends PolyhedronGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new icosahedron geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - Radius of the icosahedron.
|
||||
* @param {number} [detail=0] - Setting this to a value greater than `0` adds vertices making it no longer a icosahedron.
|
||||
*/
|
||||
constructor( radius = 1, detail = 0 ) {
|
||||
|
||||
const t = ( 1 + Math.sqrt( 5 ) ) / 2;
|
||||
|
||||
const 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
|
||||
];
|
||||
|
||||
const 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
|
||||
];
|
||||
|
||||
super( vertices, indices, radius, detail );
|
||||
|
||||
this.type = 'IcosahedronGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {IcosahedronGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new IcosahedronGeometry( data.radius, data.detail );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { IcosahedronGeometry };
|
||||
229
app/node_modules/three/src/geometries/LatheGeometry.js
generated
vendored
Normal file
229
app/node_modules/three/src/geometries/LatheGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
import { clamp } from '../math/MathUtils.js';
|
||||
|
||||
/**
|
||||
* Creates meshes with axial symmetry like vases. The lathe rotates around the Y axis.
|
||||
*
|
||||
* ```js
|
||||
* const points = [];
|
||||
* for ( let i = 0; i < 10; i ++ ) {
|
||||
* points.push( new THREE.Vector2( Math.sin( i * 0.2 ) * 10 + 5, ( i - 5 ) * 2 ) );
|
||||
* }
|
||||
* const geometry = new THREE.LatheGeometry( points );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const lathe = new THREE.Mesh( geometry, material );
|
||||
* scene.add( lathe );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class LatheGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new lathe geometry.
|
||||
*
|
||||
* @param {Array<Vector2|Vector3>} [points] - An array of points in 2D space. The x-coordinate of each point
|
||||
* must be greater than zero.
|
||||
* @param {number} [segments=12] - The number of circumference segments to generate.
|
||||
* @param {number} [phiStart=0] - The starting angle in radians.
|
||||
* @param {number} [phiLength=Math.PI*2] - The radian (0 to 2PI) range of the lathed section 2PI is a
|
||||
* closed lathe, less than 2PI is a portion.
|
||||
*/
|
||||
constructor( points = [ new Vector2( 0, - 0.5 ), new Vector2( 0.5, 0 ), new Vector2( 0, 0.5 ) ], segments = 12, phiStart = 0, phiLength = Math.PI * 2 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'LatheGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
points: points,
|
||||
segments: segments,
|
||||
phiStart: phiStart,
|
||||
phiLength: phiLength
|
||||
};
|
||||
|
||||
segments = Math.floor( segments );
|
||||
|
||||
// clamp phiLength so it's in range of [ 0, 2PI ]
|
||||
|
||||
phiLength = clamp( phiLength, 0, Math.PI * 2 );
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const uvs = [];
|
||||
const initNormals = [];
|
||||
const normals = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
const inverseSegments = 1.0 / segments;
|
||||
const vertex = new Vector3();
|
||||
const uv = new Vector2();
|
||||
const normal = new Vector3();
|
||||
const curNormal = new Vector3();
|
||||
const prevNormal = new Vector3();
|
||||
let dx = 0;
|
||||
let dy = 0;
|
||||
|
||||
// pre-compute normals for initial "meridian"
|
||||
|
||||
for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
|
||||
|
||||
switch ( j ) {
|
||||
|
||||
case 0: // special handling for 1st vertex on path
|
||||
|
||||
dx = points[ j + 1 ].x - points[ j ].x;
|
||||
dy = points[ j + 1 ].y - points[ j ].y;
|
||||
|
||||
normal.x = dy * 1.0;
|
||||
normal.y = - dx;
|
||||
normal.z = dy * 0.0;
|
||||
|
||||
prevNormal.copy( normal );
|
||||
|
||||
normal.normalize();
|
||||
|
||||
initNormals.push( normal.x, normal.y, normal.z );
|
||||
|
||||
break;
|
||||
|
||||
case ( points.length - 1 ): // special handling for last Vertex on path
|
||||
|
||||
initNormals.push( prevNormal.x, prevNormal.y, prevNormal.z );
|
||||
|
||||
break;
|
||||
|
||||
default: // default handling for all vertices in between
|
||||
|
||||
dx = points[ j + 1 ].x - points[ j ].x;
|
||||
dy = points[ j + 1 ].y - points[ j ].y;
|
||||
|
||||
normal.x = dy * 1.0;
|
||||
normal.y = - dx;
|
||||
normal.z = dy * 0.0;
|
||||
|
||||
curNormal.copy( normal );
|
||||
|
||||
normal.x += prevNormal.x;
|
||||
normal.y += prevNormal.y;
|
||||
normal.z += prevNormal.z;
|
||||
|
||||
normal.normalize();
|
||||
|
||||
initNormals.push( normal.x, normal.y, normal.z );
|
||||
|
||||
prevNormal.copy( curNormal );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// generate vertices, uvs and normals
|
||||
|
||||
for ( let i = 0; i <= segments; i ++ ) {
|
||||
|
||||
const phi = phiStart + i * inverseSegments * phiLength;
|
||||
|
||||
const sin = Math.sin( phi );
|
||||
const cos = Math.cos( phi );
|
||||
|
||||
for ( let 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 );
|
||||
|
||||
// normal
|
||||
|
||||
const x = initNormals[ 3 * j + 0 ] * sin;
|
||||
const y = initNormals[ 3 * j + 1 ];
|
||||
const z = initNormals[ 3 * j + 0 ] * cos;
|
||||
|
||||
normals.push( x, y, z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// indices
|
||||
|
||||
for ( let i = 0; i < segments; i ++ ) {
|
||||
|
||||
for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
|
||||
|
||||
const base = j + i * points.length;
|
||||
|
||||
const a = base;
|
||||
const b = base + points.length;
|
||||
const c = base + points.length + 1;
|
||||
const d = base + 1;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( c, d, b );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {LatheGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new LatheGeometry( data.points, data.segments, data.phiStart, data.phiLength );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { LatheGeometry };
|
||||
69
app/node_modules/three/src/geometries/OctahedronGeometry.js
generated
vendored
Normal file
69
app/node_modules/three/src/geometries/OctahedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import { PolyhedronGeometry } from './PolyhedronGeometry.js';
|
||||
|
||||
/**
|
||||
* A geometry class for representing an octahedron.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.OctahedronGeometry();
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const octahedron = new THREE.Mesh( geometry, material );
|
||||
* scene.add( octahedron );
|
||||
* ```
|
||||
*
|
||||
* @augments PolyhedronGeometry
|
||||
*/
|
||||
class OctahedronGeometry extends PolyhedronGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new octahedron geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - Radius of the octahedron.
|
||||
* @param {number} [detail=0] - Setting this to a value greater than `0` adds vertices making it no longer a octahedron.
|
||||
*/
|
||||
constructor( radius = 1, detail = 0 ) {
|
||||
|
||||
const vertices = [
|
||||
1, 0, 0, - 1, 0, 0, 0, 1, 0,
|
||||
0, - 1, 0, 0, 0, 1, 0, 0, - 1
|
||||
];
|
||||
|
||||
const 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
|
||||
];
|
||||
|
||||
super( vertices, indices, radius, detail );
|
||||
|
||||
this.type = 'OctahedronGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {OctahedronGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new OctahedronGeometry( data.radius, data.detail );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { OctahedronGeometry };
|
||||
132
app/node_modules/three/src/geometries/PlaneGeometry.js
generated
vendored
Normal file
132
app/node_modules/three/src/geometries/PlaneGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
|
||||
/**
|
||||
* A geometry class for representing a plane.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.PlaneGeometry( 1, 1 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00, side: THREE.DoubleSide } );
|
||||
* const plane = new THREE.Mesh( geometry, material );
|
||||
* scene.add( plane );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class PlaneGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new plane geometry.
|
||||
*
|
||||
* @param {number} [width=1] - The width along the X axis.
|
||||
* @param {number} [height=1] - The height along the Y axis
|
||||
* @param {number} [widthSegments=1] - The number of segments along the X axis.
|
||||
* @param {number} [heightSegments=1] - The number of segments along the Y axis.
|
||||
*/
|
||||
constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'PlaneGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
width: width,
|
||||
height: height,
|
||||
widthSegments: widthSegments,
|
||||
heightSegments: heightSegments
|
||||
};
|
||||
|
||||
const width_half = width / 2;
|
||||
const height_half = height / 2;
|
||||
|
||||
const gridX = Math.floor( widthSegments );
|
||||
const gridY = Math.floor( heightSegments );
|
||||
|
||||
const gridX1 = gridX + 1;
|
||||
const gridY1 = gridY + 1;
|
||||
|
||||
const segment_width = width / gridX;
|
||||
const segment_height = height / gridY;
|
||||
|
||||
//
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
for ( let iy = 0; iy < gridY1; iy ++ ) {
|
||||
|
||||
const y = iy * segment_height - height_half;
|
||||
|
||||
for ( let ix = 0; ix < gridX1; ix ++ ) {
|
||||
|
||||
const 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 ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for ( let iy = 0; iy < gridY; iy ++ ) {
|
||||
|
||||
for ( let ix = 0; ix < gridX; ix ++ ) {
|
||||
|
||||
const a = ix + gridX1 * iy;
|
||||
const b = ix + gridX1 * ( iy + 1 );
|
||||
const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
|
||||
const d = ( ix + 1 ) + gridX1 * iy;
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.setIndex( indices );
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {PlaneGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new PlaneGeometry( data.width, data.height, data.widthSegments, data.heightSegments );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { PlaneGeometry };
|
||||
348
app/node_modules/three/src/geometries/PolyhedronGeometry.js
generated
vendored
Normal file
348
app/node_modules/three/src/geometries/PolyhedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,348 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
|
||||
/**
|
||||
* A polyhedron is a solid in three dimensions with flat faces. This class
|
||||
* will take an array of vertices, project them onto a sphere, and then
|
||||
* divide them up to the desired level of detail.
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class PolyhedronGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new polyhedron geometry.
|
||||
*
|
||||
* @param {Array<number>} [vertices] - A flat array of vertices describing the base shape.
|
||||
* @param {Array<number>} [indices] - A flat array of indices describing the base shape.
|
||||
* @param {number} [radius=1] - The radius of the shape.
|
||||
* @param {number} [detail=0] - How many levels to subdivide the geometry. The more detail, the smoother the shape.
|
||||
*/
|
||||
constructor( vertices = [], indices = [], radius = 1, detail = 0 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'PolyhedronGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
vertices: vertices,
|
||||
indices: indices,
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
// default buffer data
|
||||
|
||||
const vertexBuffer = [];
|
||||
const uvBuffer = [];
|
||||
|
||||
// the subdivision creates the vertex buffer data
|
||||
|
||||
subdivide( detail );
|
||||
|
||||
// all vertices should lie on a conceptual sphere with a given radius
|
||||
|
||||
applyRadius( radius );
|
||||
|
||||
// finally, create the uv data
|
||||
|
||||
generateUVs();
|
||||
|
||||
// build non-indexed geometry
|
||||
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
|
||||
|
||||
if ( detail === 0 ) {
|
||||
|
||||
this.computeVertexNormals(); // flat normals
|
||||
|
||||
} else {
|
||||
|
||||
this.normalizeNormals(); // smooth normals
|
||||
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
||||
function subdivide( detail ) {
|
||||
|
||||
const a = new Vector3();
|
||||
const b = new Vector3();
|
||||
const c = new Vector3();
|
||||
|
||||
// iterate over all faces and apply a subdivision with the given detail value
|
||||
|
||||
for ( let 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 ) {
|
||||
|
||||
const cols = detail + 1;
|
||||
|
||||
// we use this multidimensional array as a data structure for creating the subdivision
|
||||
|
||||
const v = [];
|
||||
|
||||
// construct all of the vertices for this subdivision
|
||||
|
||||
for ( let i = 0; i <= cols; i ++ ) {
|
||||
|
||||
v[ i ] = [];
|
||||
|
||||
const aj = a.clone().lerp( c, i / cols );
|
||||
const bj = b.clone().lerp( c, i / cols );
|
||||
|
||||
const rows = cols - i;
|
||||
|
||||
for ( let 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 ( let i = 0; i < cols; i ++ ) {
|
||||
|
||||
for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
|
||||
|
||||
const 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 applyRadius( radius ) {
|
||||
|
||||
const vertex = new Vector3();
|
||||
|
||||
// iterate over the entire buffer and apply the radius to each vertex
|
||||
|
||||
for ( let 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() {
|
||||
|
||||
const vertex = new Vector3();
|
||||
|
||||
for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
|
||||
|
||||
vertex.x = vertexBuffer[ i + 0 ];
|
||||
vertex.y = vertexBuffer[ i + 1 ];
|
||||
vertex.z = vertexBuffer[ i + 2 ];
|
||||
|
||||
const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
|
||||
const 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 ( let i = 0; i < uvBuffer.length; i += 6 ) {
|
||||
|
||||
// uv data of a single face
|
||||
|
||||
const x0 = uvBuffer[ i + 0 ];
|
||||
const x1 = uvBuffer[ i + 2 ];
|
||||
const x2 = uvBuffer[ i + 4 ];
|
||||
|
||||
const max = Math.max( x0, x1, x2 );
|
||||
const 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 ) {
|
||||
|
||||
const stride = index * 3;
|
||||
|
||||
vertex.x = vertices[ stride + 0 ];
|
||||
vertex.y = vertices[ stride + 1 ];
|
||||
vertex.z = vertices[ stride + 2 ];
|
||||
|
||||
}
|
||||
|
||||
function correctUVs() {
|
||||
|
||||
const a = new Vector3();
|
||||
const b = new Vector3();
|
||||
const c = new Vector3();
|
||||
|
||||
const centroid = new Vector3();
|
||||
|
||||
const uvA = new Vector2();
|
||||
const uvB = new Vector2();
|
||||
const uvC = new Vector2();
|
||||
|
||||
for ( let 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 );
|
||||
|
||||
const 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 ) ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {PolyhedronGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new PolyhedronGeometry( data.vertices, data.indices, data.radius, data.details );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { PolyhedronGeometry };
|
||||
164
app/node_modules/three/src/geometries/RingGeometry.js
generated
vendored
Normal file
164
app/node_modules/three/src/geometries/RingGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* A class for generating a two-dimensional ring geometry.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.RingGeometry( 1, 5, 32 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00, side: THREE.DoubleSide } );
|
||||
* const mesh = new THREE.Mesh( geometry, material );
|
||||
* scene.add( mesh );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class RingGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new ring geometry.
|
||||
*
|
||||
* @param {number} [innerRadius=0.5] - The inner radius of the ring.
|
||||
* @param {number} [outerRadius=1] - The outer radius of the ring.
|
||||
* @param {number} [thetaSegments=32] - Number of segments. A higher number means the ring will be more round. Minimum is `3`.
|
||||
* @param {number} [phiSegments=1] - Number of segments per ring segment. Minimum is `1`.
|
||||
* @param {number} [thetaStart=0] - Starting angle in radians.
|
||||
* @param {number} [thetaLength=Math.PI*2] - Central angle in radians.
|
||||
*/
|
||||
constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 32, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'RingGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
innerRadius: innerRadius,
|
||||
outerRadius: outerRadius,
|
||||
thetaSegments: thetaSegments,
|
||||
phiSegments: phiSegments,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
thetaSegments = Math.max( 3, thetaSegments );
|
||||
phiSegments = Math.max( 1, phiSegments );
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
// some helper variables
|
||||
|
||||
let radius = innerRadius;
|
||||
const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
|
||||
const vertex = new Vector3();
|
||||
const uv = new Vector2();
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( let j = 0; j <= phiSegments; j ++ ) {
|
||||
|
||||
for ( let i = 0; i <= thetaSegments; i ++ ) {
|
||||
|
||||
// values are generate from the inside of the ring to the outside
|
||||
|
||||
const 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 ( let j = 0; j < phiSegments; j ++ ) {
|
||||
|
||||
const thetaSegmentLevel = j * ( thetaSegments + 1 );
|
||||
|
||||
for ( let i = 0; i < thetaSegments; i ++ ) {
|
||||
|
||||
const segment = i + thetaSegmentLevel;
|
||||
|
||||
const a = segment;
|
||||
const b = segment + thetaSegments + 1;
|
||||
const c = segment + thetaSegments + 2;
|
||||
const d = segment + 1;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {RingGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new RingGeometry( data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { RingGeometry };
|
||||
232
app/node_modules/three/src/geometries/ShapeGeometry.js
generated
vendored
Normal file
232
app/node_modules/three/src/geometries/ShapeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Shape } from '../extras/core/Shape.js';
|
||||
import { ShapeUtils } from '../extras/ShapeUtils.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
|
||||
/**
|
||||
* Creates an one-sided polygonal geometry from one or more path shapes.
|
||||
*
|
||||
* ```js
|
||||
* const arcShape = new THREE.Shape()
|
||||
* .moveTo( 5, 1 )
|
||||
* .absarc( 1, 1, 4, 0, Math.PI * 2, false );
|
||||
*
|
||||
* const geometry = new THREE.ShapeGeometry( arcShape );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00, side: THREE.DoubleSide } );
|
||||
* const mesh = new THREE.Mesh( geometry, material ) ;
|
||||
* scene.add( mesh );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class ShapeGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new shape geometry.
|
||||
*
|
||||
* @param {Shape|Array<Shape>} [shapes] - A shape or an array of shapes.
|
||||
* @param {number} [curveSegments=12] - Number of segments per shape.
|
||||
*/
|
||||
constructor( shapes = new Shape( [ new Vector2( 0, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), curveSegments = 12 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'ShapeGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
shapes: shapes,
|
||||
curveSegments: curveSegments
|
||||
};
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
let groupStart = 0;
|
||||
let groupCount = 0;
|
||||
|
||||
// allow single and array values for "shapes" parameter
|
||||
|
||||
if ( Array.isArray( shapes ) === false ) {
|
||||
|
||||
addShape( shapes );
|
||||
|
||||
} else {
|
||||
|
||||
for ( let 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.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
|
||||
// helper functions
|
||||
|
||||
function addShape( shape ) {
|
||||
|
||||
const indexOffset = vertices.length / 3;
|
||||
const points = shape.extractPoints( curveSegments );
|
||||
|
||||
let shapeVertices = points.shape;
|
||||
const shapeHoles = points.holes;
|
||||
|
||||
// check direction of vertices
|
||||
|
||||
if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
|
||||
|
||||
shapeVertices = shapeVertices.reverse();
|
||||
|
||||
}
|
||||
|
||||
for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
|
||||
|
||||
const shapeHole = shapeHoles[ i ];
|
||||
|
||||
if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
|
||||
|
||||
shapeHoles[ i ] = shapeHole.reverse();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
|
||||
|
||||
// join vertices of inner and outer paths to a single array
|
||||
|
||||
for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
|
||||
|
||||
const shapeHole = shapeHoles[ i ];
|
||||
shapeVertices = shapeVertices.concat( shapeHole );
|
||||
|
||||
}
|
||||
|
||||
// vertices, normals, uvs
|
||||
|
||||
for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
|
||||
|
||||
const vertex = shapeVertices[ i ];
|
||||
|
||||
vertices.push( vertex.x, vertex.y, 0 );
|
||||
normals.push( 0, 0, 1 );
|
||||
uvs.push( vertex.x, vertex.y ); // world uvs
|
||||
|
||||
}
|
||||
|
||||
// indices
|
||||
|
||||
for ( let i = 0, l = faces.length; i < l; i ++ ) {
|
||||
|
||||
const face = faces[ i ];
|
||||
|
||||
const a = face[ 0 ] + indexOffset;
|
||||
const b = face[ 1 ] + indexOffset;
|
||||
const c = face[ 2 ] + indexOffset;
|
||||
|
||||
indices.push( a, b, c );
|
||||
groupCount += 3;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
const shapes = this.parameters.shapes;
|
||||
|
||||
return toJSON( shapes, data );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @param {Array<Shape>} shapes - An array of shapes.
|
||||
* @return {ShapeGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data, shapes ) {
|
||||
|
||||
const geometryShapes = [];
|
||||
|
||||
for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
|
||||
|
||||
const shape = shapes[ data.shapes[ j ] ];
|
||||
|
||||
geometryShapes.push( shape );
|
||||
|
||||
}
|
||||
|
||||
return new ShapeGeometry( geometryShapes, data.curveSegments );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function toJSON( shapes, data ) {
|
||||
|
||||
data.shapes = [];
|
||||
|
||||
if ( Array.isArray( shapes ) ) {
|
||||
|
||||
for ( let i = 0, l = shapes.length; i < l; i ++ ) {
|
||||
|
||||
const shape = shapes[ i ];
|
||||
|
||||
data.shapes.push( shape.uuid );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
data.shapes.push( shapes.uuid );
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
export { ShapeGeometry };
|
||||
174
app/node_modules/three/src/geometries/SphereGeometry.js
generated
vendored
Normal file
174
app/node_modules/three/src/geometries/SphereGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* A class for generating a sphere geometry.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.SphereGeometry( 15, 32, 16 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const sphere = new THREE.Mesh( geometry, material );
|
||||
* scene.add( sphere );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class SphereGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new sphere geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - The sphere radius.
|
||||
* @param {number} [widthSegments=32] - The number of horizontal segments. Minimum value is `3`.
|
||||
* @param {number} [heightSegments=16] - The number of vertical segments. Minimum value is `2`.
|
||||
* @param {number} [phiStart=0] - The horizontal starting angle in radians.
|
||||
* @param {number} [phiLength=Math.PI*2] - The horizontal sweep angle size.
|
||||
* @param {number} [thetaStart=0] - The vertical starting angle in radians.
|
||||
* @param {number} [thetaLength=Math.PI] - The vertical sweep angle size.
|
||||
*/
|
||||
constructor( radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'SphereGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
widthSegments: widthSegments,
|
||||
heightSegments: heightSegments,
|
||||
phiStart: phiStart,
|
||||
phiLength: phiLength,
|
||||
thetaStart: thetaStart,
|
||||
thetaLength: thetaLength
|
||||
};
|
||||
|
||||
widthSegments = Math.max( 3, Math.floor( widthSegments ) );
|
||||
heightSegments = Math.max( 2, Math.floor( heightSegments ) );
|
||||
|
||||
const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
|
||||
|
||||
let index = 0;
|
||||
const grid = [];
|
||||
|
||||
const vertex = new Vector3();
|
||||
const normal = new Vector3();
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( let iy = 0; iy <= heightSegments; iy ++ ) {
|
||||
|
||||
const verticesRow = [];
|
||||
|
||||
const v = iy / heightSegments;
|
||||
|
||||
// special case for the poles
|
||||
|
||||
let uOffset = 0;
|
||||
|
||||
if ( iy === 0 && thetaStart === 0 ) {
|
||||
|
||||
uOffset = 0.5 / widthSegments;
|
||||
|
||||
} else if ( iy === heightSegments && thetaEnd === Math.PI ) {
|
||||
|
||||
uOffset = - 0.5 / widthSegments;
|
||||
|
||||
}
|
||||
|
||||
for ( let ix = 0; ix <= widthSegments; ix ++ ) {
|
||||
|
||||
const 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.copy( vertex ).normalize();
|
||||
normals.push( normal.x, normal.y, normal.z );
|
||||
|
||||
// uv
|
||||
|
||||
uvs.push( u + uOffset, 1 - v );
|
||||
|
||||
verticesRow.push( index ++ );
|
||||
|
||||
}
|
||||
|
||||
grid.push( verticesRow );
|
||||
|
||||
}
|
||||
|
||||
// indices
|
||||
|
||||
for ( let iy = 0; iy < heightSegments; iy ++ ) {
|
||||
|
||||
for ( let ix = 0; ix < widthSegments; ix ++ ) {
|
||||
|
||||
const a = grid[ iy ][ ix + 1 ];
|
||||
const b = grid[ iy ][ ix ];
|
||||
const c = grid[ iy + 1 ][ ix ];
|
||||
const 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.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {SphereGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new SphereGeometry( data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { SphereGeometry };
|
||||
66
app/node_modules/three/src/geometries/TetrahedronGeometry.js
generated
vendored
Normal file
66
app/node_modules/three/src/geometries/TetrahedronGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
import { PolyhedronGeometry } from './PolyhedronGeometry.js';
|
||||
|
||||
/**
|
||||
* A geometry class for representing an tetrahedron.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.TetrahedronGeometry();
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const tetrahedron = new THREE.Mesh( geometry, material );
|
||||
* scene.add( tetrahedron );
|
||||
* ```
|
||||
*
|
||||
* @augments PolyhedronGeometry
|
||||
*/
|
||||
class TetrahedronGeometry extends PolyhedronGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new tetrahedron geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - Radius of the tetrahedron.
|
||||
* @param {number} [detail=0] - Setting this to a value greater than `0` adds vertices making it no longer a tetrahedron.
|
||||
*/
|
||||
constructor( radius = 1, detail = 0 ) {
|
||||
|
||||
const vertices = [
|
||||
1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
|
||||
];
|
||||
|
||||
const indices = [
|
||||
2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
|
||||
];
|
||||
|
||||
super( vertices, indices, radius, detail );
|
||||
|
||||
this.type = 'TetrahedronGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
detail: detail
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {TetrahedronGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new TetrahedronGeometry( data.radius, data.detail );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { TetrahedronGeometry };
|
||||
155
app/node_modules/three/src/geometries/TorusGeometry.js
generated
vendored
Normal file
155
app/node_modules/three/src/geometries/TorusGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* A geometry class for representing an torus.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.TorusGeometry( 10, 3, 16, 100 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const torus = new THREE.Mesh( geometry, material );
|
||||
* scene.add( torus );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class TorusGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new torus geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - Radius of the torus, from the center of the torus to the center of the tube.
|
||||
* @param {number} [tube=0.4] - Radius of the tube. Must be smaller than `radius`.
|
||||
* @param {number} [radialSegments=12] - The number of radial segments.
|
||||
* @param {number} [tubularSegments=48] - The number of tubular segments.
|
||||
* @param {number} [arc=Math.PI*2] - Central angle in radians.
|
||||
*/
|
||||
constructor( radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'TorusGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
tube: tube,
|
||||
radialSegments: radialSegments,
|
||||
tubularSegments: tubularSegments,
|
||||
arc: arc
|
||||
};
|
||||
|
||||
radialSegments = Math.floor( radialSegments );
|
||||
tubularSegments = Math.floor( tubularSegments );
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
const center = new Vector3();
|
||||
const vertex = new Vector3();
|
||||
const normal = new Vector3();
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( let j = 0; j <= radialSegments; j ++ ) {
|
||||
|
||||
for ( let i = 0; i <= tubularSegments; i ++ ) {
|
||||
|
||||
const u = i / tubularSegments * arc;
|
||||
const 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 ( let j = 1; j <= radialSegments; j ++ ) {
|
||||
|
||||
for ( let i = 1; i <= tubularSegments; i ++ ) {
|
||||
|
||||
// indices
|
||||
|
||||
const a = ( tubularSegments + 1 ) * j + i - 1;
|
||||
const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
|
||||
const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
|
||||
const d = ( tubularSegments + 1 ) * j + i;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {TorusGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new TorusGeometry( data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { TorusGeometry };
|
||||
205
app/node_modules/three/src/geometries/TorusKnotGeometry.js
generated
vendored
Normal file
205
app/node_modules/three/src/geometries/TorusKnotGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* Creates a torus knot, the particular shape of which is defined by a pair
|
||||
* of coprime integers, p and q. If p and q are not coprime, the result will
|
||||
* be a torus link.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.TorusKnotGeometry( 10, 3, 100, 16 );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
|
||||
* const torusKnot = new THREE.Mesh( geometry, material );
|
||||
* scene.add( torusKnot );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class TorusKnotGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new torus knot geometry.
|
||||
*
|
||||
* @param {number} [radius=1] - Radius of the torus knot.
|
||||
* @param {number} [tube=0.4] - Radius of the tube.
|
||||
* @param {number} [tubularSegments=64] - The number of tubular segments.
|
||||
* @param {number} [radialSegments=8] - The number of radial segments.
|
||||
* @param {number} [p=2] - This value determines, how many times the geometry winds around its axis of rotational symmetry.
|
||||
* @param {number} [q=3] - This value determines, how many times the geometry winds around a circle in the interior of the torus.
|
||||
*/
|
||||
constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'TorusKnotGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
radius: radius,
|
||||
tube: tube,
|
||||
tubularSegments: tubularSegments,
|
||||
radialSegments: radialSegments,
|
||||
p: p,
|
||||
q: q
|
||||
};
|
||||
|
||||
tubularSegments = Math.floor( tubularSegments );
|
||||
radialSegments = Math.floor( radialSegments );
|
||||
|
||||
// buffers
|
||||
|
||||
const indices = [];
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
|
||||
// helper variables
|
||||
|
||||
const vertex = new Vector3();
|
||||
const normal = new Vector3();
|
||||
|
||||
const P1 = new Vector3();
|
||||
const P2 = new Vector3();
|
||||
|
||||
const B = new Vector3();
|
||||
const T = new Vector3();
|
||||
const N = new Vector3();
|
||||
|
||||
// generate vertices, normals and uvs
|
||||
|
||||
for ( let i = 0; i <= tubularSegments; ++ i ) {
|
||||
|
||||
// the radian "u" is used to calculate the position on the torus curve of the current tubular segment
|
||||
|
||||
const 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 ( let 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.
|
||||
|
||||
const v = j / radialSegments * Math.PI * 2;
|
||||
const cx = - tube * Math.cos( v );
|
||||
const cy = tube * Math.sin( v );
|
||||
|
||||
// now calculate the final vertex position.
|
||||
// first we orient the extrusion with our basis vectors, 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 ( let j = 1; j <= tubularSegments; j ++ ) {
|
||||
|
||||
for ( let i = 1; i <= radialSegments; i ++ ) {
|
||||
|
||||
// indices
|
||||
|
||||
const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
|
||||
const b = ( radialSegments + 1 ) * j + ( i - 1 );
|
||||
const c = ( radialSegments + 1 ) * j + i;
|
||||
const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
// this function calculates the current position on the torus curve
|
||||
|
||||
function calculatePositionOnCurve( u, p, q, radius, position ) {
|
||||
|
||||
const cu = Math.cos( u );
|
||||
const su = Math.sin( u );
|
||||
const quOverP = q / p * u;
|
||||
const 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {TorusKnotGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
return new TorusKnotGeometry( data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { TorusKnotGeometry };
|
||||
252
app/node_modules/three/src/geometries/TubeGeometry.js
generated
vendored
Normal file
252
app/node_modules/three/src/geometries/TubeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,252 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import * as Curves from '../extras/curves/Curves.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* Creates a tube that extrudes along a 3D curve.
|
||||
*
|
||||
* ```js
|
||||
* class CustomSinCurve extends THREE.Curve {
|
||||
*
|
||||
* getPoint( t, optionalTarget = new THREE.Vector3() ) {
|
||||
*
|
||||
* const tx = t * 3 - 1.5;
|
||||
* const ty = Math.sin( 2 * Math.PI * t );
|
||||
* const tz = 0;
|
||||
*
|
||||
* return optionalTarget.set( tx, ty, tz );
|
||||
* }
|
||||
*
|
||||
* }
|
||||
*
|
||||
* const path = new CustomSinCurve( 10 );
|
||||
* const geometry = new THREE.TubeGeometry( path, 20, 2, 8, false );
|
||||
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
|
||||
* const mesh = new THREE.Mesh( geometry, material );
|
||||
* scene.add( mesh );
|
||||
* ```
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class TubeGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new tube geometry.
|
||||
*
|
||||
* @param {Curve} [path=QuadraticBezierCurve3] - A 3D curve defining the path of the tube.
|
||||
* @param {number} [tubularSegments=64] - The number of segments that make up the tube.
|
||||
* @param {number} [radius=1] -The radius of the tube.
|
||||
* @param {number} [radialSegments=8] - The number of segments that make up the cross-section.
|
||||
* @param {boolean} [closed=false] - Whether the tube is closed or not.
|
||||
*/
|
||||
constructor( path = new Curves[ 'QuadraticBezierCurve3' ]( new Vector3( - 1, - 1, 0 ), new Vector3( - 1, 1, 0 ), new Vector3( 1, 1, 0 ) ), tubularSegments = 64, radius = 1, radialSegments = 8, closed = false ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'TubeGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
path: path,
|
||||
tubularSegments: tubularSegments,
|
||||
radius: radius,
|
||||
radialSegments: radialSegments,
|
||||
closed: closed
|
||||
};
|
||||
|
||||
const frames = path.computeFrenetFrames( tubularSegments, closed );
|
||||
|
||||
// expose internals
|
||||
|
||||
this.tangents = frames.tangents;
|
||||
this.normals = frames.normals;
|
||||
this.binormals = frames.binormals;
|
||||
|
||||
// helper variables
|
||||
|
||||
const vertex = new Vector3();
|
||||
const normal = new Vector3();
|
||||
const uv = new Vector2();
|
||||
let P = new Vector3();
|
||||
|
||||
// buffer
|
||||
|
||||
const vertices = [];
|
||||
const normals = [];
|
||||
const uvs = [];
|
||||
const indices = [];
|
||||
|
||||
// create buffer data
|
||||
|
||||
generateBufferData();
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setIndex( indices );
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
||||
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
||||
|
||||
// functions
|
||||
|
||||
function generateBufferData() {
|
||||
|
||||
for ( let 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
|
||||
|
||||
P = path.getPointAt( i / tubularSegments, P );
|
||||
|
||||
// retrieve corresponding normal and binormal
|
||||
|
||||
const N = frames.normals[ i ];
|
||||
const B = frames.binormals[ i ];
|
||||
|
||||
// generate normals and vertices for the current segment
|
||||
|
||||
for ( let j = 0; j <= radialSegments; j ++ ) {
|
||||
|
||||
const v = j / radialSegments * Math.PI * 2;
|
||||
|
||||
const sin = Math.sin( v );
|
||||
const 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 ( let j = 1; j <= tubularSegments; j ++ ) {
|
||||
|
||||
for ( let i = 1; i <= radialSegments; i ++ ) {
|
||||
|
||||
const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
|
||||
const b = ( radialSegments + 1 ) * j + ( i - 1 );
|
||||
const c = ( radialSegments + 1 ) * j + i;
|
||||
const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
|
||||
|
||||
// faces
|
||||
|
||||
indices.push( a, b, d );
|
||||
indices.push( b, c, d );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function generateUVs() {
|
||||
|
||||
for ( let i = 0; i <= tubularSegments; i ++ ) {
|
||||
|
||||
for ( let j = 0; j <= radialSegments; j ++ ) {
|
||||
|
||||
uv.x = i / tubularSegments;
|
||||
uv.y = j / radialSegments;
|
||||
|
||||
uvs.push( uv.x, uv.y );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
const data = super.toJSON();
|
||||
|
||||
data.path = this.parameters.path.toJSON();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating an instance of this class from the given
|
||||
* JSON object.
|
||||
*
|
||||
* @param {Object} data - A JSON object representing the serialized geometry.
|
||||
* @return {TubeGeometry} A new instance.
|
||||
*/
|
||||
static fromJSON( data ) {
|
||||
|
||||
// This only works for built-in curves (e.g. CatmullRomCurve3).
|
||||
// User defined curves or instances of CurvePath will not be deserialized.
|
||||
return new TubeGeometry(
|
||||
new Curves[ data.path.type ]().fromJSON( data.path ),
|
||||
data.tubularSegments,
|
||||
data.radius,
|
||||
data.radialSegments,
|
||||
data.closed
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { TubeGeometry };
|
||||
179
app/node_modules/three/src/geometries/WireframeGeometry.js
generated
vendored
Normal file
179
app/node_modules/three/src/geometries/WireframeGeometry.js
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
/**
|
||||
* Can be used as a helper object to visualize a geometry as a wireframe.
|
||||
*
|
||||
* ```js
|
||||
* const geometry = new THREE.SphereGeometry();
|
||||
*
|
||||
* const wireframe = new THREE.WireframeGeometry( geometry );
|
||||
*
|
||||
* const line = new THREE.LineSegments( wireframe );
|
||||
* line.material.depthWrite = false;
|
||||
* line.material.opacity = 0.25;
|
||||
* line.material.transparent = true;
|
||||
*
|
||||
* scene.add( line );
|
||||
* ```
|
||||
*
|
||||
* Note: It is not yet possible to serialize/deserialize instances of this class.
|
||||
*
|
||||
* @augments BufferGeometry
|
||||
*/
|
||||
class WireframeGeometry extends BufferGeometry {
|
||||
|
||||
/**
|
||||
* Constructs a new wireframe geometry.
|
||||
*
|
||||
* @param {?BufferGeometry} [geometry=null] - The geometry.
|
||||
*/
|
||||
constructor( geometry = null ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'WireframeGeometry';
|
||||
|
||||
/**
|
||||
* Holds the constructor parameters that have been
|
||||
* used to generate the geometry. Any modification
|
||||
* after instantiation does not change the geometry.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
this.parameters = {
|
||||
geometry: geometry
|
||||
};
|
||||
|
||||
if ( geometry !== null ) {
|
||||
|
||||
// buffer
|
||||
|
||||
const vertices = [];
|
||||
const edges = new Set();
|
||||
|
||||
// helper variables
|
||||
|
||||
const start = new Vector3();
|
||||
const end = new Vector3();
|
||||
|
||||
if ( geometry.index !== null ) {
|
||||
|
||||
// indexed BufferGeometry
|
||||
|
||||
const position = geometry.attributes.position;
|
||||
const indices = geometry.index;
|
||||
let groups = geometry.groups;
|
||||
|
||||
if ( groups.length === 0 ) {
|
||||
|
||||
groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
|
||||
|
||||
}
|
||||
|
||||
// create a data structure that contains all edges without duplicates
|
||||
|
||||
for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
|
||||
|
||||
const group = groups[ o ];
|
||||
|
||||
const groupStart = group.start;
|
||||
const groupCount = group.count;
|
||||
|
||||
for ( let i = groupStart, l = ( groupStart + groupCount ); i < l; i += 3 ) {
|
||||
|
||||
for ( let j = 0; j < 3; j ++ ) {
|
||||
|
||||
const index1 = indices.getX( i + j );
|
||||
const index2 = indices.getX( i + ( j + 1 ) % 3 );
|
||||
|
||||
start.fromBufferAttribute( position, index1 );
|
||||
end.fromBufferAttribute( position, index2 );
|
||||
|
||||
if ( isUniqueEdge( start, end, edges ) === true ) {
|
||||
|
||||
vertices.push( start.x, start.y, start.z );
|
||||
vertices.push( end.x, end.y, end.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// non-indexed BufferGeometry
|
||||
|
||||
const position = geometry.attributes.position;
|
||||
|
||||
for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
|
||||
|
||||
for ( let 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)
|
||||
|
||||
const index1 = 3 * i + j;
|
||||
const index2 = 3 * i + ( ( j + 1 ) % 3 );
|
||||
|
||||
start.fromBufferAttribute( position, index1 );
|
||||
end.fromBufferAttribute( position, index2 );
|
||||
|
||||
if ( isUniqueEdge( start, end, edges ) === true ) {
|
||||
|
||||
vertices.push( start.x, start.y, start.z );
|
||||
vertices.push( end.x, end.y, end.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build geometry
|
||||
|
||||
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source );
|
||||
|
||||
this.parameters = Object.assign( {}, source.parameters );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function isUniqueEdge( start, end, edges ) {
|
||||
|
||||
const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`;
|
||||
const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`; // coincident edge
|
||||
|
||||
if ( edges.has( hash1 ) === true || edges.has( hash2 ) === true ) {
|
||||
|
||||
return false;
|
||||
|
||||
} else {
|
||||
|
||||
edges.add( hash1 );
|
||||
edges.add( hash2 );
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { WireframeGeometry };
|
||||
171
app/node_modules/three/src/helpers/ArrowHelper.js
generated
vendored
Normal file
171
app/node_modules/three/src/helpers/ArrowHelper.js
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { ConeGeometry } from '../geometries/ConeGeometry.js';
|
||||
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Mesh } from '../objects/Mesh.js';
|
||||
import { Line } from '../objects/Line.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
const _axis = /*@__PURE__*/ new Vector3();
|
||||
let _lineGeometry, _coneGeometry;
|
||||
|
||||
/**
|
||||
* An 3D arrow object for visualizing directions.
|
||||
*
|
||||
* ```js
|
||||
* const dir = new THREE.Vector3( 1, 2, 0 );
|
||||
*
|
||||
* //normalize the direction vector (convert to vector of length 1)
|
||||
* dir.normalize();
|
||||
*
|
||||
* const origin = new THREE.Vector3( 0, 0, 0 );
|
||||
* const length = 1;
|
||||
* const hex = 0xffff00;
|
||||
*
|
||||
* const arrowHelper = new THREE.ArrowHelper( dir, origin, length, hex );
|
||||
* scene.add( arrowHelper );
|
||||
* ```
|
||||
*
|
||||
* @augments Object3D
|
||||
*/
|
||||
class ArrowHelper extends Object3D {
|
||||
|
||||
/**
|
||||
* Constructs a new arrow helper.
|
||||
*
|
||||
* @param {Vector3} [dir=(0, 0, 1)] - The (normalized) direction vector.
|
||||
* @param {Vector3} [origin=(0, 0, 0)] - Point at which the arrow starts.
|
||||
* @param {number} [length=1] - Length of the arrow in world units.
|
||||
* @param {(number|Color|string)} [color=0xffff00] - Color of the arrow.
|
||||
* @param {number} [headLength=length*0.2] - The length of the head of the arrow.
|
||||
* @param {number} [headWidth=headLength*0.2] - The width of the head of the arrow.
|
||||
*/
|
||||
constructor( dir = new Vector3( 0, 0, 1 ), origin = new Vector3( 0, 0, 0 ), length = 1, color = 0xffff00, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'ArrowHelper';
|
||||
|
||||
if ( _lineGeometry === undefined ) {
|
||||
|
||||
_lineGeometry = new BufferGeometry();
|
||||
_lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
|
||||
|
||||
_coneGeometry = new ConeGeometry( 0.5, 1, 5, 1 );
|
||||
_coneGeometry.translate( 0, - 0.5, 0 );
|
||||
|
||||
}
|
||||
|
||||
this.position.copy( origin );
|
||||
|
||||
/**
|
||||
* The line part of the arrow helper.
|
||||
*
|
||||
* @type {Line}
|
||||
*/
|
||||
this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
|
||||
this.line.matrixAutoUpdate = false;
|
||||
this.add( this.line );
|
||||
|
||||
/**
|
||||
* The cone part of the arrow helper.
|
||||
*
|
||||
* @type {Mesh}
|
||||
*/
|
||||
this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
|
||||
this.cone.matrixAutoUpdate = false;
|
||||
this.add( this.cone );
|
||||
|
||||
this.setDirection( dir );
|
||||
this.setLength( length, headLength, headWidth );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the direction of the helper.
|
||||
*
|
||||
* @param {Vector3} dir - The normalized direction vector.
|
||||
*/
|
||||
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();
|
||||
|
||||
const radians = Math.acos( dir.y );
|
||||
|
||||
this.quaternion.setFromAxisAngle( _axis, radians );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the length of the helper.
|
||||
*
|
||||
* @param {number} length - Length of the arrow in world units.
|
||||
* @param {number} [headLength=length*0.2] - The length of the head of the arrow.
|
||||
* @param {number} [headWidth=headLength*0.2] - The width of the head of the arrow.
|
||||
*/
|
||||
setLength( length, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
|
||||
|
||||
this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
|
||||
this.line.updateMatrix();
|
||||
|
||||
this.cone.scale.set( headWidth, headLength, headWidth );
|
||||
this.cone.position.y = length;
|
||||
this.cone.updateMatrix();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the helper.
|
||||
*
|
||||
* @param {number|Color|string} color - The color to set.
|
||||
*/
|
||||
setColor( color ) {
|
||||
|
||||
this.line.material.color.set( color );
|
||||
this.cone.material.color.set( color );
|
||||
|
||||
}
|
||||
|
||||
copy( source ) {
|
||||
|
||||
super.copy( source, false );
|
||||
|
||||
this.line.copy( source.line );
|
||||
this.cone.copy( source.cone );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever this instance is no longer used in your app.
|
||||
*/
|
||||
dispose() {
|
||||
|
||||
this.line.geometry.dispose();
|
||||
this.line.material.dispose();
|
||||
this.cone.geometry.dispose();
|
||||
this.cone.material.dispose();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { ArrowHelper };
|
||||
96
app/node_modules/three/src/helpers/AxesHelper.js
generated
vendored
Normal file
96
app/node_modules/three/src/helpers/AxesHelper.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Color } from '../math/Color.js';
|
||||
|
||||
/**
|
||||
* An axis object to visualize the 3 axes in a simple way.
|
||||
* The X axis is red. The Y axis is green. The Z axis is blue.
|
||||
*
|
||||
* ```js
|
||||
* const axesHelper = new THREE.AxesHelper( 5 );
|
||||
* scene.add( axesHelper );
|
||||
* ```
|
||||
*
|
||||
* @augments LineSegments
|
||||
*/
|
||||
class AxesHelper extends LineSegments {
|
||||
|
||||
/**
|
||||
* Constructs a new axes helper.
|
||||
*
|
||||
* @param {number} [size=1] - Size of the lines representing the axes.
|
||||
*/
|
||||
constructor( size = 1 ) {
|
||||
|
||||
const vertices = [
|
||||
0, 0, 0, size, 0, 0,
|
||||
0, 0, 0, 0, size, 0,
|
||||
0, 0, 0, 0, 0, size
|
||||
];
|
||||
|
||||
const colors = [
|
||||
1, 0, 0, 1, 0.6, 0,
|
||||
0, 1, 0, 0.6, 1, 0,
|
||||
0, 0, 1, 0, 0.6, 1
|
||||
];
|
||||
|
||||
const geometry = new BufferGeometry();
|
||||
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
|
||||
|
||||
super( geometry, material );
|
||||
|
||||
this.type = 'AxesHelper';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the colors of the axes helper.
|
||||
*
|
||||
* @param {number|Color|string} xAxisColor - The color for the x axis.
|
||||
* @param {number|Color|string} yAxisColor - The color for the y axis.
|
||||
* @param {number|Color|string} zAxisColor - The color for the z axis.
|
||||
* @return {AxesHelper} A reference to this axes helper.
|
||||
*/
|
||||
setColors( xAxisColor, yAxisColor, zAxisColor ) {
|
||||
|
||||
const color = new Color();
|
||||
const array = this.geometry.attributes.color.array;
|
||||
|
||||
color.set( xAxisColor );
|
||||
color.toArray( array, 0 );
|
||||
color.toArray( array, 3 );
|
||||
|
||||
color.set( yAxisColor );
|
||||
color.toArray( array, 6 );
|
||||
color.toArray( array, 9 );
|
||||
|
||||
color.set( zAxisColor );
|
||||
color.toArray( array, 12 );
|
||||
color.toArray( array, 15 );
|
||||
|
||||
this.geometry.attributes.color.needsUpdate = true;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever this instance is no longer used in your app.
|
||||
*/
|
||||
dispose() {
|
||||
|
||||
this.geometry.dispose();
|
||||
this.material.dispose();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { AxesHelper };
|
||||
83
app/node_modules/three/src/helpers/Box3Helper.js
generated
vendored
Normal file
83
app/node_modules/three/src/helpers/Box3Helper.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { BufferAttribute, Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
|
||||
/**
|
||||
* A helper object to visualize an instance of {@link Box3}.
|
||||
*
|
||||
* ```js
|
||||
* const box = new THREE.Box3();
|
||||
* box.setFromCenterAndSize( new THREE.Vector3( 1, 1, 1 ), new THREE.Vector3( 2, 1, 3 ) );
|
||||
*
|
||||
* const helper = new THREE.Box3Helper( box, 0xffff00 );
|
||||
* scene.add( helper )
|
||||
* ```
|
||||
*
|
||||
* @augments LineSegments
|
||||
*/
|
||||
class Box3Helper extends LineSegments {
|
||||
|
||||
/**
|
||||
* Constructs a new box3 helper.
|
||||
*
|
||||
* @param {Box3} box - The box to visualize.
|
||||
* @param {number|Color|string} [color=0xffff00] - The box's color.
|
||||
*/
|
||||
constructor( box, color = 0xffff00 ) {
|
||||
|
||||
const 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 ] );
|
||||
|
||||
const positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 1, - 1, 1, - 1, - 1 ];
|
||||
|
||||
const geometry = new BufferGeometry();
|
||||
|
||||
geometry.setIndex( new BufferAttribute( indices, 1 ) );
|
||||
|
||||
geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
|
||||
|
||||
super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
|
||||
|
||||
/**
|
||||
* The box being visualized.
|
||||
*
|
||||
* @type {Box3}
|
||||
*/
|
||||
this.box = box;
|
||||
|
||||
this.type = 'Box3Helper';
|
||||
|
||||
this.geometry.computeBoundingSphere();
|
||||
|
||||
}
|
||||
|
||||
updateMatrixWorld( force ) {
|
||||
|
||||
const box = this.box;
|
||||
|
||||
if ( box.isEmpty() ) return;
|
||||
|
||||
box.getCenter( this.position );
|
||||
|
||||
box.getSize( this.scale );
|
||||
|
||||
this.scale.multiplyScalar( 0.5 );
|
||||
|
||||
super.updateMatrixWorld( force );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever this instance is no longer used in your app.
|
||||
*/
|
||||
dispose() {
|
||||
|
||||
this.geometry.dispose();
|
||||
this.material.dispose();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Box3Helper };
|
||||
149
app/node_modules/three/src/helpers/BoxHelper.js
generated
vendored
Normal file
149
app/node_modules/three/src/helpers/BoxHelper.js
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
import { Box3 } from '../math/Box3.js';
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
|
||||
const _box = /*@__PURE__*/ new Box3();
|
||||
|
||||
/**
|
||||
* Helper object to graphically show the world-axis-aligned bounding box
|
||||
* around an object. The actual bounding box is handled with {@link Box3},
|
||||
* this is just a visual helper for debugging. It can be automatically
|
||||
* resized with {@link BoxHelper#update} when the object it's created from
|
||||
* is transformed. Note that the object must have a geometry for this to work,
|
||||
* so it won't work with sprites.
|
||||
*
|
||||
* ```js
|
||||
* const sphere = new THREE.SphereGeometry();
|
||||
* const object = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( 0xff0000 ) );
|
||||
* const box = new THREE.BoxHelper( object, 0xffff00 );
|
||||
* scene.add( box );
|
||||
* ```
|
||||
*
|
||||
* @augments LineSegments
|
||||
*/
|
||||
class BoxHelper extends LineSegments {
|
||||
|
||||
/**
|
||||
* Constructs a new box helper.
|
||||
*
|
||||
* @param {Object3D} [object] - The 3D object to show the world-axis-aligned bounding box.
|
||||
* @param {number|Color|string} [color=0xffff00] - The box's color.
|
||||
*/
|
||||
constructor( object, color = 0xffff00 ) {
|
||||
|
||||
const 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 ] );
|
||||
const positions = new Float32Array( 8 * 3 );
|
||||
|
||||
const geometry = new BufferGeometry();
|
||||
geometry.setIndex( new BufferAttribute( indices, 1 ) );
|
||||
geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
|
||||
|
||||
super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
|
||||
|
||||
/**
|
||||
* The 3D object being visualized.
|
||||
*
|
||||
* @type {Object3D}
|
||||
*/
|
||||
this.object = object;
|
||||
this.type = 'BoxHelper';
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the helper's geometry to match the dimensions of the object,
|
||||
* including any children.
|
||||
*/
|
||||
update() {
|
||||
|
||||
if ( this.object !== undefined ) {
|
||||
|
||||
_box.setFromObject( this.object );
|
||||
|
||||
}
|
||||
|
||||
if ( _box.isEmpty() ) return;
|
||||
|
||||
const min = _box.min;
|
||||
const 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
|
||||
*/
|
||||
|
||||
const position = this.geometry.attributes.position;
|
||||
const 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();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the wireframe box for the passed object.
|
||||
*
|
||||
* @param {Object3D} object - The 3D object to create the helper for.
|
||||
* @return {BoxHelper} A reference to this instance.
|
||||
*/
|
||||
setFromObject( object ) {
|
||||
|
||||
this.object = object;
|
||||
this.update();
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
copy( source, recursive ) {
|
||||
|
||||
super.copy( source, recursive );
|
||||
|
||||
this.object = source.object;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the GPU-related resources allocated by this instance. Call this
|
||||
* method whenever this instance is no longer used in your app.
|
||||
*/
|
||||
dispose() {
|
||||
|
||||
this.geometry.dispose();
|
||||
this.material.dispose();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { BoxHelper };
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user