@zephyr3d/scene 0.1.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/dist/animation/animation.js +173 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/animationset.js +95 -0
- package/dist/animation/animationset.js.map +1 -0
- package/dist/animation/animationtrack.js +38 -0
- package/dist/animation/animationtrack.js.map +1 -0
- package/dist/animation/eulerrotationtrack.js +33 -0
- package/dist/animation/eulerrotationtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +37 -0
- package/dist/animation/rotationtrack.js.map +1 -0
- package/dist/animation/scaletrack.js +36 -0
- package/dist/animation/scaletrack.js.map +1 -0
- package/dist/animation/skeleton.js +97 -0
- package/dist/animation/skeleton.js.map +1 -0
- package/dist/animation/translationtrack.js +36 -0
- package/dist/animation/translationtrack.js.map +1 -0
- package/dist/animation/usertrack.js +47 -0
- package/dist/animation/usertrack.js.map +1 -0
- package/dist/app.js +173 -0
- package/dist/app.js.map +1 -0
- package/dist/asset/assetmanager.js +476 -0
- package/dist/asset/assetmanager.js.map +1 -0
- package/dist/asset/builtin.js +373 -0
- package/dist/asset/builtin.js.map +1 -0
- package/dist/asset/loaders/dds/dds.js +472 -0
- package/dist/asset/loaders/dds/dds.js.map +1 -0
- package/dist/asset/loaders/dds/dds_loader.js +38 -0
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/helpers.js +314 -0
- package/dist/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/asset/loaders/hdr/hdr.js +175 -0
- package/dist/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/asset/loaders/image/tga_Loader.js +117 -0
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/asset/loaders/image/webimage_loader.js +50 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/asset/loaders/loader.js +45 -0
- package/dist/asset/loaders/loader.js.map +1 -0
- package/dist/asset/model.js +264 -0
- package/dist/asset/model.js.map +1 -0
- package/dist/blitter/blitter.js +389 -0
- package/dist/blitter/blitter.js.map +1 -0
- package/dist/blitter/box.js +118 -0
- package/dist/blitter/box.js.map +1 -0
- package/dist/blitter/copy.js +22 -0
- package/dist/blitter/copy.js.map +1 -0
- package/dist/blitter/depthlimitedgaussion.js +166 -0
- package/dist/blitter/depthlimitedgaussion.js.map +1 -0
- package/dist/blitter/gaussianblur.js +229 -0
- package/dist/blitter/gaussianblur.js.map +1 -0
- package/dist/camera/base.js +90 -0
- package/dist/camera/base.js.map +1 -0
- package/dist/camera/camera.js +358 -0
- package/dist/camera/camera.js.map +1 -0
- package/dist/camera/fps.js +246 -0
- package/dist/camera/fps.js.map +1 -0
- package/dist/camera/orbit.js +157 -0
- package/dist/camera/orbit.js.map +1 -0
- package/dist/camera/orthocamera.js +126 -0
- package/dist/camera/orthocamera.js.map +1 -0
- package/dist/camera/perspectivecamera.js +133 -0
- package/dist/camera/perspectivecamera.js.map +1 -0
- package/dist/index.d.ts +8402 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/input/inputmgr.js +242 -0
- package/dist/input/inputmgr.js.map +1 -0
- package/dist/material/blinn.js +75 -0
- package/dist/material/blinn.js.map +1 -0
- package/dist/material/grassmaterial.js +221 -0
- package/dist/material/grassmaterial.js.map +1 -0
- package/dist/material/lambert.js +52 -0
- package/dist/material/lambert.js.map +1 -0
- package/dist/material/lightmodel.js +2074 -0
- package/dist/material/lightmodel.js.map +1 -0
- package/dist/material/lit.js +578 -0
- package/dist/material/lit.js.map +1 -0
- package/dist/material/material.js +458 -0
- package/dist/material/material.js.map +1 -0
- package/dist/material/meshmaterial.js +311 -0
- package/dist/material/meshmaterial.js.map +1 -0
- package/dist/material/mixins/albedocolor.js +130 -0
- package/dist/material/mixins/albedocolor.js.map +1 -0
- package/dist/material/mixins/texture.js +110 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +45 -0
- package/dist/material/mixins/vertexcolor.js.map +1 -0
- package/dist/material/pbr.js +27 -0
- package/dist/material/pbr.js.map +1 -0
- package/dist/material/standard.js +282 -0
- package/dist/material/standard.js.map +1 -0
- package/dist/material/terrainlightmodel.js +259 -0
- package/dist/material/terrainlightmodel.js.map +1 -0
- package/dist/material/terrainmaterial.js +139 -0
- package/dist/material/terrainmaterial.js.map +1 -0
- package/dist/material/unlit.js +29 -0
- package/dist/material/unlit.js.map +1 -0
- package/dist/posteffect/bloom.js +398 -0
- package/dist/posteffect/bloom.js.map +1 -0
- package/dist/posteffect/compositor.js +264 -0
- package/dist/posteffect/compositor.js.map +1 -0
- package/dist/posteffect/fxaa.js +291 -0
- package/dist/posteffect/fxaa.js.map +1 -0
- package/dist/posteffect/grayscale.js +87 -0
- package/dist/posteffect/grayscale.js.map +1 -0
- package/dist/posteffect/posteffect.js +165 -0
- package/dist/posteffect/posteffect.js.map +1 -0
- package/dist/posteffect/sao.js +327 -0
- package/dist/posteffect/sao.js.map +1 -0
- package/dist/posteffect/tonemap.js +112 -0
- package/dist/posteffect/tonemap.js.map +1 -0
- package/dist/posteffect/water.js +535 -0
- package/dist/posteffect/water.js.map +1 -0
- package/dist/render/clipmap.js +462 -0
- package/dist/render/clipmap.js.map +1 -0
- package/dist/render/cluster_light.js +329 -0
- package/dist/render/cluster_light.js.map +1 -0
- package/dist/render/cull_visitor.js +124 -0
- package/dist/render/cull_visitor.js.map +1 -0
- package/dist/render/depth_pass.js +47 -0
- package/dist/render/depth_pass.js.map +1 -0
- package/dist/render/envlight.js +282 -0
- package/dist/render/envlight.js.map +1 -0
- package/dist/render/forward.js +186 -0
- package/dist/render/forward.js.map +1 -0
- package/dist/render/forward_pass.js +137 -0
- package/dist/render/forward_pass.js.map +1 -0
- package/dist/render/helper.js +38 -0
- package/dist/render/helper.js.map +1 -0
- package/dist/render/primitive.js +246 -0
- package/dist/render/primitive.js.map +1 -0
- package/dist/render/render_queue.js +163 -0
- package/dist/render/render_queue.js.map +1 -0
- package/dist/render/renderpass.js +151 -0
- package/dist/render/renderpass.js.map +1 -0
- package/dist/render/renderscheme.js +61 -0
- package/dist/render/renderscheme.js.map +1 -0
- package/dist/render/scatteringlut.js +634 -0
- package/dist/render/scatteringlut.js.map +1 -0
- package/dist/render/shadowmap_pass.js +70 -0
- package/dist/render/shadowmap_pass.js.map +1 -0
- package/dist/render/sky.js +881 -0
- package/dist/render/sky.js.map +1 -0
- package/dist/render/temporalcache.js +222 -0
- package/dist/render/temporalcache.js.map +1 -0
- package/dist/render/watermesh.js +835 -0
- package/dist/render/watermesh.js.map +1 -0
- package/dist/scene/environment.js +146 -0
- package/dist/scene/environment.js.map +1 -0
- package/dist/scene/graph_node.js +69 -0
- package/dist/scene/graph_node.js.map +1 -0
- package/dist/scene/light.js +436 -0
- package/dist/scene/light.js.map +1 -0
- package/dist/scene/mesh.js +215 -0
- package/dist/scene/mesh.js.map +1 -0
- package/dist/scene/model.js +111 -0
- package/dist/scene/model.js.map +1 -0
- package/dist/scene/octree.js +651 -0
- package/dist/scene/octree.js.map +1 -0
- package/dist/scene/octree_update_visitor.js +16 -0
- package/dist/scene/octree_update_visitor.js.map +1 -0
- package/dist/scene/raycast_visitor.js +72 -0
- package/dist/scene/raycast_visitor.js.map +1 -0
- package/dist/scene/scene.js +225 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/scene/scene_node.js +299 -0
- package/dist/scene/scene_node.js.map +1 -0
- package/dist/scene/terrain/grass.js +277 -0
- package/dist/scene/terrain/grass.js.map +1 -0
- package/dist/scene/terrain/heightfield.js +391 -0
- package/dist/scene/terrain/heightfield.js.map +1 -0
- package/dist/scene/terrain/patch.js +530 -0
- package/dist/scene/terrain/patch.js.map +1 -0
- package/dist/scene/terrain/quadtree.js +430 -0
- package/dist/scene/terrain/quadtree.js.map +1 -0
- package/dist/scene/terrain/terrain.js +258 -0
- package/dist/scene/terrain/terrain.js.map +1 -0
- package/dist/scene/xform.js +224 -0
- package/dist/scene/xform.js.map +1 -0
- package/dist/shaders/builtins.js +110 -0
- package/dist/shaders/builtins.js.map +1 -0
- package/dist/shaders/framework.js +709 -0
- package/dist/shaders/framework.js.map +1 -0
- package/dist/shaders/lighting.js +335 -0
- package/dist/shaders/lighting.js.map +1 -0
- package/dist/shaders/misc.js +405 -0
- package/dist/shaders/misc.js.map +1 -0
- package/dist/shaders/noise.js +157 -0
- package/dist/shaders/noise.js.map +1 -0
- package/dist/shaders/pbr.js +132 -0
- package/dist/shaders/pbr.js.map +1 -0
- package/dist/shaders/shadow.js +642 -0
- package/dist/shaders/shadow.js.map +1 -0
- package/dist/shaders/water.js +630 -0
- package/dist/shaders/water.js.map +1 -0
- package/dist/shadow/esm.js +235 -0
- package/dist/shadow/esm.js.map +1 -0
- package/dist/shadow/pcf_opt.js +182 -0
- package/dist/shadow/pcf_opt.js.map +1 -0
- package/dist/shadow/pcf_pd.js +190 -0
- package/dist/shadow/pcf_pd.js.map +1 -0
- package/dist/shadow/shadow_impl.js +15 -0
- package/dist/shadow/shadow_impl.js.map +1 -0
- package/dist/shadow/shadowmapper.js +709 -0
- package/dist/shadow/shadowmapper.js.map +1 -0
- package/dist/shadow/ssm.js +194 -0
- package/dist/shadow/ssm.js.map +1 -0
- package/dist/shadow/vsm.js +298 -0
- package/dist/shadow/vsm.js.map +1 -0
- package/dist/shapes/box.js +313 -0
- package/dist/shapes/box.js.map +1 -0
- package/dist/shapes/cylinder.js +74 -0
- package/dist/shapes/cylinder.js.map +1 -0
- package/dist/shapes/plane.js +48 -0
- package/dist/shapes/plane.js.map +1 -0
- package/dist/shapes/shape.js +33 -0
- package/dist/shapes/shape.js.map +1 -0
- package/dist/shapes/sphere.js +91 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/torus.js +100 -0
- package/dist/shapes/torus.js.map +1 -0
- package/dist/utility/aabbtree.js +390 -0
- package/dist/utility/aabbtree.js.map +1 -0
- package/dist/utility/bounding_volume.js +78 -0
- package/dist/utility/bounding_volume.js.map +1 -0
- package/dist/utility/panorama.js +163 -0
- package/dist/utility/panorama.js.map +1 -0
- package/dist/utility/pmrem.js +345 -0
- package/dist/utility/pmrem.js.map +1 -0
- package/dist/utility/shprojection.js +448 -0
- package/dist/utility/shprojection.js.map +1 -0
- package/dist/values.js +48 -0
- package/dist/values.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
import { Vector4, Vector3 } from '@zephyr3d/base';
|
|
2
|
+
import { BoundingBox } from '../../utility/bounding_volume.js';
|
|
3
|
+
import { Primitive } from '../../render/primitive.js';
|
|
4
|
+
import { Application } from '../../app.js';
|
|
5
|
+
import { RENDER_PASS_TYPE_SHADOWMAP } from '../../values.js';
|
|
6
|
+
|
|
7
|
+
/** @internal */ class TerrainPatch {
|
|
8
|
+
_terrain;
|
|
9
|
+
_geometry;
|
|
10
|
+
_geometryLines;
|
|
11
|
+
_quadtree;
|
|
12
|
+
_mipLevel;
|
|
13
|
+
_offsetX;
|
|
14
|
+
_offsetZ;
|
|
15
|
+
_step;
|
|
16
|
+
_boundingBox;
|
|
17
|
+
_lodDistance;
|
|
18
|
+
_maxError;
|
|
19
|
+
_parent;
|
|
20
|
+
_offsetScale;
|
|
21
|
+
constructor(terrain){
|
|
22
|
+
this._terrain = terrain;
|
|
23
|
+
this._geometry = null;
|
|
24
|
+
this._geometryLines = null;
|
|
25
|
+
this._mipLevel = 0;
|
|
26
|
+
this._offsetX = 0;
|
|
27
|
+
this._offsetZ = 0;
|
|
28
|
+
this._boundingBox = null;
|
|
29
|
+
this._parent = null;
|
|
30
|
+
this._offsetScale = null;
|
|
31
|
+
this._quadtree = null;
|
|
32
|
+
this._step = 0;
|
|
33
|
+
this._lodDistance = 0;
|
|
34
|
+
}
|
|
35
|
+
initialize(quadtree, parent, rowIndex, colIndex, baseVertices, normals, heightScale, elevations) {
|
|
36
|
+
const patchSize = quadtree.getPatchSize();
|
|
37
|
+
const rootSize = quadtree.getRootSize();
|
|
38
|
+
this._mipLevel = parent ? parent.getMipLevel() + 1 : 0;
|
|
39
|
+
const step = Math.floor((rootSize - 1) / (patchSize - 1)) >> this._mipLevel;
|
|
40
|
+
const interval = (patchSize - 1) * step;
|
|
41
|
+
const parentOffsetX = parent ? parent.getOffsetX() : 0;
|
|
42
|
+
const parentOffsetZ = parent ? parent.getOffsetZ() : 0;
|
|
43
|
+
this._offsetX = parentOffsetX + rowIndex * interval;
|
|
44
|
+
this._offsetZ = parentOffsetZ + colIndex * interval;
|
|
45
|
+
if (this._offsetX + interval >= quadtree.getRootSizeX() || this._offsetZ + interval >= quadtree.getRootSizeZ()) {
|
|
46
|
+
baseVertices = null;
|
|
47
|
+
}
|
|
48
|
+
this._quadtree = quadtree;
|
|
49
|
+
this._step = step;
|
|
50
|
+
this._parent = parent;
|
|
51
|
+
this._geometry = baseVertices ? new Primitive() : null;
|
|
52
|
+
this._geometryLines = baseVertices ? new Primitive() : null;
|
|
53
|
+
this._maxError = baseVertices ? this.computeMaxError() : 0;
|
|
54
|
+
if (baseVertices) {
|
|
55
|
+
const scaleX = this._quadtree.getScaleX();
|
|
56
|
+
const scaleZ = this._quadtree.getScaleZ();
|
|
57
|
+
if (step === 1) {
|
|
58
|
+
this._boundingBox = new BoundingBox();
|
|
59
|
+
this._boundingBox.minPoint.x = this._offsetX * scaleX;
|
|
60
|
+
this._boundingBox.minPoint.y = Number.MAX_VALUE;
|
|
61
|
+
this._boundingBox.minPoint.z = this._offsetZ * scaleZ;
|
|
62
|
+
this._boundingBox.maxPoint.x = this._offsetX * scaleX + (this._quadtree.getPatchSize() - 1) * this._step * scaleX;
|
|
63
|
+
this._boundingBox.maxPoint.y = -Number.MAX_VALUE;
|
|
64
|
+
this._boundingBox.maxPoint.z = this._offsetZ * scaleZ + (this._quadtree.getPatchSize() - 1) * this._step * scaleZ;
|
|
65
|
+
}
|
|
66
|
+
this.setupVertices(this.computeSkirtLength(), baseVertices, normals, heightScale, elevations);
|
|
67
|
+
this._offsetScale = new Vector4(this._step * scaleX, this._offsetX * scaleX, this._step * scaleZ, this._offsetZ * scaleZ);
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
getInstanceColor() {
|
|
72
|
+
return this._terrain.getInstanceColor();
|
|
73
|
+
}
|
|
74
|
+
getPickTarget() {
|
|
75
|
+
return this._terrain;
|
|
76
|
+
}
|
|
77
|
+
draw(ctx) {
|
|
78
|
+
const isShadowMapPass = ctx.renderPass.type === RENDER_PASS_TYPE_SHADOWMAP;
|
|
79
|
+
const primitive = this._quadtree.getTerrain().wireframe && !isShadowMapPass ? this.getGeometryWireframe() : this.getGeometry();
|
|
80
|
+
const material = this._quadtree.getTerrain().material;
|
|
81
|
+
if (isShadowMapPass) {
|
|
82
|
+
material.stateSet.useRasterizerState().setCullMode('front');
|
|
83
|
+
}
|
|
84
|
+
this._quadtree.getTerrain().material.draw(primitive, ctx);
|
|
85
|
+
if (isShadowMapPass) {
|
|
86
|
+
material.stateSet.defaultRasterizerState();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
setupCamera(viewportH, tanHalfFovy, maxPixelError) {
|
|
90
|
+
if (maxPixelError > 0 && tanHalfFovy > 0) {
|
|
91
|
+
this._lodDistance = this.computeLodDistance(viewportH, tanHalfFovy, maxPixelError);
|
|
92
|
+
} else {
|
|
93
|
+
this._lodDistance = -1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
getName() {
|
|
97
|
+
return 'TerrainPatch';
|
|
98
|
+
}
|
|
99
|
+
getXForm() {
|
|
100
|
+
return this._quadtree.getTerrain();
|
|
101
|
+
}
|
|
102
|
+
getBoneMatrices() {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
getInvBindMatrix() {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
getSortDistance(camera) {
|
|
109
|
+
return this._quadtree.getTerrain().getSortDistance(camera);
|
|
110
|
+
}
|
|
111
|
+
isTransparency() {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
isUnlit() {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
isBatchable() {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
setupVertices(skirtLength, baseVertices, normalVectors, heightScale, elevations) {
|
|
121
|
+
const that = this;
|
|
122
|
+
const sx = this._quadtree.getScaleX() * this._step;
|
|
123
|
+
const sz = this._quadtree.getScaleZ() * this._step;
|
|
124
|
+
const tx = this._quadtree.getScaleX() * this._offsetX;
|
|
125
|
+
const tz = this._quadtree.getScaleZ() * this._offsetZ;
|
|
126
|
+
function setNormalAndHeight(heights, normals, index, x, z, width, hDelta) {
|
|
127
|
+
const k = x + z * width;
|
|
128
|
+
const h = elevations[k] * heightScale;
|
|
129
|
+
normals[index * 3 + 0] = normalVectors[k].x;
|
|
130
|
+
normals[index * 3 + 1] = normalVectors[k].y;
|
|
131
|
+
normals[index * 3 + 2] = normalVectors[k].z;
|
|
132
|
+
heights[index * 3 + 0] = baseVertices[index * 3 + 0] * sx + tx;
|
|
133
|
+
heights[index * 3 + 1] = h + hDelta;
|
|
134
|
+
heights[index * 3 + 2] = baseVertices[index * 3 + 2] * sz + tz;
|
|
135
|
+
if (that._boundingBox) {
|
|
136
|
+
if (that._boundingBox.maxPoint.y < h) {
|
|
137
|
+
that._boundingBox.maxPoint.y = h;
|
|
138
|
+
}
|
|
139
|
+
if (that._boundingBox.minPoint.y > h) {
|
|
140
|
+
that._boundingBox.minPoint.y = h;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return index + 1;
|
|
144
|
+
}
|
|
145
|
+
const patchSize = this._quadtree.getPatchSize();
|
|
146
|
+
const numVerts = (patchSize + 2) * (patchSize + 2);
|
|
147
|
+
const heights = new Float32Array(numVerts * 3);
|
|
148
|
+
const normals = new Float32Array(numVerts * 3);
|
|
149
|
+
let x = this._offsetX;
|
|
150
|
+
let z = this._offsetZ;
|
|
151
|
+
let t = 0;
|
|
152
|
+
const hf = this._quadtree.getHeightField();
|
|
153
|
+
const w = hf.getSizeX();
|
|
154
|
+
t = setNormalAndHeight(heights, normals, t, x, z, w, -skirtLength);
|
|
155
|
+
for(let i = 0; i < patchSize; i++, x += this._step){
|
|
156
|
+
t = setNormalAndHeight(heights, normals, t, x, z, w, -skirtLength);
|
|
157
|
+
}
|
|
158
|
+
t = setNormalAndHeight(heights, normals, t, x - this._step, z, w, -skirtLength);
|
|
159
|
+
z = this._offsetZ;
|
|
160
|
+
for(let i = 0; i < patchSize; i++, z += this._step){
|
|
161
|
+
x = this._offsetX;
|
|
162
|
+
t = setNormalAndHeight(heights, normals, t, x, z, w, -skirtLength);
|
|
163
|
+
for(let j = 0; j < patchSize; j++, x += this._step){
|
|
164
|
+
t = setNormalAndHeight(heights, normals, t, x, z, w, 0);
|
|
165
|
+
}
|
|
166
|
+
t = setNormalAndHeight(heights, normals, t, x - this._step, z, w, -skirtLength);
|
|
167
|
+
}
|
|
168
|
+
x = this._offsetX;
|
|
169
|
+
z -= this._step;
|
|
170
|
+
t = setNormalAndHeight(heights, normals, t, x, z, w, -skirtLength);
|
|
171
|
+
for(let i = 0; i < patchSize; i++, x += this._step){
|
|
172
|
+
t = setNormalAndHeight(heights, normals, t, x, z, w, -skirtLength);
|
|
173
|
+
}
|
|
174
|
+
t = setNormalAndHeight(heights, normals, t, x - this._step, z, w, -skirtLength);
|
|
175
|
+
const heightArray = Application.instance.device.createVertexBuffer('position_f32x3', heights);
|
|
176
|
+
const normalArray = Application.instance.device.createVertexBuffer('normal_f32x3', normals);
|
|
177
|
+
this._geometry.setVertexBuffer(heightArray);
|
|
178
|
+
this._geometry.setVertexBuffer(normalArray);
|
|
179
|
+
this._geometry.setIndexBuffer(this._quadtree.getIndices());
|
|
180
|
+
this._geometry.indexStart = 0;
|
|
181
|
+
this._geometry.indexCount = this._quadtree.getIndices().length;
|
|
182
|
+
this._geometry.primitiveType = 'triangle-strip';
|
|
183
|
+
this._geometryLines.setVertexBuffer(heightArray);
|
|
184
|
+
this._geometryLines.setVertexBuffer(normalArray);
|
|
185
|
+
this._geometryLines.setIndexBuffer(this._quadtree.getIndicesWireframe());
|
|
186
|
+
this._geometryLines.indexStart = 0;
|
|
187
|
+
this._geometryLines.indexCount = this._quadtree.getIndicesWireframe().length;
|
|
188
|
+
this._geometryLines.primitiveType = 'line-list';
|
|
189
|
+
}
|
|
190
|
+
getOffsetScale() {
|
|
191
|
+
if (!this._offsetScale) {
|
|
192
|
+
const scaleX = this._quadtree.getScaleX();
|
|
193
|
+
const scaleZ = this._quadtree.getScaleZ();
|
|
194
|
+
this._offsetScale = new Vector4(this._step * scaleX, this._offsetX * scaleX, this._step * scaleZ, this._offsetZ * scaleZ);
|
|
195
|
+
}
|
|
196
|
+
return this._offsetScale;
|
|
197
|
+
}
|
|
198
|
+
getBoundingBox() {
|
|
199
|
+
return this._boundingBox;
|
|
200
|
+
}
|
|
201
|
+
setBoundingBox(bbox) {
|
|
202
|
+
this._boundingBox = bbox;
|
|
203
|
+
}
|
|
204
|
+
getMipLevel() {
|
|
205
|
+
return this._mipLevel;
|
|
206
|
+
}
|
|
207
|
+
getOffsetX() {
|
|
208
|
+
return this._offsetX;
|
|
209
|
+
}
|
|
210
|
+
getOffsetZ() {
|
|
211
|
+
return this._offsetZ;
|
|
212
|
+
}
|
|
213
|
+
getStep() {
|
|
214
|
+
return this._step;
|
|
215
|
+
}
|
|
216
|
+
getLODDistance() {
|
|
217
|
+
return this._lodDistance;
|
|
218
|
+
}
|
|
219
|
+
getGeometry() {
|
|
220
|
+
return this._geometry;
|
|
221
|
+
}
|
|
222
|
+
getGeometryWireframe() {
|
|
223
|
+
return this._geometryLines;
|
|
224
|
+
}
|
|
225
|
+
getHeight(x, z) {
|
|
226
|
+
const startX = this._offsetX + this._step * Math.floor((x - this._offsetX) / this._step);
|
|
227
|
+
const startZ = this._offsetZ + this._step * Math.floor((z - this._offsetZ) / this._step);
|
|
228
|
+
const endX = startX == x ? startX : startX + this._step;
|
|
229
|
+
const endZ = startZ == z ? startZ : startZ + this._step;
|
|
230
|
+
const hf = this._quadtree.getHeightField();
|
|
231
|
+
const lt_height = hf.getHeight(startX, startZ);
|
|
232
|
+
const rt_height = hf.getHeight(endX, startZ);
|
|
233
|
+
const lb_height = hf.getHeight(startX, endZ);
|
|
234
|
+
const rb_height = hf.getHeight(endX, endZ);
|
|
235
|
+
const t1 = (x - startX) / this._step;
|
|
236
|
+
const t2 = (z - startZ) / this._step;
|
|
237
|
+
const h1 = lt_height + (rt_height - lt_height) * t1;
|
|
238
|
+
const h2 = lb_height + (rb_height - lb_height) * t1;
|
|
239
|
+
return h1 + (h2 - h1) * t2;
|
|
240
|
+
}
|
|
241
|
+
computeMaxError() {
|
|
242
|
+
if (this._step === 1) {
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
let maxError = 0;
|
|
246
|
+
const dimension = this._step * (this._quadtree.getPatchSize() - 1);
|
|
247
|
+
const rootSize = this._quadtree.getRootSize();
|
|
248
|
+
const hf = this._quadtree.getHeightField();
|
|
249
|
+
for(let i = this._offsetZ; i <= this._offsetZ + dimension; i++){
|
|
250
|
+
for(let j = this._offsetX; j <= this._offsetX + dimension; j++){
|
|
251
|
+
const i00 = this._offsetZ + Math.floor((i - this._offsetZ) / this._step) * this._step;
|
|
252
|
+
const j00 = this._offsetX + Math.floor((j - this._offsetX) / this._step) * this._step;
|
|
253
|
+
if (i00 === rootSize - 1 || j00 === rootSize - 1) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const i11 = i00 + this._step;
|
|
257
|
+
const j11 = j00 + this._step;
|
|
258
|
+
const h00 = hf.getHeight(j00, i00);
|
|
259
|
+
const h01 = hf.getHeight(j11, i00);
|
|
260
|
+
const h10 = hf.getHeight(j00, i11);
|
|
261
|
+
const h11 = hf.getHeight(j11, i11);
|
|
262
|
+
const factorZ = (i - i00) / this._step;
|
|
263
|
+
const factorX = (j - j00) / this._step;
|
|
264
|
+
const h = hf.getHeight(j, i);
|
|
265
|
+
const h0 = h00 + factorX * (h01 - h00);
|
|
266
|
+
const h1 = h10 + factorX * (h11 - h10);
|
|
267
|
+
const h2 = h0 + factorZ * (h1 - h0);
|
|
268
|
+
const err = Math.abs(h - h2);
|
|
269
|
+
if (err > maxError) {
|
|
270
|
+
maxError = err;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return maxError;
|
|
275
|
+
}
|
|
276
|
+
computeSkirtLength() {
|
|
277
|
+
let skirtLength = 0;
|
|
278
|
+
let p = this._parent;
|
|
279
|
+
while(p){
|
|
280
|
+
const f = this.computeErrorMetric(p);
|
|
281
|
+
if (f > skirtLength) {
|
|
282
|
+
skirtLength = f;
|
|
283
|
+
}
|
|
284
|
+
p = p._parent;
|
|
285
|
+
}
|
|
286
|
+
return skirtLength;
|
|
287
|
+
}
|
|
288
|
+
computeErrorMetric(other) {
|
|
289
|
+
let errMetric = 0;
|
|
290
|
+
if (other.getMipLevel() > this._mipLevel) {
|
|
291
|
+
const otherOffsetX = other.getOffsetX();
|
|
292
|
+
const otherOffsetZ = other.getOffsetZ();
|
|
293
|
+
const otherStep = other.getStep();
|
|
294
|
+
const otherDimension = other.getStep() * this._quadtree.getPatchSize();
|
|
295
|
+
for(let i = otherOffsetZ; i < otherOffsetZ + otherDimension; i += otherStep){
|
|
296
|
+
for(let j = otherOffsetX; j < otherOffsetX + otherDimension; j += otherStep){
|
|
297
|
+
const err = Math.abs(this.getHeight(j, i) - other.getHeight(j, i));
|
|
298
|
+
if (err > errMetric) {
|
|
299
|
+
errMetric = err;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
} else if (other.getMipLevel() < this._mipLevel) {
|
|
304
|
+
const dimension = this._step * (this._quadtree.getPatchSize() - 1);
|
|
305
|
+
for(let i = this._offsetZ; i <= this._offsetZ + dimension; i += this._step){
|
|
306
|
+
for(let j = this._offsetX; j <= this._offsetX + dimension; j += this._step){
|
|
307
|
+
const err = Math.abs(this.getHeight(j, i) - other.getHeight(j, i));
|
|
308
|
+
if (err > errMetric) {
|
|
309
|
+
errMetric = err;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return errMetric;
|
|
315
|
+
}
|
|
316
|
+
computeBoundingBox(box) {
|
|
317
|
+
const [maxHeight, minHeight] = this.computeHeightBound();
|
|
318
|
+
const scaleX = this._quadtree.getScaleX();
|
|
319
|
+
const scaleZ = this._quadtree.getScaleZ();
|
|
320
|
+
box.minPoint = new Vector3(this._offsetX * scaleX, minHeight, this._offsetZ * scaleZ);
|
|
321
|
+
box.maxPoint = new Vector3(this._offsetX * scaleX + (this._quadtree.getPatchSize() - 1) * this._step * scaleX, maxHeight, this._offsetZ * scaleZ + (this._quadtree.getPatchSize() - 1) * this._step * scaleZ);
|
|
322
|
+
}
|
|
323
|
+
computeLodDistance(viewportH, tanHalfFovy, maxPixelError) {
|
|
324
|
+
return 0.5 * this._maxError * viewportH / (maxPixelError * tanHalfFovy);
|
|
325
|
+
}
|
|
326
|
+
sqrDistanceToPoint(point) {
|
|
327
|
+
const bbox = this.getBoundingBox();
|
|
328
|
+
const radius = Math.sqrt(bbox.extents.x * bbox.extents.x + bbox.extents.z * bbox.extents.z);
|
|
329
|
+
const dx = point.x - bbox.center.x;
|
|
330
|
+
const dz = point.z - bbox.center.z;
|
|
331
|
+
const s = Math.max(0, Math.sqrt(dx * dx + dz * dz) - radius);
|
|
332
|
+
const t = point.y > bbox.maxPoint.y ? point.y - bbox.maxPoint.y : point.y < bbox.minPoint.y ? bbox.minPoint.y - point.y : 0;
|
|
333
|
+
return s * s + t * t;
|
|
334
|
+
}
|
|
335
|
+
sqrDistancePointToTriangle(P, t0, t1, t2) {
|
|
336
|
+
const B = t0;
|
|
337
|
+
const E0 = Vector3.sub(t1, B);
|
|
338
|
+
const E1 = Vector3.sub(t2, B);
|
|
339
|
+
const D = Vector3.sub(B, P);
|
|
340
|
+
const a = Vector3.dot(E0, E0);
|
|
341
|
+
const b = Vector3.dot(E0, E1);
|
|
342
|
+
const c = Vector3.dot(E1, E1);
|
|
343
|
+
const d = Vector3.dot(E0, D);
|
|
344
|
+
const e = Vector3.dot(E1, D);
|
|
345
|
+
const f = Vector3.dot(D, D);
|
|
346
|
+
const det = a * c - b * b;
|
|
347
|
+
let s = b * e - c * d;
|
|
348
|
+
let t = b * d - a * e;
|
|
349
|
+
let sqrDistance;
|
|
350
|
+
if (s + t <= det) {
|
|
351
|
+
if (s < 0) {
|
|
352
|
+
if (t < 0) {
|
|
353
|
+
if (d < 0) {
|
|
354
|
+
t = 0;
|
|
355
|
+
if (-d >= a) {
|
|
356
|
+
s = 1;
|
|
357
|
+
sqrDistance = a + 2 * d + f;
|
|
358
|
+
} else {
|
|
359
|
+
s = -d / a;
|
|
360
|
+
sqrDistance = d * s + f;
|
|
361
|
+
}
|
|
362
|
+
} else {
|
|
363
|
+
s = 0;
|
|
364
|
+
if (e >= 0) {
|
|
365
|
+
t = 0;
|
|
366
|
+
sqrDistance = f;
|
|
367
|
+
} else {
|
|
368
|
+
if (-e >= c) {
|
|
369
|
+
t = 1;
|
|
370
|
+
sqrDistance = c + 2 * e + f;
|
|
371
|
+
} else {
|
|
372
|
+
t = -e / c;
|
|
373
|
+
sqrDistance = e * t + f;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
s = 0;
|
|
379
|
+
if (e >= 0) {
|
|
380
|
+
t = 0;
|
|
381
|
+
sqrDistance = f;
|
|
382
|
+
} else {
|
|
383
|
+
if (-e >= c) {
|
|
384
|
+
t = 1;
|
|
385
|
+
sqrDistance = c + 2 * e + f;
|
|
386
|
+
} else {
|
|
387
|
+
t = -e / c;
|
|
388
|
+
sqrDistance = e * t + f;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
} else {
|
|
393
|
+
if (t < 0) {
|
|
394
|
+
t = 0;
|
|
395
|
+
if (d >= 0) {
|
|
396
|
+
s = 0;
|
|
397
|
+
sqrDistance = f;
|
|
398
|
+
} else {
|
|
399
|
+
if (-d >= a) {
|
|
400
|
+
s = 1;
|
|
401
|
+
sqrDistance = a + 2 * d + f;
|
|
402
|
+
} else {
|
|
403
|
+
s = -d / a;
|
|
404
|
+
sqrDistance = d * s + f;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
s /= det;
|
|
409
|
+
t /= det;
|
|
410
|
+
sqrDistance = s * (a * s + b * t + 2 * d) + t * (b * s + c * t + 2 * e) + f;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
} else {
|
|
414
|
+
if (s < 0) {
|
|
415
|
+
const tmp0 = b + d;
|
|
416
|
+
const tmp1 = c + e;
|
|
417
|
+
if (tmp1 > tmp0) {
|
|
418
|
+
const numer = tmp1 - tmp0;
|
|
419
|
+
const denom = a - 2 * b + c;
|
|
420
|
+
if (numer >= denom) {
|
|
421
|
+
s = 1;
|
|
422
|
+
t = 0;
|
|
423
|
+
sqrDistance = a + 2 * d + f;
|
|
424
|
+
} else {
|
|
425
|
+
s = numer / denom;
|
|
426
|
+
t = 1 - s;
|
|
427
|
+
sqrDistance = s * (a * s + b * t + 2 * d) + t * (b * s + c * t + 2 * e) + f;
|
|
428
|
+
}
|
|
429
|
+
} else {
|
|
430
|
+
s = 0;
|
|
431
|
+
if (tmp1 <= 0) {
|
|
432
|
+
t = 1;
|
|
433
|
+
sqrDistance = c + 2 * e + f;
|
|
434
|
+
} else {
|
|
435
|
+
if (e >= 0) {
|
|
436
|
+
t = 0;
|
|
437
|
+
sqrDistance = f;
|
|
438
|
+
} else {
|
|
439
|
+
t = -e / c;
|
|
440
|
+
sqrDistance = e * t + f;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
} else {
|
|
445
|
+
if (t < 0) {
|
|
446
|
+
const tmp0 = b + e;
|
|
447
|
+
const tmp1 = a + d;
|
|
448
|
+
if (tmp1 > tmp0) {
|
|
449
|
+
const numer = tmp1 - tmp0;
|
|
450
|
+
const denom = a - 2 * b + c;
|
|
451
|
+
if (numer >= denom) {
|
|
452
|
+
t = 1;
|
|
453
|
+
s = 0;
|
|
454
|
+
sqrDistance = c + 2 * e + f;
|
|
455
|
+
} else {
|
|
456
|
+
t = numer / denom;
|
|
457
|
+
s = 1 - t;
|
|
458
|
+
sqrDistance = s * (a * s + b * t + 2 * d) + t * (b * s + c * t + 2 * e) + f;
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
t = 0;
|
|
462
|
+
if (tmp1 <= 0) {
|
|
463
|
+
s = 1;
|
|
464
|
+
sqrDistance = a + 2 * d + f;
|
|
465
|
+
} else {
|
|
466
|
+
if (d >= 0) {
|
|
467
|
+
s = 0;
|
|
468
|
+
sqrDistance = f;
|
|
469
|
+
} else {
|
|
470
|
+
s = -d / a;
|
|
471
|
+
sqrDistance = d * s + f;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
} else {
|
|
476
|
+
const numer = c + e - b - d;
|
|
477
|
+
if (numer <= 0) {
|
|
478
|
+
s = 0;
|
|
479
|
+
t = 1;
|
|
480
|
+
sqrDistance = c + 2 * e + f;
|
|
481
|
+
} else {
|
|
482
|
+
const denom = a - 2 * b + c;
|
|
483
|
+
if (numer >= denom) {
|
|
484
|
+
s = 1;
|
|
485
|
+
t = 0;
|
|
486
|
+
sqrDistance = a + 2 * d + f;
|
|
487
|
+
} else {
|
|
488
|
+
s = numer / denom;
|
|
489
|
+
t = 1 - s;
|
|
490
|
+
sqrDistance = s * (a * s + b * t + 2 * d) + t * (b * s + c * t + 2 * e) + f;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (sqrDistance < 0) {
|
|
497
|
+
sqrDistance = 0;
|
|
498
|
+
}
|
|
499
|
+
return sqrDistance;
|
|
500
|
+
}
|
|
501
|
+
computeHeightBound() {
|
|
502
|
+
let maxHeight = -Number.MAX_VALUE;
|
|
503
|
+
let minHeight = Number.MAX_VALUE;
|
|
504
|
+
const dimension = this._step * (this._quadtree.getPatchSize() - 1);
|
|
505
|
+
const hf = this._quadtree.getHeightField();
|
|
506
|
+
const z = Math.min(hf.getSizeZ() - 1, this._offsetZ + dimension);
|
|
507
|
+
const x = Math.min(hf.getSizeX() - 1, this._offsetX + dimension);
|
|
508
|
+
for(let i = this._offsetZ; i <= z; i++){
|
|
509
|
+
for(let j = this._offsetX; j <= x; j++){
|
|
510
|
+
const h = hf.getHeight(j, i);
|
|
511
|
+
if (h > maxHeight) {
|
|
512
|
+
maxHeight = h;
|
|
513
|
+
}
|
|
514
|
+
if (h < minHeight) {
|
|
515
|
+
minHeight = h;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return [
|
|
520
|
+
maxHeight,
|
|
521
|
+
minHeight
|
|
522
|
+
];
|
|
523
|
+
}
|
|
524
|
+
isDummy() {
|
|
525
|
+
return !this._geometry && !!this._quadtree;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export { TerrainPatch };
|
|
530
|
+
//# sourceMappingURL=patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|