three-base 2.0.134 → 2.0.142
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/DirectionalLight.d.ts +6 -6
- package/DirectionalLight.js +68 -68
- package/DirectionalLight.ts +70 -0
- package/EventMap.d.ts +103 -0
- package/EventMap.js +17 -0
- package/EventMap.ts +139 -0
- package/EventMesh.d.ts +18 -18
- package/EventMesh.js +59 -59
- package/EventMesh.ts +60 -0
- package/ExtrudeMesh.d.ts +112 -112
- package/ExtrudeMesh.js +342 -366
- package/ExtrudeMesh.ts +553 -0
- package/FPScontrol.d.ts +511 -71
- package/FPScontrol.js +1799 -505
- package/FPScontrol.ts +1855 -0
- package/Fire/Fire.d.ts +28 -28
- package/Fire/Fire.js +80 -79
- package/Fire/Fire.ts +89 -0
- package/Fire/{FireGromtry.d.ts → FireGeometry.d.ts} +9 -9
- package/Fire/{FireGromtry.js → FireGeometry.js} +40 -40
- package/Fire/FireGeometry.ts +40 -0
- package/Fire/FireMaterial.d.ts +28 -28
- package/Fire/FireMaterial.js +32 -32
- package/Fire/FireMaterial.ts +89 -0
- package/Fire/index.d.ts +2 -1
- package/Fire/index.js +2 -1
- package/Fire/index.ts +2 -0
- package/GLTFDracoLoader.d.ts +71 -0
- package/GLTFDracoLoader.js +266 -0
- package/GLTFDracoLoader.ts +430 -0
- package/Grass/Grass.d.ts +8 -8
- package/Grass/Grass.js +38 -38
- package/Grass/Grass.ts +38 -0
- package/Grass/index.d.ts +2 -1
- package/Grass/index.js +2 -1
- package/Grass/index.ts +2 -0
- package/Ground1/Ground1.d.ts +10 -11
- package/Ground1/Ground1.js +95 -91
- package/Ground1/Ground1.ts +114 -0
- package/Ground1/index.d.ts +1 -1
- package/Ground1/index.js +1 -1
- package/Ground1/index.ts +1 -0
- package/MeshBase.d.ts +36 -35
- package/MeshBase.js +247 -223
- package/MeshBase.ts +253 -0
- package/Mirror.d.ts +25 -25
- package/Mirror.js +143 -139
- package/Mirror.ts +203 -0
- package/MktMesh/MktMesh.d.ts +291 -0
- package/MktMesh/MktMesh.js +1045 -0
- package/MktMesh/MktMesh.ts +1075 -0
- package/MktMesh/assetUrl.d.ts +35 -0
- package/MktMesh/assetUrl.js +69 -0
- package/MktMesh/assetUrl.ts +69 -0
- package/MktMesh/mktMappingShader.d.ts +12 -0
- package/MktMesh/mktMappingShader.js +139 -0
- package/MktMesh/mktMappingShader.ts +139 -0
- package/MktMesh/mktShader.d.ts +263 -0
- package/MktMesh/mktShader.js +1248 -0
- package/MktMesh/mktShader.ts +1344 -0
- package/MktMesh/panoBitmapTexture.d.ts +25 -0
- package/MktMesh/panoBitmapTexture.js +52 -0
- package/MktMesh/panoBitmapTexture.ts +54 -0
- package/MktMesh/panoSlotBind.d.ts +29 -0
- package/MktMesh/panoSlotBind.js +106 -0
- package/MktMesh/panoSlotBind.ts +153 -0
- package/MktMesh/panoSlotRoster.d.ts +22 -0
- package/MktMesh/panoSlotRoster.js +169 -0
- package/MktMesh/panoSlotRoster.ts +168 -0
- package/MktMesh/panoTileStitcher.d.ts +119 -0
- package/MktMesh/panoTileStitcher.js +533 -0
- package/MktMesh/panoTileStitcher.ts +616 -0
- package/MktMesh/types.d.ts +75 -0
- package/MktMesh/types.js +1 -0
- package/MktMesh/types.ts +87 -0
- package/MktMesh/wallCapTessellate.d.ts +33 -0
- package/MktMesh/wallCapTessellate.js +97 -0
- package/MktMesh/wallCapTessellate.ts +68 -0
- package/PipeMesh/PathGeometry.d.ts +44 -44
- package/PipeMesh/PathGeometry.js +307 -300
- package/PipeMesh/PathGeometry.ts +343 -0
- package/PipeMesh/PathPoint.d.ts +17 -17
- package/PipeMesh/PathPoint.js +31 -31
- package/PipeMesh/PathPoint.ts +36 -0
- package/PipeMesh/PathPointList.d.ts +31 -31
- package/PipeMesh/PathPointList.js +209 -208
- package/PipeMesh/PathPointList.ts +227 -0
- package/PipeMesh/PathTubeGeometry.d.ts +25 -25
- package/PipeMesh/PathTubeGeometry.js +130 -130
- package/PipeMesh/PathTubeGeometry.ts +146 -0
- package/PipeMesh/PipeMesh.d.ts +25 -25
- package/PipeMesh/PipeMesh.js +63 -63
- package/PipeMesh/PipeMesh.ts +76 -0
- package/PipeMesh/index.d.ts +1 -1
- package/PipeMesh/index.js +1 -1
- package/PipeMesh/index.ts +1 -0
- package/PlaneModal1/PlaneModal1.d.ts +34 -31
- package/PlaneModal1/PlaneModal1.js +109 -105
- package/PlaneModal1/PlaneModal1.ts +138 -0
- package/PlaneModal1/index.d.ts +1 -1
- package/PlaneModal1/index.js +1 -1
- package/PlaneModal1/index.ts +1 -0
- package/PlaneText.d.ts +27 -39
- package/PlaneText.js +35 -30
- package/PlaneText.ts +55 -0
- package/PlaneWithHtml.d.ts +13 -11
- package/PlaneWithHtml.js +64 -63
- package/PlaneWithHtml.ts +70 -0
- package/PointLight/PointLight.d.ts +13 -14
- package/PointLight/PointLight.js +64 -70
- package/PointLight/PointLight.ts +67 -0
- package/PointLight/index.d.ts +1 -1
- package/PointLight/index.js +1 -1
- package/PointLight/index.ts +1 -0
- package/README.md +110 -79
- package/Sky/Sky.d.ts +9 -9
- package/Sky/Sky.js +22 -22
- package/Sky/Sky.ts +22 -0
- package/Sky/index.d.ts +1 -1
- package/Sky/index.js +1 -1
- package/Sky/index.ts +1 -0
- package/SpotLight.d.ts +6 -6
- package/SpotLight.js +72 -72
- package/SpotLight.ts +74 -0
- package/SpriteModal1/SpriteModal1.d.ts +33 -30
- package/SpriteModal1/SpriteModal1.js +116 -110
- package/SpriteModal1/SpriteModal1.ts +146 -0
- package/SpriteModal1/index.d.ts +1 -1
- package/SpriteModal1/index.js +1 -1
- package/SpriteModal1/index.ts +1 -0
- package/SpriteText.d.ts +46 -45
- package/SpriteText.js +176 -163
- package/SpriteText.ts +205 -0
- package/SpriteText2.d.ts +48 -47
- package/SpriteText2.js +223 -198
- package/SpriteText2.ts +258 -0
- package/SpriteText3.d.ts +86 -0
- package/SpriteText3.js +519 -0
- package/SpriteText3.ts +599 -0
- package/SpriteWithHtml.d.ts +9 -7
- package/SpriteWithHtml.js +44 -44
- package/SpriteWithHtml.ts +50 -0
- package/Text3D/Text3D.d.ts +20 -20
- package/Text3D/Text3D.js +58 -62
- package/Text3D/Text3D.ts +77 -0
- package/Text3D/fontController.d.ts +60 -59
- package/Text3D/fontController.js +166 -199
- package/Text3D/fontController.ts +209 -0
- package/Text3D/index.d.ts +1 -1
- package/Text3D/index.js +1 -1
- package/Text3D/index.ts +1 -0
- package/ThreeBase.d.ts +248 -97
- package/ThreeBase.js +1202 -613
- package/ThreeBase.ts +1314 -0
- package/ThreeMouse.d.ts +54 -40
- package/ThreeMouse.js +453 -407
- package/ThreeMouse.ts +472 -0
- package/Transition.d.ts +45 -40
- package/Transition.js +209 -210
- package/Transition.ts +242 -0
- package/Water/Water.d.ts +5 -5
- package/Water/Water.js +44 -26
- package/Water/Water.ts +45 -0
- package/Water/index.d.ts +2 -0
- package/Water/index.js +2 -0
- package/Water/index.ts +2 -0
- package/WaterFlow/FloatingDuck.d.ts +88 -0
- package/WaterFlow/FloatingDuck.js +307 -0
- package/WaterFlow/FloatingDuck.ts +445 -0
- package/WaterFlow/GPUFluidSimulation.d.ts +56 -0
- package/WaterFlow/GPUFluidSimulation.js +785 -0
- package/WaterFlow/GPUFluidSimulation.ts +827 -0
- package/WaterFlow/ReservoirSystem.d.ts +106 -0
- package/WaterFlow/ReservoirSystem.js +621 -0
- package/WaterFlow/ReservoirSystem.ts +754 -0
- package/WaterFlow/SPHField.d.ts +35 -0
- package/WaterFlow/SPHField.js +204 -0
- package/WaterFlow/SPHField.ts +228 -0
- package/WaterFlow/ScreenSpaceFluidPass.d.ts +69 -0
- package/WaterFlow/ScreenSpaceFluidPass.js +736 -0
- package/WaterFlow/ScreenSpaceFluidPass.ts +789 -0
- package/WaterFlow/ShallowWaterSurface.d.ts +45 -0
- package/WaterFlow/ShallowWaterSurface.js +441 -0
- package/WaterFlow/ShallowWaterSurface.ts +510 -0
- package/WaterFlow/WaterFlow.d.ts +87 -0
- package/WaterFlow/WaterFlow.js +171 -0
- package/WaterFlow/WaterFlow.ts +219 -0
- package/WaterFlow/types.d.ts +161 -0
- package/WaterFlow/types.js +1 -0
- package/WaterFlow/types.ts +189 -0
- package/WaterFlow/waterFlowPass.d.ts +3 -0
- package/WaterFlow/waterFlowPass.js +20 -0
- package/WaterFlow/waterFlowPass.ts +40 -0
- package/collisionOBB.d.ts +42 -0
- package/collisionOBB.js +112 -0
- package/collisionOBB.ts +108 -0
- package/declare.d.ts +23 -165
- package/index.d.ts +1 -1
- package/index.js +1 -2
- package/index.ts +1 -0
- package/instanced/InstancedBatch.d.ts +57 -0
- package/instanced/InstancedBatch.js +348 -0
- package/instanced/InstancedBatch.ts +406 -0
- package/instanced/InstancedChild.d.ts +174 -0
- package/instanced/InstancedChild.js +264 -0
- package/instanced/InstancedChild.ts +327 -0
- package/instanced/InstancedGroup.d.ts +43 -0
- package/instanced/InstancedGroup.js +126 -0
- package/instanced/InstancedGroup.ts +137 -0
- package/{InstancedMeshBase.d.ts → instanced/InstancedMeshBase.d.ts} +38 -39
- package/{InstancedMeshBase.js → instanced/InstancedMeshBase.js} +282 -293
- package/instanced/InstancedMeshBase.ts +292 -0
- package/instanced/InstancedTemplate.d.ts +46 -0
- package/instanced/InstancedTemplate.js +125 -0
- package/instanced/InstancedTemplate.ts +188 -0
- package/keyControls.d.ts +30 -0
- package/{keyContorls.js → keyControls.js} +101 -98
- package/keyControls.ts +107 -0
- package/lensflare/LensFlare.d.ts +39 -0
- package/lensflare/LensFlare.js +373 -0
- package/lensflare/LensFlare.ts +448 -0
- package/lensflare/lensflare0.png +0 -0
- package/lensflare/lensflare3.png +0 -0
- package/lensflare/lensflare_custom.png +0 -0
- package/lensflare/lensflare_hex_ghost.png +0 -0
- package/lensflare/lensflare_hex_main.png +0 -0
- package/package.json +101 -26
- package/pass/bloom_pass.d.ts +2 -2
- package/pass/bloom_pass.js +188 -101
- package/pass/bloom_pass.ts +243 -0
- package/pass/cover_pass.d.ts +2 -2
- package/pass/cover_pass.js +122 -99
- package/pass/cover_pass.ts +182 -0
- package/pass/debugDepthState.d.ts +20 -0
- package/pass/debugDepthState.js +9 -0
- package/pass/debugDepthState.ts +22 -0
- package/pass/depthTestBias.d.ts +12 -0
- package/pass/depthTestBias.js +12 -0
- package/pass/depthTestBias.ts +12 -0
- package/pass/effectUserData.d.ts +27 -0
- package/pass/effectUserData.js +1 -0
- package/pass/effectUserData.ts +46 -0
- package/pass/frosted_glass_pass.d.ts +2 -2
- package/pass/frosted_glass_pass.js +167 -186
- package/pass/frosted_glass_pass.ts +288 -0
- package/pass/fsQuad.d.ts +9 -9
- package/pass/fsQuad.js +28 -28
- package/pass/fsQuad.ts +34 -0
- package/pass/glow_pass.d.ts +2 -2
- package/pass/glow_pass.js +449 -233
- package/pass/glow_pass.ts +654 -0
- package/pass/screen_bloom_pass.d.ts +11 -0
- package/pass/screen_bloom_pass.js +235 -0
- package/pass/screen_bloom_pass.ts +263 -0
- package/pass/ssao_pass.d.ts +88 -11
- package/pass/ssao_pass.js +802 -288
- package/pass/ssao_pass.ts +918 -0
- package/pass/stroke_pass.d.ts +2 -2
- package/pass/stroke_pass.js +329 -258
- package/pass/stroke_pass.ts +638 -0
- package/shaders/FXAAShaderMaterial.d.ts +3 -3
- package/shaders/FXAAShaderMaterial.js +23 -66
- package/shaders/FXAAShaderMaterial.ts +201 -0
- package/shaders/baseDepthVisShader.d.ts +11 -0
- package/shaders/baseDepthVisShader.js +36 -0
- package/shaders/baseDepthVisShader.ts +36 -0
- package/shaders/baseTextureToRenderShader.d.ts +2 -2
- package/shaders/baseTextureToRenderShader.js +55 -60
- package/shaders/baseTextureToRenderShader.ts +232 -0
- package/shaders/copyShader.d.ts +3 -3
- package/shaders/copyShader.js +13 -14
- package/shaders/copyShader.ts +32 -0
- package/shaders/debugDepthCompareShader.d.ts +14 -0
- package/shaders/debugDepthCompareShader.js +49 -0
- package/shaders/debugDepthCompareShader.ts +50 -0
- package/shaders/debugDepthJudgeShader.d.ts +18 -0
- package/shaders/debugDepthJudgeShader.js +52 -0
- package/shaders/debugDepthJudgeShader.ts +54 -0
- package/shaders/debugExcludedShader.d.ts +13 -0
- package/shaders/debugExcludedShader.js +46 -0
- package/shaders/debugExcludedShader.ts +48 -0
- package/spriteTextBg.d.ts +1 -0
- package/spriteTextBg.js +20 -0
- package/spriteTextBg.ts +20 -0
- package/threeLoader.d.ts +35 -34
- package/threeLoader.js +518 -527
- package/threeLoader.ts +525 -0
- package/threeUtils.d.ts +53 -52
- package/threeUtils.js +329 -330
- package/threeUtils.ts +373 -0
- package/types.d.ts +2 -0
- package/types.js +6 -0
- package/types.ts +8 -0
- package/ApngTexture.d.ts +0 -13
- package/ApngTexture.js +0 -61
- package/ApngTextureManage.d.ts +0 -18
- package/ApngTextureManage.js +0 -87
- package/KeyFrameAnimation.d.ts +0 -25
- package/KeyFrameAnimation.js +0 -78
- package/keyContorls.d.ts +0 -25
- package/lib/draco/draco_decoder.js +0 -34
- package/lib/draco/draco_decoder.wasm +0 -0
- package/lib/draco/draco_wasm_wrapper.js +0 -117
- package/shaders.d.ts +0 -5
- package/shaders.js +0 -93
package/MeshBase.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-02-24 22:49:42
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2025-06-25
|
|
6
|
+
*/
|
|
7
|
+
import { AnimationAction, AnimationClip, AnimationMixer, Clock, Group, Mesh, Object3D, Vector3 } from "three";
|
|
8
|
+
import threeUtils from "./threeUtils";
|
|
9
|
+
import threeLoader from "./threeLoader";
|
|
10
|
+
import * as SkeletonUtils from "three/examples/jsm/utils/SkeletonUtils";
|
|
11
|
+
import { isString } from "lodash";
|
|
12
|
+
import { dispatchCustomEvent } from "./EventMap";
|
|
13
|
+
|
|
14
|
+
// 模型基类
|
|
15
|
+
export default class MeshBase extends Group {
|
|
16
|
+
constructor(url?: string) {
|
|
17
|
+
super();
|
|
18
|
+
url && this.loadModel(url);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
url: string = "";
|
|
22
|
+
// 模型对象
|
|
23
|
+
static models: Map<string, Object3D> = new Map();
|
|
24
|
+
// 模型是否在加载中
|
|
25
|
+
static loadModeling: Map<string, boolean> = new Map();
|
|
26
|
+
// 加载完成
|
|
27
|
+
loaded: boolean = false;
|
|
28
|
+
// 是否有动画
|
|
29
|
+
hasAnimation: boolean = false;
|
|
30
|
+
//动画混合器
|
|
31
|
+
mixer?: AnimationMixer;
|
|
32
|
+
//动画剪辑对象数组
|
|
33
|
+
animationActions: {
|
|
34
|
+
[key: string]: AnimationAction;
|
|
35
|
+
} = {};
|
|
36
|
+
// 获取文件名的后缀
|
|
37
|
+
getSuffix(filename: string): string {
|
|
38
|
+
const match = filename.match(/\.([^\.]+)$/);
|
|
39
|
+
return match ? match[1].toLowerCase() : "";
|
|
40
|
+
}
|
|
41
|
+
reset(...object: Object3D[]): this {
|
|
42
|
+
threeUtils.dipose(this);
|
|
43
|
+
for (const child of this.children) {
|
|
44
|
+
child.parent = null;
|
|
45
|
+
}
|
|
46
|
+
for (const item of object) {
|
|
47
|
+
this.add(item);
|
|
48
|
+
}
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
// 兜底:为缺失顶点法线的几何体计算法线。
|
|
52
|
+
// 某些 glb/stl 模型仅有 POSITION 没有 NORMAL(如 public/models/bottle.glb),
|
|
53
|
+
// 会让法线 pass 输出零向量 -> AO 算出 NaN -> 整片被乘黑,且 PBR 金属材质无法正确受光 -> 发黑。
|
|
54
|
+
// 在加载完成后统一兜底,保证光照与 AO 都正确;已含法线的模型不受影响。
|
|
55
|
+
protected ensureNormals(root: Object3D): void {
|
|
56
|
+
root.traverse((obj) => {
|
|
57
|
+
if (obj instanceof Mesh && obj.geometry && !obj.geometry.getAttribute("normal")) {
|
|
58
|
+
obj.geometry.computeVertexNormals();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// 如果url 是blob地址的话,就用suffix字段来制定模型的类型
|
|
63
|
+
async loadModel(url: string | File | Array<File>, filename: string = ""): Promise<void> {
|
|
64
|
+
//获取模型文件的地址
|
|
65
|
+
const modelurl = await (async (): Promise<string> => {
|
|
66
|
+
if (isString(url)) {
|
|
67
|
+
return url;
|
|
68
|
+
}
|
|
69
|
+
else if (url instanceof File) {
|
|
70
|
+
return url.name;
|
|
71
|
+
}
|
|
72
|
+
else if (url instanceof Array) {
|
|
73
|
+
let modelurl = "";
|
|
74
|
+
const suffixs = [
|
|
75
|
+
"zip",
|
|
76
|
+
"obj",
|
|
77
|
+
"glb",
|
|
78
|
+
"gltf",
|
|
79
|
+
"fbx",
|
|
80
|
+
"dae",
|
|
81
|
+
"stl",
|
|
82
|
+
"usdz",
|
|
83
|
+
];
|
|
84
|
+
for (let file of url) {
|
|
85
|
+
if (suffixs.includes(threeUtils.getSuffix(file.name))) {
|
|
86
|
+
modelurl = file.name;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return modelurl;
|
|
90
|
+
}
|
|
91
|
+
return "";
|
|
92
|
+
})();
|
|
93
|
+
this.url = modelurl || "";
|
|
94
|
+
if (!modelurl) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.loaded = false;
|
|
98
|
+
// 没有模型并且没有加载任务时就去加载模型
|
|
99
|
+
if (!MeshBase.models.get(modelurl) &&
|
|
100
|
+
!MeshBase.loadModeling.get(modelurl)) {
|
|
101
|
+
MeshBase.loadModeling.set(modelurl, true);
|
|
102
|
+
// 万能加载器
|
|
103
|
+
let modal = await threeLoader.loadModel(url, filename);
|
|
104
|
+
MeshBase.models.set(modelurl, modal);
|
|
105
|
+
MeshBase.loadModeling.set(modelurl, false);
|
|
106
|
+
}
|
|
107
|
+
// 如果模型还在加载中, 就等待模型加载完成
|
|
108
|
+
do {
|
|
109
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
110
|
+
} while (MeshBase.loadModeling.get(modelurl));
|
|
111
|
+
if (MeshBase.models.get(modelurl)) {
|
|
112
|
+
const mesh = MeshBase.models.get(modelurl)!;
|
|
113
|
+
// 兜底:为缺失顶点法线的几何体补算法线。某些 glb/stl 模型只有 POSITION,
|
|
114
|
+
// 没有 NORMAL,会导致:① 法线 pass 输出零向量 -> AO 算出 NaN -> 整片被乘黑;
|
|
115
|
+
// ② PBR 金属材质无法正确光照 -> 颜色发黑。统一在加载后兜底,光照与 AO 都正确。
|
|
116
|
+
this.ensureNormals(mesh);
|
|
117
|
+
// 判断是否有动画
|
|
118
|
+
this.hasAnimation = (mesh as Group & { animations: AnimationClip[] }).animations.length > 0;
|
|
119
|
+
if (this.hasAnimation) {
|
|
120
|
+
const model = SkeletonUtils.clone(mesh);
|
|
121
|
+
this.mixer = new AnimationMixer(model);
|
|
122
|
+
this.animationActions = {};
|
|
123
|
+
(mesh as Group & { animations: AnimationClip[] }).animations.map((animation: AnimationClip) => {
|
|
124
|
+
const animationAction = this.mixer!.clipAction(animation).play();
|
|
125
|
+
animationAction.weight = 0;
|
|
126
|
+
this.animationActions[animation.name] = animationAction;
|
|
127
|
+
});
|
|
128
|
+
this.reset(model);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.reset(mesh.clone(true));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
135
|
+
this.loaded = true;
|
|
136
|
+
// 加载完成事件
|
|
137
|
+
dispatchCustomEvent(this, { type: "loaded" });
|
|
138
|
+
}
|
|
139
|
+
// 超出绘制区域时不绘制
|
|
140
|
+
frustumCulled: boolean = false;
|
|
141
|
+
// 创建阴影
|
|
142
|
+
castShadow: boolean = false;
|
|
143
|
+
// 接受阴影
|
|
144
|
+
receiveShadow: boolean = false;
|
|
145
|
+
// promise.resole 队列
|
|
146
|
+
resoles: Array<(value: void | PromiseLike<void>) => void> = [];
|
|
147
|
+
// 等待加载加载完成
|
|
148
|
+
async awaitLoaded(): Promise<void> {
|
|
149
|
+
if (!this.loaded) {
|
|
150
|
+
await new Promise<void>((resolve) => {
|
|
151
|
+
if (this.resoles.length === 0) {
|
|
152
|
+
(async () => {
|
|
153
|
+
while (!this.loaded) {
|
|
154
|
+
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
155
|
+
}
|
|
156
|
+
while (this.resoles.length > 0) {
|
|
157
|
+
const resole = this.resoles.pop();
|
|
158
|
+
resole && resole();
|
|
159
|
+
}
|
|
160
|
+
})();
|
|
161
|
+
}
|
|
162
|
+
this.resoles.unshift(resolve);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//遍历模型
|
|
167
|
+
async traverseMesh(callback: (mesh: Mesh) => void): Promise<void> {
|
|
168
|
+
// 等待加载完成
|
|
169
|
+
await this.awaitLoaded();
|
|
170
|
+
this.traverse((obj) => {
|
|
171
|
+
if (obj instanceof Mesh) {
|
|
172
|
+
callback(obj);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
clock: Clock = new Clock();
|
|
177
|
+
//设置动画的权重
|
|
178
|
+
async setClipActionWeight(weights: {
|
|
179
|
+
[key: string]: number;
|
|
180
|
+
} = {}): Promise<void> {
|
|
181
|
+
// 等待加载完成
|
|
182
|
+
await this.awaitLoaded();
|
|
183
|
+
for (let key in this.animationActions) {
|
|
184
|
+
this.animationActions[key].weight = weights[key] || 0;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//获取动画列表
|
|
188
|
+
getAnimas(): string[] {
|
|
189
|
+
return Object.keys(this.animationActions);
|
|
190
|
+
}
|
|
191
|
+
//播放指定动画
|
|
192
|
+
setAnimas(anima: string = ""): void {
|
|
193
|
+
this.setClipActionWeight({ [anima]: 1 });
|
|
194
|
+
}
|
|
195
|
+
//停止所有动画
|
|
196
|
+
stop(): void {
|
|
197
|
+
this.setClipActionWeight();
|
|
198
|
+
}
|
|
199
|
+
updateMatrix(): void {
|
|
200
|
+
//播放动画
|
|
201
|
+
if (this.mixer) {
|
|
202
|
+
this.mixer.update(this.clock.getDelta());
|
|
203
|
+
}
|
|
204
|
+
// 深度应用属性
|
|
205
|
+
this.traverse((obj) => {
|
|
206
|
+
if (obj instanceof Mesh) {
|
|
207
|
+
obj.frustumCulled = this.frustumCulled;
|
|
208
|
+
obj.castShadow = this.castShadow;
|
|
209
|
+
obj.receiveShadow = this.receiveShadow;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
super.updateMatrix();
|
|
213
|
+
}
|
|
214
|
+
// 获取模型的尺寸
|
|
215
|
+
async getSize(): Promise<Vector3> {
|
|
216
|
+
await this.awaitLoaded();
|
|
217
|
+
return threeUtils.getSize(this);
|
|
218
|
+
}
|
|
219
|
+
// 居中
|
|
220
|
+
async center(): Promise<void> {
|
|
221
|
+
await this.awaitLoaded();
|
|
222
|
+
threeUtils.center(this);
|
|
223
|
+
}
|
|
224
|
+
//底对齐
|
|
225
|
+
async alignBottom(y: number = 0): Promise<void> {
|
|
226
|
+
await this.awaitLoaded();
|
|
227
|
+
threeUtils.alignBottom(this, y);
|
|
228
|
+
}
|
|
229
|
+
// 放大到指定尺寸
|
|
230
|
+
async scaleTo(size: number = 1, key: Array<"x" | "y" | "z"> = ["x", "y", "z"]): Promise<void> {
|
|
231
|
+
await this.awaitLoaded();
|
|
232
|
+
threeUtils.scaleTo(this, size, key);
|
|
233
|
+
}
|
|
234
|
+
//按照法线拓展
|
|
235
|
+
expandBynormal(length: number): void {
|
|
236
|
+
this.traverseMesh((mesh) => {
|
|
237
|
+
// 没有法线就计算法线
|
|
238
|
+
mesh.geometry = mesh.geometry.clone();
|
|
239
|
+
if (!mesh.geometry.getAttribute("normal")) {
|
|
240
|
+
mesh.geometry.computeVertexNormals();
|
|
241
|
+
}
|
|
242
|
+
const normal = mesh.geometry.getAttribute("normal");
|
|
243
|
+
const position = mesh.geometry.getAttribute("position");
|
|
244
|
+
const v3 = new Vector3(0, 0, 0);
|
|
245
|
+
for (let i = 0; i < position.count; i++) {
|
|
246
|
+
v3.set(normal.getX(i), normal.getY(i), normal.getZ(i));
|
|
247
|
+
v3.setLength(length);
|
|
248
|
+
position.setXYZ(i, position.getX(i) + v3.x, position.getY(i) + v3.y, position.getZ(i) + v3.z);
|
|
249
|
+
}
|
|
250
|
+
position.needsUpdate = true;
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
package/Mirror.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class Mirror extends Mesh {
|
|
3
|
-
constructor(geometry?: BufferGeometry);
|
|
4
|
-
static geometry: PlaneGeometry;
|
|
5
|
-
isReflector: boolean;
|
|
6
|
-
type: string;
|
|
7
|
-
camera: PerspectiveCamera;
|
|
8
|
-
reflectorPlane: Plane;
|
|
9
|
-
normal: Vector3;
|
|
10
|
-
reflectorWorldPosition: Vector3;
|
|
11
|
-
cameraWorldPosition: Vector3;
|
|
12
|
-
rotationMatrix: Matrix4;
|
|
13
|
-
lookAtPosition: Vector3;
|
|
14
|
-
clipPlane: Vector4;
|
|
15
|
-
view: Vector3;
|
|
16
|
-
target: Vector3;
|
|
17
|
-
q: Vector4;
|
|
18
|
-
textureMatrix: Matrix4;
|
|
19
|
-
virtualCamera: PerspectiveCamera;
|
|
20
|
-
renderTarget: WebGLRenderTarget<
|
|
21
|
-
material: ShaderMaterial;
|
|
22
|
-
onBeforeRender: (renderer: WebGLRenderer, scene: Scene, camera: Camera, geometry: BufferGeometry, material: Material, group: Group) => void;
|
|
23
|
-
getRenderTarget(): WebGLRenderTarget<
|
|
24
|
-
dispose(): void;
|
|
25
|
-
}
|
|
1
|
+
import { Matrix4, Mesh, PerspectiveCamera, Plane, PlaneGeometry, ShaderMaterial, Vector3, Vector4, WebGLRenderTarget, WebGLRenderer, Scene, Camera, BufferGeometry, Material, Group, Texture } from "three";
|
|
2
|
+
export default class Mirror extends Mesh {
|
|
3
|
+
constructor(geometry?: BufferGeometry);
|
|
4
|
+
static geometry: PlaneGeometry;
|
|
5
|
+
isReflector: boolean;
|
|
6
|
+
type: string;
|
|
7
|
+
camera: PerspectiveCamera;
|
|
8
|
+
reflectorPlane: Plane;
|
|
9
|
+
normal: Vector3;
|
|
10
|
+
reflectorWorldPosition: Vector3;
|
|
11
|
+
cameraWorldPosition: Vector3;
|
|
12
|
+
rotationMatrix: Matrix4;
|
|
13
|
+
lookAtPosition: Vector3;
|
|
14
|
+
clipPlane: Vector4;
|
|
15
|
+
view: Vector3;
|
|
16
|
+
target: Vector3;
|
|
17
|
+
q: Vector4;
|
|
18
|
+
textureMatrix: Matrix4;
|
|
19
|
+
virtualCamera: PerspectiveCamera;
|
|
20
|
+
renderTarget: WebGLRenderTarget<Texture>;
|
|
21
|
+
material: ShaderMaterial;
|
|
22
|
+
onBeforeRender: (renderer: WebGLRenderer, scene: Scene, camera: Camera, geometry: BufferGeometry, material: Material, group: Group) => void;
|
|
23
|
+
getRenderTarget(): WebGLRenderTarget<Texture>;
|
|
24
|
+
dispose(): void;
|
|
25
|
+
}
|
package/Mirror.js
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2023-08-04 17:17:15
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2024-01-20 05:33:51
|
|
6
|
-
*/
|
|
7
|
-
import { Color, DoubleSide, HalfFloatType, Matrix4, Mesh, PerspectiveCamera, Plane, PlaneGeometry, ShaderMaterial, Vector3, Vector4, WebGLRenderTarget } from "three";
|
|
8
|
-
// 镜子模型
|
|
9
|
-
export default class Mirror extends Mesh {
|
|
10
|
-
constructor(geometry = Mirror.geometry) {
|
|
11
|
-
super(geometry);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-08-04 17:17:15
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2024-01-20 05:33:51
|
|
6
|
+
*/
|
|
7
|
+
import { Color, DoubleSide, HalfFloatType, Matrix4, Mesh, PerspectiveCamera, Plane, PlaneGeometry, ShaderMaterial, Vector3, Vector4, WebGLRenderTarget } from "three";
|
|
8
|
+
// 镜子模型
|
|
9
|
+
export default class Mirror extends Mesh {
|
|
10
|
+
constructor(geometry = Mirror.geometry) {
|
|
11
|
+
super(geometry);
|
|
12
|
+
// 镜子虽标了 transparent:true(为渲染顺序),但 fragment shader 实际输出 alpha=1.0,
|
|
13
|
+
// 是实心反射面、并非可透视表面 → 必须参与 AO 与描边/辉光的深度遮挡。
|
|
14
|
+
// SSAO 的 AO 数据准备会排除所有 transparent 物体,故此处显式声明保留。
|
|
15
|
+
this.userData.aoOpaque = true;
|
|
16
|
+
}
|
|
17
|
+
// 正方形网格
|
|
18
|
+
static geometry = (() => {
|
|
19
|
+
const geometry = new PlaneGeometry(10, 10, 1, 1);
|
|
20
|
+
return geometry;
|
|
21
|
+
})();
|
|
22
|
+
isReflector = true;
|
|
23
|
+
type = 'Reflector';
|
|
24
|
+
camera = new PerspectiveCamera();
|
|
25
|
+
reflectorPlane = new Plane();
|
|
26
|
+
normal = new Vector3();
|
|
27
|
+
reflectorWorldPosition = new Vector3();
|
|
28
|
+
cameraWorldPosition = new Vector3();
|
|
29
|
+
rotationMatrix = new Matrix4();
|
|
30
|
+
lookAtPosition = new Vector3(0, 0, -1);
|
|
31
|
+
clipPlane = new Vector4();
|
|
32
|
+
view = new Vector3();
|
|
33
|
+
target = new Vector3();
|
|
34
|
+
q = new Vector4();
|
|
35
|
+
textureMatrix = new Matrix4();
|
|
36
|
+
virtualCamera = this.camera;
|
|
37
|
+
renderTarget = new WebGLRenderTarget(2048, 2048, { type: HalfFloatType });
|
|
38
|
+
material = new ShaderMaterial({
|
|
39
|
+
uniforms: {
|
|
40
|
+
'color': {
|
|
41
|
+
value: new Color("#b6b6b6")
|
|
42
|
+
},
|
|
43
|
+
'tDiffuse': {
|
|
44
|
+
value: this.renderTarget.texture
|
|
45
|
+
},
|
|
46
|
+
'textureMatrix': {
|
|
47
|
+
value: this.textureMatrix
|
|
48
|
+
},
|
|
49
|
+
blurAmount: {
|
|
50
|
+
value: 0.5
|
|
51
|
+
} // 模糊程度,可以根据需求调整
|
|
52
|
+
},
|
|
49
53
|
vertexShader: /* glsl */ `
|
|
50
54
|
uniform mat4 textureMatrix;
|
|
51
55
|
varying vec4 vUv;
|
|
@@ -61,7 +65,7 @@ export default class Mirror extends Mesh {
|
|
|
61
65
|
|
|
62
66
|
#include <logdepthbuf_vertex>
|
|
63
67
|
|
|
64
|
-
}`,
|
|
68
|
+
}`,
|
|
65
69
|
fragmentShader: /* glsl */ `
|
|
66
70
|
uniform vec3 color;
|
|
67
71
|
uniform sampler2D tDiffuse;
|
|
@@ -104,93 +108,93 @@ export default class Mirror extends Mesh {
|
|
|
104
108
|
|
|
105
109
|
#include <tonemapping_fragment>
|
|
106
110
|
#include <colorspace_fragment>
|
|
107
|
-
}`,
|
|
108
|
-
depthTest: true,
|
|
109
|
-
depthWrite: true,
|
|
110
|
-
transparent: true,
|
|
111
|
-
side: DoubleSide
|
|
112
|
-
});
|
|
113
|
-
onBeforeRender = (renderer, scene, camera, geometry, material, group) => {
|
|
114
|
-
this.reflectorWorldPosition.setFromMatrixPosition(this.matrixWorld);
|
|
115
|
-
this.cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
|
|
116
|
-
this.rotationMatrix.extractRotation(this.matrixWorld);
|
|
117
|
-
this.normal.set(0, 0, 1);
|
|
118
|
-
this.normal.applyMatrix4(this.rotationMatrix);
|
|
119
|
-
this.view.subVectors(this.reflectorWorldPosition, this.cameraWorldPosition);
|
|
120
|
-
// Avoid rendering when reflector is facing away
|
|
121
|
-
if (this.view.dot(this.normal) > 0) {
|
|
122
|
-
this.normal.set(0, 0, -1);
|
|
123
|
-
}
|
|
124
|
-
;
|
|
125
|
-
this.view.reflect(this.normal).negate();
|
|
126
|
-
this.view.add(this.reflectorWorldPosition);
|
|
127
|
-
this.rotationMatrix.extractRotation(camera.matrixWorld);
|
|
128
|
-
this.lookAtPosition.set(0, 0, -1);
|
|
129
|
-
this.lookAtPosition.applyMatrix4(this.rotationMatrix);
|
|
130
|
-
this.lookAtPosition.add(this.cameraWorldPosition);
|
|
131
|
-
this.target.subVectors(this.reflectorWorldPosition, this.lookAtPosition);
|
|
132
|
-
this.target.reflect(this.normal).negate();
|
|
133
|
-
this.target.add(this.reflectorWorldPosition);
|
|
134
|
-
this.virtualCamera.position.copy(this.view);
|
|
135
|
-
this.virtualCamera.up.set(0, 1, 0);
|
|
136
|
-
this.virtualCamera.up.applyMatrix4(this.rotationMatrix);
|
|
137
|
-
this.virtualCamera.up.reflect(this.normal);
|
|
138
|
-
this.virtualCamera.lookAt(this.target);
|
|
139
|
-
this.virtualCamera.far = this.camera.far; // Used in WebGLBackground
|
|
140
|
-
this.virtualCamera.updateMatrixWorld();
|
|
141
|
-
this.virtualCamera.projectionMatrix.copy(camera.projectionMatrix);
|
|
142
|
-
// Update the texture matrix
|
|
143
|
-
this.textureMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
|
|
144
|
-
this.textureMatrix.multiply(this.virtualCamera.projectionMatrix);
|
|
145
|
-
this.textureMatrix.multiply(this.virtualCamera.matrixWorldInverse);
|
|
146
|
-
this.textureMatrix.multiply(this.matrixWorld);
|
|
147
|
-
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
148
|
-
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
149
|
-
this.reflectorPlane.setFromNormalAndCoplanarPoint(this.normal, this.reflectorWorldPosition);
|
|
150
|
-
this.reflectorPlane.applyMatrix4(this.virtualCamera.matrixWorldInverse);
|
|
151
|
-
this.clipPlane.set(this.reflectorPlane.normal.x, this.reflectorPlane.normal.y, this.reflectorPlane.normal.z, this.reflectorPlane.constant);
|
|
152
|
-
const projectionMatrix = this.virtualCamera.projectionMatrix;
|
|
153
|
-
this.q.x = (Math.sign(this.clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
|
|
154
|
-
this.q.y = (Math.sign(this.clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
|
|
155
|
-
this.q.z = -1.0;
|
|
156
|
-
this.q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
|
|
157
|
-
// Calculate the scaled plane vector
|
|
158
|
-
this.clipPlane.multiplyScalar(2.0 / this.clipPlane.dot(this.q));
|
|
159
|
-
// Replacing the third row of the projection matrix
|
|
160
|
-
projectionMatrix.elements[2] = this.clipPlane.x;
|
|
161
|
-
projectionMatrix.elements[6] = this.clipPlane.y;
|
|
162
|
-
projectionMatrix.elements[10] = this.clipPlane.z + 1.0 - 0.003;
|
|
163
|
-
projectionMatrix.elements[14] = this.clipPlane.w;
|
|
164
|
-
// Render
|
|
165
|
-
this.visible = false;
|
|
166
|
-
const currentRenderTarget = renderer.getRenderTarget();
|
|
167
|
-
const currentXrEnabled = renderer.xr.enabled;
|
|
168
|
-
const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
|
|
169
|
-
renderer.xr.enabled = false; // Avoid camera modification
|
|
170
|
-
renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
|
|
171
|
-
renderer.setRenderTarget(this.renderTarget);
|
|
172
|
-
renderer.state.buffers.depth.setMask(true); // make sure the depth buffer is writable so it can be properly cleared, see #18897
|
|
173
|
-
if (renderer.autoClear === false)
|
|
174
|
-
renderer.clear();
|
|
175
|
-
renderer.render(scene, this.virtualCamera);
|
|
176
|
-
renderer.xr.enabled = currentXrEnabled;
|
|
177
|
-
renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
|
|
178
|
-
renderer.setRenderTarget(currentRenderTarget);
|
|
179
|
-
// Restore viewport
|
|
180
|
-
|
|
181
|
-
const viewport =
|
|
182
|
-
if (viewport !== undefined) {
|
|
183
|
-
renderer.state.viewport(viewport);
|
|
184
|
-
}
|
|
185
|
-
this.visible = true;
|
|
186
|
-
};
|
|
187
|
-
getRenderTarget() {
|
|
188
|
-
return this.renderTarget;
|
|
189
|
-
}
|
|
190
|
-
;
|
|
191
|
-
dispose() {
|
|
192
|
-
this.renderTarget.dispose();
|
|
193
|
-
// this.material.dispose();
|
|
194
|
-
}
|
|
195
|
-
;
|
|
196
|
-
}
|
|
111
|
+
}`,
|
|
112
|
+
depthTest: true,
|
|
113
|
+
depthWrite: true,
|
|
114
|
+
transparent: true,
|
|
115
|
+
side: DoubleSide
|
|
116
|
+
});
|
|
117
|
+
onBeforeRender = (renderer, scene, camera, geometry, material, group) => {
|
|
118
|
+
this.reflectorWorldPosition.setFromMatrixPosition(this.matrixWorld);
|
|
119
|
+
this.cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
|
|
120
|
+
this.rotationMatrix.extractRotation(this.matrixWorld);
|
|
121
|
+
this.normal.set(0, 0, 1);
|
|
122
|
+
this.normal.applyMatrix4(this.rotationMatrix);
|
|
123
|
+
this.view.subVectors(this.reflectorWorldPosition, this.cameraWorldPosition);
|
|
124
|
+
// Avoid rendering when reflector is facing away
|
|
125
|
+
if (this.view.dot(this.normal) > 0) {
|
|
126
|
+
this.normal.set(0, 0, -1);
|
|
127
|
+
}
|
|
128
|
+
;
|
|
129
|
+
this.view.reflect(this.normal).negate();
|
|
130
|
+
this.view.add(this.reflectorWorldPosition);
|
|
131
|
+
this.rotationMatrix.extractRotation(camera.matrixWorld);
|
|
132
|
+
this.lookAtPosition.set(0, 0, -1);
|
|
133
|
+
this.lookAtPosition.applyMatrix4(this.rotationMatrix);
|
|
134
|
+
this.lookAtPosition.add(this.cameraWorldPosition);
|
|
135
|
+
this.target.subVectors(this.reflectorWorldPosition, this.lookAtPosition);
|
|
136
|
+
this.target.reflect(this.normal).negate();
|
|
137
|
+
this.target.add(this.reflectorWorldPosition);
|
|
138
|
+
this.virtualCamera.position.copy(this.view);
|
|
139
|
+
this.virtualCamera.up.set(0, 1, 0);
|
|
140
|
+
this.virtualCamera.up.applyMatrix4(this.rotationMatrix);
|
|
141
|
+
this.virtualCamera.up.reflect(this.normal);
|
|
142
|
+
this.virtualCamera.lookAt(this.target);
|
|
143
|
+
this.virtualCamera.far = this.camera.far; // Used in WebGLBackground
|
|
144
|
+
this.virtualCamera.updateMatrixWorld();
|
|
145
|
+
this.virtualCamera.projectionMatrix.copy(camera.projectionMatrix);
|
|
146
|
+
// Update the texture matrix
|
|
147
|
+
this.textureMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
|
|
148
|
+
this.textureMatrix.multiply(this.virtualCamera.projectionMatrix);
|
|
149
|
+
this.textureMatrix.multiply(this.virtualCamera.matrixWorldInverse);
|
|
150
|
+
this.textureMatrix.multiply(this.matrixWorld);
|
|
151
|
+
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
152
|
+
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
153
|
+
this.reflectorPlane.setFromNormalAndCoplanarPoint(this.normal, this.reflectorWorldPosition);
|
|
154
|
+
this.reflectorPlane.applyMatrix4(this.virtualCamera.matrixWorldInverse);
|
|
155
|
+
this.clipPlane.set(this.reflectorPlane.normal.x, this.reflectorPlane.normal.y, this.reflectorPlane.normal.z, this.reflectorPlane.constant);
|
|
156
|
+
const projectionMatrix = this.virtualCamera.projectionMatrix;
|
|
157
|
+
this.q.x = (Math.sign(this.clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
|
|
158
|
+
this.q.y = (Math.sign(this.clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
|
|
159
|
+
this.q.z = -1.0;
|
|
160
|
+
this.q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
|
|
161
|
+
// Calculate the scaled plane vector
|
|
162
|
+
this.clipPlane.multiplyScalar(2.0 / this.clipPlane.dot(this.q));
|
|
163
|
+
// Replacing the third row of the projection matrix
|
|
164
|
+
projectionMatrix.elements[2] = this.clipPlane.x;
|
|
165
|
+
projectionMatrix.elements[6] = this.clipPlane.y;
|
|
166
|
+
projectionMatrix.elements[10] = this.clipPlane.z + 1.0 - 0.003;
|
|
167
|
+
projectionMatrix.elements[14] = this.clipPlane.w;
|
|
168
|
+
// Render
|
|
169
|
+
this.visible = false;
|
|
170
|
+
const currentRenderTarget = renderer.getRenderTarget();
|
|
171
|
+
const currentXrEnabled = renderer.xr.enabled;
|
|
172
|
+
const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
|
|
173
|
+
renderer.xr.enabled = false; // Avoid camera modification
|
|
174
|
+
renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
|
|
175
|
+
renderer.setRenderTarget(this.renderTarget);
|
|
176
|
+
renderer.state.buffers.depth.setMask(true); // make sure the depth buffer is writable so it can be properly cleared, see #18897
|
|
177
|
+
if (renderer.autoClear === false)
|
|
178
|
+
renderer.clear();
|
|
179
|
+
renderer.render(scene, this.virtualCamera);
|
|
180
|
+
renderer.xr.enabled = currentXrEnabled;
|
|
181
|
+
renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
|
|
182
|
+
renderer.setRenderTarget(currentRenderTarget);
|
|
183
|
+
// Restore viewport
|
|
184
|
+
const cameraWithViewport = this.camera;
|
|
185
|
+
const viewport = cameraWithViewport.viewport;
|
|
186
|
+
if (viewport !== undefined) {
|
|
187
|
+
renderer.state.viewport(viewport);
|
|
188
|
+
}
|
|
189
|
+
this.visible = true;
|
|
190
|
+
};
|
|
191
|
+
getRenderTarget() {
|
|
192
|
+
return this.renderTarget;
|
|
193
|
+
}
|
|
194
|
+
;
|
|
195
|
+
dispose() {
|
|
196
|
+
this.renderTarget.dispose();
|
|
197
|
+
// this.material.dispose();
|
|
198
|
+
}
|
|
199
|
+
;
|
|
200
|
+
}
|