super-three 0.157.0 → 0.158.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/build/three.cjs +1486 -842
- package/build/three.js +1486 -842
- package/build/three.min.js +1 -1
- package/build/three.module.js +1481 -843
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +290 -0
- package/examples/jsm/controls/FlyControls.js +26 -0
- package/examples/jsm/controls/OrbitControls.js +12 -1
- package/examples/jsm/controls/TransformControls.js +27 -11
- package/examples/jsm/csm/CSMShader.js +1 -1
- package/examples/jsm/exporters/GLTFExporter.js +72 -2
- package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -0
- package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -0
- package/examples/jsm/libs/lottie_canvas.module.js +6 -1
- package/examples/jsm/libs/opentype.module.js +13 -75
- package/examples/jsm/libs/surfaceNet.js +201 -0
- package/examples/jsm/loaders/GLTFLoader.js +12 -3
- package/examples/jsm/loaders/LUTImageLoader.js +162 -0
- package/examples/jsm/loaders/lwo/IFFParser.js +89 -93
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/math/Capsule.js +0 -55
- package/examples/jsm/math/Octree.js +70 -3
- package/examples/jsm/modifiers/SimplifyModifier.js +103 -11
- package/examples/jsm/modifiers/TessellateModifier.js +3 -3
- package/examples/jsm/nodes/Nodes.js +6 -6
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +3 -3
- package/examples/jsm/nodes/accessors/InstanceNode.js +3 -3
- package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +21 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +68 -31
- package/examples/jsm/nodes/accessors/ModelNode.js +1 -2
- package/examples/jsm/nodes/accessors/MorphNode.js +5 -5
- package/examples/jsm/nodes/accessors/NormalNode.js +1 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +1 -1
- package/examples/jsm/nodes/accessors/SkinningNode.js +13 -3
- package/examples/jsm/nodes/accessors/TextureNode.js +3 -3
- package/examples/jsm/nodes/code/FunctionNode.js +1 -1
- package/examples/jsm/nodes/core/AssignNode.js +72 -0
- package/examples/jsm/nodes/core/LightingModel.js +3 -1
- package/examples/jsm/nodes/core/Node.js +7 -12
- package/examples/jsm/nodes/core/NodeBuilder.js +126 -16
- package/examples/jsm/nodes/core/NodeUtils.js +4 -2
- package/examples/jsm/nodes/core/OutputStructNode.js +1 -1
- package/examples/jsm/nodes/core/ParameterNode.js +33 -0
- package/examples/jsm/nodes/core/PropertyNode.js +4 -10
- package/examples/jsm/nodes/core/StackNode.js +7 -17
- package/examples/jsm/nodes/core/TempNode.js +1 -1
- package/examples/jsm/nodes/core/VarNode.js +6 -35
- package/examples/jsm/nodes/core/VaryingNode.js +2 -0
- package/examples/jsm/nodes/display/BumpMapNode.js +35 -13
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -1
- package/examples/jsm/nodes/display/ViewportNode.js +14 -4
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +20 -6
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -7
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +8 -3
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +8 -0
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +8 -0
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +93 -43
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +2 -2
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +19 -5
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +0 -6
- package/examples/jsm/nodes/lighting/LightingContextNode.js +21 -57
- package/examples/jsm/nodes/lighting/LightsNode.js +62 -4
- package/examples/jsm/nodes/lighting/PointLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/SpotLightNode.js +1 -1
- package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +162 -0
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +70 -71
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +5 -5
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +3 -3
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +47 -20
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +6 -6
- package/examples/jsm/nodes/materials/NodeMaterial.js +17 -20
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +5 -5
- package/examples/jsm/nodes/math/OperatorNode.js +5 -21
- package/examples/jsm/nodes/shadernode/ShaderNode.js +128 -9
- package/examples/jsm/nodes/utils/ArrayElementNode.js +2 -0
- package/examples/jsm/nodes/utils/DiscardNode.js +3 -2
- package/examples/jsm/nodes/utils/JoinNode.js +11 -1
- package/examples/jsm/nodes/utils/LoopNode.js +36 -24
- package/examples/jsm/nodes/utils/SplitNode.js +2 -0
- package/examples/jsm/objects/BatchedMesh.js +586 -0
- package/examples/jsm/objects/InstancedPoints.js +21 -0
- package/examples/jsm/objects/Lensflare.js +20 -0
- package/examples/jsm/objects/ReflectorForSSRPass.js +3 -0
- package/examples/jsm/objects/Refractor.js +3 -0
- package/examples/jsm/objects/Sky.js +5 -3
- package/examples/jsm/objects/Water.js +5 -2
- package/examples/jsm/objects/Water2.js +3 -0
- package/examples/jsm/physics/AmmoPhysics.js +21 -0
- package/examples/jsm/physics/RapierPhysics.js +21 -0
- package/examples/jsm/postprocessing/BokehPass.js +3 -2
- package/examples/jsm/postprocessing/LUTPass.js +2 -1
- package/examples/jsm/postprocessing/OutputPass.js +1 -0
- package/examples/jsm/postprocessing/Pass.js +14 -3
- package/examples/jsm/postprocessing/SAOPass.js +0 -1
- package/examples/jsm/postprocessing/SMAAPass.js +0 -2
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -2
- package/examples/jsm/renderers/CSS3DRenderer.js +3 -9
- package/examples/jsm/renderers/SVGRenderer.js +9 -6
- package/examples/jsm/renderers/common/Bindings.js +1 -1
- package/examples/jsm/renderers/common/RenderObject.js +8 -1
- package/examples/jsm/renderers/common/RenderObjects.js +1 -1
- package/examples/jsm/renderers/common/Textures.js +4 -36
- package/examples/jsm/renderers/common/nodes/Nodes.js +53 -18
- package/examples/jsm/renderers/webgl/WebGLBackend.js +291 -50
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +88 -12
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +40 -5
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +14 -2
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +2 -0
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +36 -4
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +2 -0
- package/examples/jsm/shaders/AfterimageShader.js +2 -0
- package/examples/jsm/shaders/BasicShader.js +2 -0
- package/examples/jsm/shaders/BlendShader.js +2 -0
- package/examples/jsm/shaders/BokehShader.js +2 -0
- package/examples/jsm/shaders/BokehShader2.js +4 -0
- package/examples/jsm/shaders/BrightnessContrastShader.js +2 -0
- package/examples/jsm/shaders/ColorCorrectionShader.js +2 -0
- package/examples/jsm/shaders/DOFMipMapShader.js +2 -0
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +5 -0
- package/examples/jsm/shaders/FXAAShader.js +2 -0
- package/examples/jsm/shaders/FilmShader.js +1 -1
- package/examples/jsm/shaders/FocusShader.js +2 -0
- package/examples/jsm/shaders/FreiChenShader.js +2 -0
- package/examples/jsm/shaders/GodRaysShader.js +8 -0
- package/examples/jsm/shaders/HalftoneShader.js +2 -0
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +2 -0
- package/examples/jsm/shaders/HueSaturationShader.js +2 -0
- package/examples/jsm/shaders/KaleidoShader.js +2 -0
- package/examples/jsm/shaders/LuminosityHighPassShader.js +2 -0
- package/examples/jsm/shaders/LuminosityShader.js +2 -0
- package/examples/jsm/shaders/MMDToonShader.js +2 -0
- package/examples/jsm/shaders/MirrorShader.js +2 -0
- package/examples/jsm/shaders/NormalMapShader.js +2 -0
- package/examples/jsm/shaders/OutputShader.js +4 -5
- package/examples/jsm/shaders/SAOShader.js +5 -0
- package/examples/jsm/shaders/SMAAShader.js +6 -0
- package/examples/jsm/shaders/SSAOShader.js +6 -0
- package/examples/jsm/shaders/SSRShader.js +6 -0
- package/examples/jsm/shaders/SobelOperatorShader.js +2 -0
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +2 -0
- package/examples/jsm/shaders/TechnicolorShader.js +2 -0
- package/examples/jsm/shaders/TriangleBlurShader.js +2 -0
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -0
- package/examples/jsm/shaders/VelocityShader.js +2 -0
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +2 -0
- package/examples/jsm/shaders/WaterRefractionShader.js +2 -0
- package/examples/jsm/transpiler/AST.js +231 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +899 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
- package/examples/jsm/transpiler/TSLEncoder.js +611 -0
- package/examples/jsm/transpiler/Transpiler.js +18 -0
- package/examples/jsm/webxr/VRButton.js +1 -1
- package/examples/jsm/webxr/XRButton.js +7 -5
- package/examples/jsm/webxr/XREstimatedLight.js +1 -1
- package/package.json +4 -1
- package/src/constants.js +7 -1
- package/src/extras/PMREMGenerator.js +7 -1
- package/src/loaders/MaterialLoader.js +10 -2
- package/src/materials/Material.js +27 -13
- package/src/math/Box3.js +35 -18
- package/src/math/Vector3.js +11 -12
- package/src/objects/SkinnedMesh.js +6 -7
- package/src/renderers/WebGLMultiviewRenderTarget.js +35 -0
- package/src/renderers/WebGLRenderer.js +199 -45
- package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +8 -6
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +2 -2
- package/src/renderers/webgl/WebGLBackground.js +1 -1
- package/src/renderers/webgl/WebGLMultiview.js +100 -0
- package/src/renderers/webgl/WebGLProgram.js +130 -50
- package/src/renderers/webgl/WebGLPrograms.js +8 -0
- package/src/renderers/webgl/WebGLState.js +25 -4
- package/src/renderers/webgl/WebGLTextures.js +197 -20
- package/src/renderers/webxr/WebXRManager.js +36 -12
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -76
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +0 -29
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box3,
|
|
3
|
+
Float32BufferAttribute,
|
|
4
|
+
InstancedBufferGeometry,
|
|
5
|
+
InstancedBufferAttribute,
|
|
6
|
+
Sphere,
|
|
7
|
+
Vector3
|
|
8
|
+
} from 'three';
|
|
9
|
+
|
|
10
|
+
const _vector = new Vector3();
|
|
11
|
+
|
|
12
|
+
class InstancedPointsGeometry extends InstancedBufferGeometry {
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
|
|
16
|
+
super();
|
|
17
|
+
|
|
18
|
+
this.isInstancedPointsGeometry = true;
|
|
19
|
+
|
|
20
|
+
this.type = 'InstancedPointsGeometry';
|
|
21
|
+
|
|
22
|
+
const positions = [ - 1, 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
|
|
23
|
+
const uvs = [ - 1, 1, 1, 1, - 1, - 1, 1, - 1 ];
|
|
24
|
+
const index = [ 0, 2, 1, 2, 3, 1 ];
|
|
25
|
+
|
|
26
|
+
this.setIndex( index );
|
|
27
|
+
this.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
|
|
28
|
+
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
applyMatrix4( matrix ) {
|
|
33
|
+
|
|
34
|
+
const pos = this.attributes.instancePosition;
|
|
35
|
+
|
|
36
|
+
if ( pos !== undefined ) {
|
|
37
|
+
|
|
38
|
+
pos.applyMatrix4( matrix );
|
|
39
|
+
|
|
40
|
+
pos.needsUpdate = true;
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if ( this.boundingBox !== null ) {
|
|
45
|
+
|
|
46
|
+
this.computeBoundingBox();
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ( this.boundingSphere !== null ) {
|
|
51
|
+
|
|
52
|
+
this.computeBoundingSphere();
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this;
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setPositions( array ) {
|
|
61
|
+
|
|
62
|
+
let points;
|
|
63
|
+
|
|
64
|
+
if ( array instanceof Float32Array ) {
|
|
65
|
+
|
|
66
|
+
points = array;
|
|
67
|
+
|
|
68
|
+
} else if ( Array.isArray( array ) ) {
|
|
69
|
+
|
|
70
|
+
points = new Float32Array( array );
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.setAttribute( 'instancePosition', new InstancedBufferAttribute( points, 3 ) ); // xyz
|
|
75
|
+
|
|
76
|
+
//
|
|
77
|
+
|
|
78
|
+
this.computeBoundingBox();
|
|
79
|
+
this.computeBoundingSphere();
|
|
80
|
+
|
|
81
|
+
return this;
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setColors( array ) {
|
|
86
|
+
|
|
87
|
+
let colors;
|
|
88
|
+
|
|
89
|
+
if ( array instanceof Float32Array ) {
|
|
90
|
+
|
|
91
|
+
colors = array;
|
|
92
|
+
|
|
93
|
+
} else if ( Array.isArray( array ) ) {
|
|
94
|
+
|
|
95
|
+
colors = new Float32Array( array );
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.setAttribute( 'instanceColor', new InstancedBufferAttribute( colors, 3 ) ); // rgb
|
|
100
|
+
|
|
101
|
+
return this;
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
computeBoundingBox() {
|
|
106
|
+
|
|
107
|
+
if ( this.boundingBox === null ) {
|
|
108
|
+
|
|
109
|
+
this.boundingBox = new Box3();
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const pos = this.attributes.instancePosition;
|
|
114
|
+
|
|
115
|
+
if ( pos !== undefined ) {
|
|
116
|
+
|
|
117
|
+
this.boundingBox.setFromBufferAttribute( pos );
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
computeBoundingSphere() {
|
|
124
|
+
|
|
125
|
+
if ( this.boundingSphere === null ) {
|
|
126
|
+
|
|
127
|
+
this.boundingSphere = new Sphere();
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if ( this.boundingBox === null ) {
|
|
132
|
+
|
|
133
|
+
this.computeBoundingBox();
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const pos = this.attributes.instancePosition;
|
|
138
|
+
|
|
139
|
+
if ( pos !== undefined ) {
|
|
140
|
+
|
|
141
|
+
const center = this.boundingSphere.center;
|
|
142
|
+
|
|
143
|
+
this.boundingBox.getCenter( center );
|
|
144
|
+
|
|
145
|
+
let maxRadiusSq = 0;
|
|
146
|
+
|
|
147
|
+
for ( let i = 0, il = pos.count; i < il; i ++ ) {
|
|
148
|
+
|
|
149
|
+
_vector.fromBufferAttribute( pos, i );
|
|
150
|
+
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
|
|
155
|
+
|
|
156
|
+
if ( isNaN( this.boundingSphere.radius ) ) {
|
|
157
|
+
|
|
158
|
+
console.error( 'THREE.InstancedPointsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.', this );
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
toJSON() {
|
|
167
|
+
|
|
168
|
+
// todo
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export default InstancedPointsGeometry;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author santiago / @glitch_life
|
|
3
|
+
* wrapper of https://www.npmjs.com/package/isosurface by https://github.com/mikolalysenko
|
|
4
|
+
*
|
|
5
|
+
* Returns BufferGeometry from SDF
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
BufferAttribute,
|
|
10
|
+
BufferGeometry,
|
|
11
|
+
FloatType,
|
|
12
|
+
Mesh,
|
|
13
|
+
OrthographicCamera,
|
|
14
|
+
PlaneGeometry,
|
|
15
|
+
Scene,
|
|
16
|
+
ShaderMaterial,
|
|
17
|
+
Vector2,
|
|
18
|
+
WebGLRenderTarget
|
|
19
|
+
} from 'three';
|
|
20
|
+
|
|
21
|
+
import { surfaceNet } from './../libs/surfaceNet.js';
|
|
22
|
+
|
|
23
|
+
class SDFGeometryGenerator {
|
|
24
|
+
|
|
25
|
+
constructor( renderer ) {
|
|
26
|
+
|
|
27
|
+
this.renderer = renderer;
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
generate( res = 64, distFunc = 'float dist( vec3 p ){ return length(p) - 0.5; }', bounds = 1 ) {
|
|
32
|
+
|
|
33
|
+
let w, h;
|
|
34
|
+
if ( res == 8 ) [ w, h ] = [ 32, 16 ];
|
|
35
|
+
else if ( res == 16 ) [ w, h ] = [ 64, 64 ];
|
|
36
|
+
else if ( res == 32 ) [ w, h ] = [ 256, 128 ];
|
|
37
|
+
else if ( res == 64 ) [ w, h ] = [ 512, 512 ];
|
|
38
|
+
else if ( res == 128 ) [ w, h ] = [ 2048, 1024 ];
|
|
39
|
+
else if ( res == 256 ) [ w, h ] = [ 4096, 4096 ];
|
|
40
|
+
else if ( res == 512 ) [ w, h ] = [ 16384, 8096 ];
|
|
41
|
+
else if ( res == 1024 ) [ w, h ] = [ 32768, 32768 ];
|
|
42
|
+
else throw new Error( 'THREE.SDFGeometryGenerator: Resolution must be in range 8 < res < 1024 and must be ^2' );
|
|
43
|
+
|
|
44
|
+
const maxTexSize = this.renderer.capabilities.maxTextureSize;
|
|
45
|
+
|
|
46
|
+
if ( w > maxTexSize || h > maxTexSize ) throw new Error( 'THREE.SDFGeometryGenerator: Your device does not support this resolution ( ' + res + ' ), decrease [res] param.' );
|
|
47
|
+
|
|
48
|
+
const [ tilesX, tilesY ] = [ ( w / res ), ( h / res ) ];
|
|
49
|
+
|
|
50
|
+
const sdfCompute = `
|
|
51
|
+
varying vec2 vUv;
|
|
52
|
+
uniform float tileNum;
|
|
53
|
+
uniform float bounds;
|
|
54
|
+
[#dist#]
|
|
55
|
+
void main() { gl_FragColor=vec4( ( dist( vec3( vUv, tileNum ) * 2.0 * bounds - vec3( bounds ) ) < 0.00001 ) ? 1.0 : 0.0 ); }
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
const sdfRT = this.computeSDF( w, h, tilesX, tilesY, bounds, sdfCompute.replace( '[#dist#]', distFunc ) );
|
|
59
|
+
|
|
60
|
+
const read = new Float32Array( w * h * 4 );
|
|
61
|
+
this.renderer.readRenderTargetPixels( sdfRT, 0, 0, w, h, read );
|
|
62
|
+
sdfRT.dispose();
|
|
63
|
+
|
|
64
|
+
//
|
|
65
|
+
|
|
66
|
+
const mesh = surfaceNet( [ res, res, res ], ( x, y, z ) => {
|
|
67
|
+
|
|
68
|
+
x = ( x + bounds ) * ( res / ( bounds * 2 ) );
|
|
69
|
+
y = ( y + bounds ) * ( res / ( bounds * 2 ) );
|
|
70
|
+
z = ( z + bounds ) * ( res / ( bounds * 2 ) );
|
|
71
|
+
let p = ( x + ( z % tilesX ) * res ) + y * w + ( Math.floor( z / tilesX ) * res * w );
|
|
72
|
+
p *= 4;
|
|
73
|
+
return ( read[ p + 3 ] > 0 ) ? - 0.000000001 : 1;
|
|
74
|
+
|
|
75
|
+
}, [[ - bounds, - bounds, - bounds ], [ bounds, bounds, bounds ]] );
|
|
76
|
+
|
|
77
|
+
const ps = [], ids = [];
|
|
78
|
+
const geometry = new BufferGeometry();
|
|
79
|
+
mesh.positions.forEach( p => {
|
|
80
|
+
|
|
81
|
+
ps.push( p[ 0 ], p[ 1 ], p[ 2 ] );
|
|
82
|
+
|
|
83
|
+
} );
|
|
84
|
+
mesh.cells.forEach( p => ids.push( p[ 0 ], p[ 1 ], p[ 2 ] ) );
|
|
85
|
+
geometry.setAttribute( 'position', new BufferAttribute( new Float32Array( ps ), 3 ) );
|
|
86
|
+
geometry.setIndex( ids );
|
|
87
|
+
|
|
88
|
+
return geometry;
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
computeSDF( width, height, tilesX, tilesY, bounds, shader ) {
|
|
93
|
+
|
|
94
|
+
const rt = new WebGLRenderTarget( width, height, { type: FloatType } );
|
|
95
|
+
const scn = new Scene();
|
|
96
|
+
const cam = new OrthographicCamera();
|
|
97
|
+
const tiles = tilesX * tilesY;
|
|
98
|
+
let currentTile = 0;
|
|
99
|
+
|
|
100
|
+
Object.assign( cam, { left: width / - 2, right: width / 2, top: height / 2, bottom: height / - 2 } ).updateProjectionMatrix();
|
|
101
|
+
cam.position.z = 2;
|
|
102
|
+
|
|
103
|
+
const tileSize = width / tilesX;
|
|
104
|
+
const geometry = new PlaneGeometry( tileSize, tileSize );
|
|
105
|
+
|
|
106
|
+
while ( currentTile ++ < tiles ) {
|
|
107
|
+
|
|
108
|
+
const c = currentTile - 1;
|
|
109
|
+
const [ px, py ] = [ ( tileSize ) / 2 + ( c % tilesX ) * ( tileSize ) - width / 2, ( tileSize ) / 2 + Math.floor( c / tilesX ) * ( tileSize ) - height / 2 ];
|
|
110
|
+
const compPlane = new Mesh( geometry, new ShaderMaterial( {
|
|
111
|
+
uniforms: {
|
|
112
|
+
res: { value: new Vector2( width, height ) },
|
|
113
|
+
tileNum: { value: c / ( tilesX * tilesY - 1 ) },
|
|
114
|
+
bounds: { value: bounds }
|
|
115
|
+
},
|
|
116
|
+
vertexShader: 'varying vec2 vUv;void main(){vUv=uv;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);}',
|
|
117
|
+
fragmentShader: shader
|
|
118
|
+
} ) );
|
|
119
|
+
compPlane.position.set( px, py, 0 );
|
|
120
|
+
scn.add( compPlane );
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this.renderer.setRenderTarget( rt );
|
|
125
|
+
this.renderer.render( scn, cam );
|
|
126
|
+
this.renderer.setRenderTarget( null );
|
|
127
|
+
|
|
128
|
+
//
|
|
129
|
+
|
|
130
|
+
geometry.dispose();
|
|
131
|
+
|
|
132
|
+
scn.traverse( function ( object ) {
|
|
133
|
+
|
|
134
|
+
if ( object.material !== undefined ) object.material.dispose();
|
|
135
|
+
|
|
136
|
+
} );
|
|
137
|
+
|
|
138
|
+
return rt;
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { SDFGeometryGenerator };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
const lottie = {};
|
|
2
|
+
|
|
3
|
+
if (typeof document !== 'undefined') {
|
|
4
|
+
|
|
1
5
|
const svgNS = 'http://www.w3.org/2000/svg';
|
|
2
6
|
|
|
3
7
|
let locationHref = '';
|
|
@@ -4547,7 +4551,6 @@ const Matrix = (function () {
|
|
|
4547
4551
|
};
|
|
4548
4552
|
}());
|
|
4549
4553
|
|
|
4550
|
-
const lottie = {};
|
|
4551
4554
|
var standalone = '__[STANDALONE]__';
|
|
4552
4555
|
var animationData = '__[ANIMATIONDATA]__';
|
|
4553
4556
|
var renderer = '';
|
|
@@ -14841,4 +14844,6 @@ setExpressionsPlugin(Expressions);
|
|
|
14841
14844
|
initialize$1();
|
|
14842
14845
|
initialize();
|
|
14843
14846
|
|
|
14847
|
+
}
|
|
14848
|
+
|
|
14844
14849
|
export { lottie as default };
|
|
@@ -8115,30 +8115,6 @@ Substitution.prototype.add = function(feature, sub, script, language) {
|
|
|
8115
8115
|
return undefined;
|
|
8116
8116
|
};
|
|
8117
8117
|
|
|
8118
|
-
function isBrowser() {
|
|
8119
|
-
return typeof window !== 'undefined';
|
|
8120
|
-
}
|
|
8121
|
-
|
|
8122
|
-
function nodeBufferToArrayBuffer(buffer) {
|
|
8123
|
-
var ab = new ArrayBuffer(buffer.length);
|
|
8124
|
-
var view = new Uint8Array(ab);
|
|
8125
|
-
for (var i = 0; i < buffer.length; ++i) {
|
|
8126
|
-
view[i] = buffer[i];
|
|
8127
|
-
}
|
|
8128
|
-
|
|
8129
|
-
return ab;
|
|
8130
|
-
}
|
|
8131
|
-
|
|
8132
|
-
function arrayBufferToNodeBuffer(ab) {
|
|
8133
|
-
var buffer = new Buffer(ab.byteLength);
|
|
8134
|
-
var view = new Uint8Array(ab);
|
|
8135
|
-
for (var i = 0; i < buffer.length; ++i) {
|
|
8136
|
-
buffer[i] = view[i];
|
|
8137
|
-
}
|
|
8138
|
-
|
|
8139
|
-
return buffer;
|
|
8140
|
-
}
|
|
8141
|
-
|
|
8142
8118
|
function checkArgument(expression, message) {
|
|
8143
8119
|
if (!expression) {
|
|
8144
8120
|
throw message;
|
|
@@ -13671,27 +13647,21 @@ Font.prototype.download = function(fileName) {
|
|
|
13671
13647
|
fileName = fileName || familyName.replace(/\s/g, '') + '-' + styleName + '.otf';
|
|
13672
13648
|
var arrayBuffer = this.toArrayBuffer();
|
|
13673
13649
|
|
|
13674
|
-
|
|
13675
|
-
window.URL = window.URL || window.webkitURL;
|
|
13650
|
+
window.URL = window.URL || window.webkitURL;
|
|
13676
13651
|
|
|
13677
|
-
|
|
13678
|
-
|
|
13679
|
-
|
|
13652
|
+
if (window.URL) {
|
|
13653
|
+
var dataView = new DataView(arrayBuffer);
|
|
13654
|
+
var blob = new Blob([dataView], {type: 'font/opentype'});
|
|
13680
13655
|
|
|
13681
|
-
|
|
13682
|
-
|
|
13683
|
-
|
|
13656
|
+
var link = document.createElement('a');
|
|
13657
|
+
link.href = window.URL.createObjectURL(blob);
|
|
13658
|
+
link.download = fileName;
|
|
13684
13659
|
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13688
|
-
} else {
|
|
13689
|
-
console.warn('Font file could not be downloaded. Try using a different browser.');
|
|
13690
|
-
}
|
|
13660
|
+
var event = document.createEvent('MouseEvents');
|
|
13661
|
+
event.initEvent('click', true, false);
|
|
13662
|
+
link.dispatchEvent(event);
|
|
13691
13663
|
} else {
|
|
13692
|
-
|
|
13693
|
-
var buffer = arrayBufferToNodeBuffer(arrayBuffer);
|
|
13694
|
-
fs.writeFileSync(fileName, buffer);
|
|
13664
|
+
console.warn('Font file could not be downloaded. Try using a different browser.');
|
|
13695
13665
|
}
|
|
13696
13666
|
};
|
|
13697
13667
|
/**
|
|
@@ -14155,22 +14125,7 @@ var loca = { parse: parseLocaTable };
|
|
|
14155
14125
|
*/
|
|
14156
14126
|
|
|
14157
14127
|
// File loaders /////////////////////////////////////////////////////////
|
|
14158
|
-
/**
|
|
14159
|
-
* Loads a font from a file. The callback throws an error message as the first parameter if it fails
|
|
14160
|
-
* and the font as an ArrayBuffer in the second parameter if it succeeds.
|
|
14161
|
-
* @param {string} path - The path of the file
|
|
14162
|
-
* @param {Function} callback - The function to call when the font load completes
|
|
14163
|
-
*/
|
|
14164
|
-
function loadFromFile(path, callback) {
|
|
14165
|
-
var fs = require('fs');
|
|
14166
|
-
fs.readFile(path, function(err, buffer) {
|
|
14167
|
-
if (err) {
|
|
14168
|
-
return callback(err.message);
|
|
14169
|
-
}
|
|
14170
14128
|
|
|
14171
|
-
callback(null, nodeBufferToArrayBuffer(buffer));
|
|
14172
|
-
});
|
|
14173
|
-
}
|
|
14174
14129
|
/**
|
|
14175
14130
|
* Loads a font from a URL. The callback throws an error message as the first parameter if it fails
|
|
14176
14131
|
* and the font as an ArrayBuffer in the second parameter if it succeeds.
|
|
@@ -14507,11 +14462,9 @@ function parseBuffer(buffer, opt) {
|
|
|
14507
14462
|
*/
|
|
14508
14463
|
function load(url, callback, opt) {
|
|
14509
14464
|
opt = (opt === undefined || opt === null) ? {} : opt;
|
|
14510
|
-
var isNode = typeof window === 'undefined';
|
|
14511
|
-
var loadFn = isNode && !opt.isUrl ? loadFromFile : loadFromUrl;
|
|
14512
14465
|
|
|
14513
14466
|
return new Promise(function (resolve, reject) {
|
|
14514
|
-
|
|
14467
|
+
loadFromUrl(url, function(err, arrayBuffer) {
|
|
14515
14468
|
if (err) {
|
|
14516
14469
|
if (callback) {
|
|
14517
14470
|
return callback(err);
|
|
@@ -14538,20 +14491,6 @@ function load(url, callback, opt) {
|
|
|
14538
14491
|
});
|
|
14539
14492
|
}
|
|
14540
14493
|
|
|
14541
|
-
/**
|
|
14542
|
-
* Synchronously load the font from a URL or file.
|
|
14543
|
-
* When done, returns the font object or throws an error.
|
|
14544
|
-
* @alias opentype.loadSync
|
|
14545
|
-
* @param {string} url - The URL of the font to load.
|
|
14546
|
-
* @param {Object} opt - opt.lowMemory
|
|
14547
|
-
* @return {opentype.Font}
|
|
14548
|
-
*/
|
|
14549
|
-
function loadSync(url, opt) {
|
|
14550
|
-
var fs = require('fs');
|
|
14551
|
-
var buffer = fs.readFileSync(url);
|
|
14552
|
-
return parseBuffer(nodeBufferToArrayBuffer(buffer), opt);
|
|
14553
|
-
}
|
|
14554
|
-
|
|
14555
14494
|
var opentype = /*#__PURE__*/Object.freeze({
|
|
14556
14495
|
__proto__: null,
|
|
14557
14496
|
Font: Font,
|
|
@@ -14561,8 +14500,7 @@ var opentype = /*#__PURE__*/Object.freeze({
|
|
|
14561
14500
|
_parse: parse,
|
|
14562
14501
|
parse: parseBuffer,
|
|
14563
14502
|
load: load,
|
|
14564
|
-
loadSync: loadSync
|
|
14565
14503
|
});
|
|
14566
14504
|
|
|
14567
14505
|
export default opentype;
|
|
14568
|
-
export { BoundingBox, Font, Glyph, Path, parse as _parse, load,
|
|
14506
|
+
export { BoundingBox, Font, Glyph, Path, parse as _parse, load, parseBuffer as parse };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SurfaceNets in JavaScript
|
|
3
|
+
*
|
|
4
|
+
* Written by Mikola Lysenko (C) 2012
|
|
5
|
+
*
|
|
6
|
+
* MIT License
|
|
7
|
+
*
|
|
8
|
+
* Based on: S.F. Gibson, 'Constrained Elastic Surface Nets'. (1998) MERL Tech Report.
|
|
9
|
+
* from https://github.com/mikolalysenko/isosurface/tree/master
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
let surfaceNet = ( dims, potential, bounds ) => {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
//Precompute edge table, like Paul Bourke does.
|
|
17
|
+
// This saves a bit of time when computing the centroid of each boundary cell
|
|
18
|
+
var cube_edges = new Int32Array(24) , edge_table = new Int32Array(256);
|
|
19
|
+
(function() {
|
|
20
|
+
|
|
21
|
+
//Initialize the cube_edges table
|
|
22
|
+
// This is just the vertex number of each cube
|
|
23
|
+
var k = 0;
|
|
24
|
+
for(var i=0; i<8; ++i) {
|
|
25
|
+
for(var j=1; j<=4; j<<=1) {
|
|
26
|
+
var p = i^j;
|
|
27
|
+
if(i <= p) {
|
|
28
|
+
cube_edges[k++] = i;
|
|
29
|
+
cube_edges[k++] = p;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//Initialize the intersection table.
|
|
35
|
+
// This is a 2^(cube configuration) -> 2^(edge configuration) map
|
|
36
|
+
// There is one entry for each possible cube configuration, and the output is a 12-bit vector enumerating all edges crossing the 0-level.
|
|
37
|
+
for(var i=0; i<256; ++i) {
|
|
38
|
+
var em = 0;
|
|
39
|
+
for(var j=0; j<24; j+=2) {
|
|
40
|
+
var a = !!(i & (1<<cube_edges[j]))
|
|
41
|
+
, b = !!(i & (1<<cube_edges[j+1]));
|
|
42
|
+
em |= a !== b ? (1 << (j >> 1)) : 0;
|
|
43
|
+
}
|
|
44
|
+
edge_table[i] = em;
|
|
45
|
+
}
|
|
46
|
+
})();
|
|
47
|
+
|
|
48
|
+
//Internal buffer, this may get resized at run time
|
|
49
|
+
var buffer = new Array(4096);
|
|
50
|
+
(function() {
|
|
51
|
+
for(var i=0; i<buffer.length; ++i) {
|
|
52
|
+
buffer[i] = 0;
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
|
|
56
|
+
if(!bounds) {
|
|
57
|
+
bounds = [[0,0,0],dims];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
var scale = [0,0,0];
|
|
61
|
+
var shift = [0,0,0];
|
|
62
|
+
for(var i=0; i<3; ++i) {
|
|
63
|
+
scale[i] = (bounds[1][i] - bounds[0][i]) / dims[i];
|
|
64
|
+
shift[i] = bounds[0][i];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var vertices = []
|
|
68
|
+
, faces = []
|
|
69
|
+
, n = 0
|
|
70
|
+
, x = [0, 0, 0]
|
|
71
|
+
, R = [1, (dims[0]+1), (dims[0]+1)*(dims[1]+1)]
|
|
72
|
+
, grid = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
|
73
|
+
, buf_no = 1;
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
//Resize buffer if necessary
|
|
77
|
+
if(R[2] * 2 > buffer.length) {
|
|
78
|
+
var ol = buffer.length;
|
|
79
|
+
buffer.length = R[2] * 2;
|
|
80
|
+
while(ol < buffer.length) {
|
|
81
|
+
buffer[ol++] = 0;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
//March over the voxel grid
|
|
86
|
+
for(x[2]=0; x[2]<dims[2]-1; ++x[2], n+=dims[0], buf_no ^= 1, R[2]=-R[2]) {
|
|
87
|
+
|
|
88
|
+
//m is the pointer into the buffer we are going to use.
|
|
89
|
+
//This is slightly obtuse because javascript does not have good support for packed data structures, so we must use typed arrays :(
|
|
90
|
+
//The contents of the buffer will be the indices of the vertices on the previous x/y slice of the volume
|
|
91
|
+
var m = 1 + (dims[0]+1) * (1 + buf_no * (dims[1]+1));
|
|
92
|
+
|
|
93
|
+
for(x[1]=0; x[1]<dims[1]-1; ++x[1], ++n, m+=2)
|
|
94
|
+
for(x[0]=0; x[0]<dims[0]-1; ++x[0], ++n, ++m) {
|
|
95
|
+
|
|
96
|
+
//Read in 8 field values around this vertex and store them in an array
|
|
97
|
+
//Also calculate 8-bit mask, like in marching cubes, so we can speed up sign checks later
|
|
98
|
+
var mask = 0, g = 0;
|
|
99
|
+
for(var k=0; k<2; ++k)
|
|
100
|
+
for(var j=0; j<2; ++j)
|
|
101
|
+
for(var i=0; i<2; ++i, ++g) {
|
|
102
|
+
var p = potential(
|
|
103
|
+
scale[0]*(x[0]+i)+shift[0],
|
|
104
|
+
scale[1]*(x[1]+j)+shift[1],
|
|
105
|
+
scale[2]*(x[2]+k)+shift[2]);
|
|
106
|
+
grid[g] = p;
|
|
107
|
+
mask |= (p < 0) ? (1<<g) : 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//Check for early termination if cell does not intersect boundary
|
|
111
|
+
if(mask === 0 || mask === 0xff) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//Sum up edge intersections
|
|
116
|
+
var edge_mask = edge_table[mask]
|
|
117
|
+
, v = [0.0,0.0,0.0]
|
|
118
|
+
, e_count = 0;
|
|
119
|
+
|
|
120
|
+
//For every edge of the cube...
|
|
121
|
+
for(var i=0; i<12; ++i) {
|
|
122
|
+
|
|
123
|
+
//Use edge mask to check if it is crossed
|
|
124
|
+
if(!(edge_mask & (1<<i))) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//If it did, increment number of edge crossings
|
|
129
|
+
++e_count;
|
|
130
|
+
|
|
131
|
+
//Now find the point of intersection
|
|
132
|
+
var e0 = cube_edges[ i<<1 ] //Unpack vertices
|
|
133
|
+
, e1 = cube_edges[(i<<1)+1]
|
|
134
|
+
, g0 = grid[e0] //Unpack grid values
|
|
135
|
+
, g1 = grid[e1]
|
|
136
|
+
, t = g0 - g1; //Compute point of intersection
|
|
137
|
+
if(Math.abs(t) > 1e-6) {
|
|
138
|
+
t = g0 / t;
|
|
139
|
+
} else {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//Interpolate vertices and add up intersections (this can be done without multiplying)
|
|
144
|
+
for(var j=0, k=1; j<3; ++j, k<<=1) {
|
|
145
|
+
var a = e0 & k
|
|
146
|
+
, b = e1 & k;
|
|
147
|
+
if(a !== b) {
|
|
148
|
+
v[j] += a ? 1.0 - t : t;
|
|
149
|
+
} else {
|
|
150
|
+
v[j] += a ? 1.0 : 0;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
//Now we just average the edge intersections and add them to coordinate
|
|
156
|
+
var s = 1.0 / e_count;
|
|
157
|
+
for(var i=0; i<3; ++i) {
|
|
158
|
+
v[i] = scale[i] * (x[i] + s * v[i]) + shift[i];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//Add vertex to buffer, store pointer to vertex index in buffer
|
|
162
|
+
buffer[m] = vertices.length;
|
|
163
|
+
vertices.push(v);
|
|
164
|
+
|
|
165
|
+
//Now we need to add faces together, to do this we just loop over 3 basis components
|
|
166
|
+
for(var i=0; i<3; ++i) {
|
|
167
|
+
//The first three entries of the edge_mask count the crossings along the edge
|
|
168
|
+
if(!(edge_mask & (1<<i)) ) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// i = axes we are point along. iu, iv = orthogonal axes
|
|
173
|
+
var iu = (i+1)%3
|
|
174
|
+
, iv = (i+2)%3;
|
|
175
|
+
|
|
176
|
+
//If we are on a boundary, skip it
|
|
177
|
+
if(x[iu] === 0 || x[iv] === 0) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
//Otherwise, look up adjacent edges in buffer
|
|
182
|
+
var du = R[iu]
|
|
183
|
+
, dv = R[iv];
|
|
184
|
+
|
|
185
|
+
//Remember to flip orientation depending on the sign of the corner.
|
|
186
|
+
if(mask & 1) {
|
|
187
|
+
faces.push([buffer[m], buffer[m-du], buffer[m-dv]]);
|
|
188
|
+
faces.push([buffer[m-dv], buffer[m-du], buffer[m-du-dv]]);
|
|
189
|
+
} else {
|
|
190
|
+
faces.push([buffer[m], buffer[m-dv], buffer[m-du]]);
|
|
191
|
+
faces.push([buffer[m-du], buffer[m-dv], buffer[m-du-dv]]);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
//All done! Return the result
|
|
198
|
+
return { positions: vertices, cells: faces };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export { surfaceNet }
|