lythreeframe 1.2.50 → 1.2.52
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/bundle.cjs.js +201 -375
- package/dist/bundle.esm.js +203 -375
- package/dist/index.d.ts +0 -3
- package/dist/lythreeframe/AssetManagement/AssetManager.d.ts +2 -2
- package/dist/lythreeframe/Frame/Controller.d.ts +0 -1
- package/dist/lythreeframe/Frame/Parameters/AppParameter.d.ts +0 -2
- package/dist/lythreeframe/Frame/Parameters/ViewportParameters.d.ts +0 -1
- package/dist/lythreeframe/Frame/Viewport.d.ts +3 -7
- package/dist/lythreeframe/Object/Actor.d.ts +3 -3
- package/dist/lythreeframe/Object/Components/Light/AmbientLight/AmbientLightComponent.d.ts +1 -1
- package/dist/lythreeframe/PostProcess/Param/AAParam.d.ts +1 -1
- package/dist/lythreeframe/PostProcess/Param/Bloom.d.ts +1 -1
- package/dist/lythreeframe/PostProcess/Param/DOF.d.ts +1 -1
- package/dist/lythreeframe/PostProcess/Param/GTAO.d.ts +1 -1
- package/dist/lythreeframe/PostProcess/Param/Outline.d.ts +2 -2
- package/dist/lythreeframe/PostProcess/Param/SSR.d.ts +1 -1
- package/dist/lythreeframe/PostProcess/WebGPUPostProcessFactory.d.ts +6 -6
- package/dist/lythreeframe/ThreeJsApp.d.ts +8 -60
- package/package.json +1 -1
package/dist/bundle.cjs.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var webgpu = require('three/webgpu');
|
|
4
4
|
var Addons_js = require('three/examples/jsm/Addons.js');
|
|
5
5
|
var tsl = require('three/tsl');
|
|
6
|
-
var three = require('three');
|
|
7
6
|
var DepthOfFieldNode_js = require('three/addons/tsl/display/DepthOfFieldNode.js');
|
|
8
7
|
var BloomNode_js = require('three/examples/jsm/tsl/display/BloomNode.js');
|
|
9
8
|
var DenoiseNode_js = require('three/examples/jsm/tsl/display/DenoiseNode.js');
|
|
@@ -12,6 +11,7 @@ var GTAONode_js = require('three/examples/jsm/tsl/display/GTAONode.js');
|
|
|
12
11
|
var OutlineNode_js = require('three/examples/jsm/tsl/display/OutlineNode.js');
|
|
13
12
|
var SMAANode_js = require('three/examples/jsm/tsl/display/SMAANode.js');
|
|
14
13
|
var gsap = require('gsap');
|
|
14
|
+
var three = require('three');
|
|
15
15
|
var SkyMesh_js = require('three/examples/jsm/objects/SkyMesh.js');
|
|
16
16
|
var CSS2DRenderer_js = require('three/examples/jsm/renderers/CSS2DRenderer.js');
|
|
17
17
|
var PointerLockControls_js = require('three/examples/jsm/controls/PointerLockControls.js');
|
|
@@ -930,16 +930,16 @@ class TAssetPointer extends TSmartPointer {
|
|
|
930
930
|
value.userData["assetPointer"] = this;
|
|
931
931
|
}
|
|
932
932
|
release() {
|
|
933
|
-
if (this.value) {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
}
|
|
942
|
-
console.log("realease", this)
|
|
933
|
+
// if (this.value) {
|
|
934
|
+
// this.referenceCount--;
|
|
935
|
+
// if (this.referenceCount === 0) {
|
|
936
|
+
// setTimeout(() => {
|
|
937
|
+
// this.value!.dispose();
|
|
938
|
+
// this.value = null;
|
|
939
|
+
// }, 0);
|
|
940
|
+
// }
|
|
941
|
+
// }
|
|
942
|
+
// console.log("realease", this)
|
|
943
943
|
}
|
|
944
944
|
forceRelease() {
|
|
945
945
|
console.log("forceRelease", this);
|
|
@@ -1045,63 +1045,58 @@ class AssetManager {
|
|
|
1045
1045
|
}
|
|
1046
1046
|
}
|
|
1047
1047
|
convertThreeObjectToLYObject(parentLYComponent, threejsObject) {
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1048
|
+
const location = threejsObject.position.clone();
|
|
1049
|
+
const rotation = threejsObject.rotation.clone();
|
|
1050
|
+
const scale = threejsObject.scale.clone();
|
|
1051
1051
|
let newComp = null;
|
|
1052
|
-
|
|
1052
|
+
const children = threejsObject.children;
|
|
1053
1053
|
threejsObject.children = [];
|
|
1054
1054
|
if (threejsObject.type === "Group" || threejsObject.type === "Object3D") {
|
|
1055
|
-
newComp = new SceneComponent(this.app, threejsObject);
|
|
1055
|
+
newComp = new SceneComponent(this.app, threejsObject.uuid);
|
|
1056
1056
|
}
|
|
1057
1057
|
else if (threejsObject.isMesh) {
|
|
1058
|
-
|
|
1058
|
+
const obj = threejsObject;
|
|
1059
1059
|
newComp = new MeshComponent(this.app, obj.geometry, obj.material);
|
|
1060
|
-
// assetManager.#collectMatAndGeoInMesh(threejsObject)
|
|
1061
1060
|
threejsObject.layers.set(0);
|
|
1062
1061
|
}
|
|
1063
1062
|
else {
|
|
1064
|
-
newComp = new SceneComponent(this.app, threejsObject);
|
|
1063
|
+
newComp = new SceneComponent(this.app, threejsObject.uuid);
|
|
1065
1064
|
}
|
|
1066
1065
|
if (newComp === null) {
|
|
1067
1066
|
threejsObject.children = children;
|
|
1068
|
-
//threejsObject.parent = parent
|
|
1069
|
-
//console.log("Unprocess", threejsObject);
|
|
1070
1067
|
return null;
|
|
1071
1068
|
}
|
|
1072
1069
|
parentLYComponent.addChildComponent(newComp);
|
|
1073
1070
|
newComp.setPosition(location);
|
|
1074
1071
|
newComp.setRotation(rotation);
|
|
1075
1072
|
newComp.setScale(scale);
|
|
1076
|
-
for (
|
|
1077
|
-
this.convertThreeObjectToLYObject(newComp,
|
|
1073
|
+
for (const child of children) {
|
|
1074
|
+
this.convertThreeObjectToLYObject(newComp, child);
|
|
1078
1075
|
}
|
|
1079
1076
|
return newComp;
|
|
1080
1077
|
}
|
|
1081
1078
|
collectResourcesAndReferences(object) {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
map.set(resource, map.get(resource) + 1);
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1079
|
+
const countResource = (map, resource) => {
|
|
1080
|
+
var _a;
|
|
1081
|
+
const currentCount = (_a = map.get(resource)) !== null && _a !== void 0 ? _a : 0;
|
|
1082
|
+
map.set(resource, currentCount + 1);
|
|
1083
|
+
};
|
|
1090
1084
|
const resources = {
|
|
1091
1085
|
geometries: new Map(),
|
|
1092
1086
|
materials: new Map(),
|
|
1093
1087
|
textures: new Map()
|
|
1094
1088
|
};
|
|
1095
1089
|
object.traverse((child) => {
|
|
1096
|
-
|
|
1097
|
-
|
|
1090
|
+
const meshChild = child;
|
|
1091
|
+
if (meshChild.geometry instanceof webgpu.BufferGeometry) {
|
|
1092
|
+
countResource(resources.geometries, meshChild.geometry);
|
|
1098
1093
|
}
|
|
1099
|
-
if (
|
|
1100
|
-
const mats = Array.isArray(
|
|
1094
|
+
if (meshChild.material) {
|
|
1095
|
+
const mats = Array.isArray(meshChild.material) ? meshChild.material : [meshChild.material];
|
|
1101
1096
|
mats.forEach((mat) => {
|
|
1102
1097
|
if (mat) {
|
|
1103
1098
|
countResource(resources.materials, mat);
|
|
1104
|
-
Object.
|
|
1099
|
+
Object.values(mat).forEach((value) => {
|
|
1105
1100
|
if (value instanceof webgpu.Texture) {
|
|
1106
1101
|
countResource(resources.textures, value);
|
|
1107
1102
|
}
|
|
@@ -1110,49 +1105,36 @@ class AssetManager {
|
|
|
1110
1105
|
});
|
|
1111
1106
|
}
|
|
1112
1107
|
});
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
createPointer(this, resources.geometries);
|
|
1119
|
-
createPointer(this, resources.materials);
|
|
1120
|
-
createPointer(this, resources.textures);
|
|
1121
|
-
// console.log('Geometries:', Array.from(resources.geometries.entries()));
|
|
1122
|
-
// console.log('Materials:', Array.from(resources.materials.entries()));
|
|
1123
|
-
// console.log('Textures:', Array.from(resources.textures.entries()));
|
|
1124
|
-
// console.log('assetPointer:', this.assetPointer);
|
|
1108
|
+
resources.geometries.forEach((count, geometry) => this.addAsset(geometry, count));
|
|
1109
|
+
resources.materials.forEach((count, material) => this.addAsset(material, count));
|
|
1110
|
+
resources.textures.forEach((count, texture) => this.addAsset(texture, count));
|
|
1125
1111
|
}
|
|
1126
1112
|
checkMeshResource(mesh) {
|
|
1127
|
-
if (mesh.geometry) {
|
|
1128
|
-
|
|
1129
|
-
this.addAsset(mesh.geometry);
|
|
1130
|
-
}
|
|
1113
|
+
if (mesh.geometry && !mesh.geometry.userData["assetPointer"]) {
|
|
1114
|
+
this.addAsset(mesh.geometry);
|
|
1131
1115
|
}
|
|
1132
1116
|
if (mesh.material) {
|
|
1133
1117
|
const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
|
|
1134
1118
|
mats.forEach((material) => {
|
|
1135
|
-
if (material)
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
Object.entries(material).forEach(([key, value]) => {
|
|
1140
|
-
if (value instanceof webgpu.Texture) {
|
|
1141
|
-
if (!(value.userData["assetPointer"])) {
|
|
1142
|
-
this.addAsset(value);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
});
|
|
1119
|
+
if (!material)
|
|
1120
|
+
return;
|
|
1121
|
+
if (!material.userData["assetPointer"]) {
|
|
1122
|
+
this.addAsset(material);
|
|
1146
1123
|
}
|
|
1124
|
+
Object.values(material).forEach((value) => {
|
|
1125
|
+
if (value instanceof webgpu.Texture && !value.userData["assetPointer"]) {
|
|
1126
|
+
this.addAsset(value);
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1147
1129
|
});
|
|
1148
1130
|
}
|
|
1149
1131
|
}
|
|
1150
1132
|
async loadGltfFromPathAsync(path) {
|
|
1151
1133
|
this.setupDracoLoader("/SceneResource/draco/");
|
|
1152
|
-
|
|
1153
|
-
return res;
|
|
1134
|
+
return await this.gltfLoader.loadAsync(path);
|
|
1154
1135
|
}
|
|
1155
1136
|
loadGltfFromPath(path, onLoadFinished) {
|
|
1137
|
+
this.setupDracoLoader("/SceneResource/draco/");
|
|
1156
1138
|
this.gltfLoader.load(path, onLoadFinished);
|
|
1157
1139
|
}
|
|
1158
1140
|
loadGltfFromBuffer(data, path, onLoadFinished) {
|
|
@@ -1161,33 +1143,30 @@ class AssetManager {
|
|
|
1161
1143
|
}
|
|
1162
1144
|
loadFile(filepath = '', onLoadFinished) {
|
|
1163
1145
|
const loader = new webgpu.FileLoader();
|
|
1164
|
-
loader.load(filepath,
|
|
1165
|
-
onLoadFinished(data);
|
|
1166
|
-
});
|
|
1146
|
+
loader.load(filepath, onLoadFinished);
|
|
1167
1147
|
}
|
|
1168
1148
|
addAsset(asset, referenceCount = 0) {
|
|
1169
1149
|
if (asset instanceof webgpu.BufferGeometry) {
|
|
1170
1150
|
return this.addGeometryAsset(asset, referenceCount);
|
|
1171
1151
|
}
|
|
1172
|
-
|
|
1152
|
+
if (asset instanceof webgpu.Material) {
|
|
1173
1153
|
return this.addMaterialAsset(asset, referenceCount);
|
|
1174
1154
|
}
|
|
1175
|
-
|
|
1155
|
+
if (asset instanceof webgpu.Texture) {
|
|
1176
1156
|
return this.addTextureAsset(asset, referenceCount);
|
|
1177
1157
|
}
|
|
1178
1158
|
return undefined;
|
|
1179
1159
|
}
|
|
1180
1160
|
addMaterialAsset(asset, referenceCount = 0) {
|
|
1181
|
-
let pointer =
|
|
1161
|
+
let pointer = asset.userData["assetPointer"];
|
|
1182
1162
|
if (!pointer) {
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
const value = asset[k];
|
|
1163
|
+
const textureMap = new Map();
|
|
1164
|
+
Object.entries(asset).forEach(([key, value]) => {
|
|
1186
1165
|
if (value instanceof webgpu.Texture) {
|
|
1187
|
-
|
|
1188
|
-
textureMap.set(
|
|
1166
|
+
const texturePointer = this.addTextureAsset(value, 1);
|
|
1167
|
+
textureMap.set(key, texturePointer);
|
|
1189
1168
|
}
|
|
1190
|
-
}
|
|
1169
|
+
});
|
|
1191
1170
|
pointer = new MaterialAssetPointer(asset, textureMap, referenceCount);
|
|
1192
1171
|
this.materialAssets.set(asset.uuid, pointer);
|
|
1193
1172
|
}
|
|
@@ -1197,7 +1176,7 @@ class AssetManager {
|
|
|
1197
1176
|
return pointer;
|
|
1198
1177
|
}
|
|
1199
1178
|
addTextureAsset(asset, referenceCount = 0) {
|
|
1200
|
-
let pointer =
|
|
1179
|
+
let pointer = asset.userData["assetPointer"];
|
|
1201
1180
|
if (!pointer) {
|
|
1202
1181
|
pointer = new TextureAssetPointer(asset, referenceCount);
|
|
1203
1182
|
this.textureAssets.set(asset.uuid, pointer);
|
|
@@ -1208,7 +1187,7 @@ class AssetManager {
|
|
|
1208
1187
|
return pointer;
|
|
1209
1188
|
}
|
|
1210
1189
|
addGeometryAsset(asset, referenceCount = 0) {
|
|
1211
|
-
let pointer =
|
|
1190
|
+
let pointer = asset.userData["assetPointer"];
|
|
1212
1191
|
if (!pointer) {
|
|
1213
1192
|
pointer = new GeometryAssetPointer(asset, referenceCount);
|
|
1214
1193
|
this.geometryAssets.set(asset.uuid, pointer);
|
|
@@ -1219,34 +1198,21 @@ class AssetManager {
|
|
|
1219
1198
|
return pointer;
|
|
1220
1199
|
}
|
|
1221
1200
|
releaseAsset(asset) {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
p.release();
|
|
1201
|
+
const pointer = asset.userData["assetPointer"];
|
|
1202
|
+
if (pointer) {
|
|
1203
|
+
pointer.release();
|
|
1226
1204
|
}
|
|
1227
1205
|
else {
|
|
1228
1206
|
asset.dispose();
|
|
1229
1207
|
}
|
|
1230
1208
|
}
|
|
1231
1209
|
clearAssets() {
|
|
1232
|
-
this.geometryAssets.forEach((
|
|
1233
|
-
p.forceRelease();
|
|
1234
|
-
});
|
|
1210
|
+
this.geometryAssets.forEach((pointer) => pointer.forceRelease());
|
|
1235
1211
|
this.geometryAssets.clear();
|
|
1236
|
-
this.materialAssets.forEach((
|
|
1237
|
-
p.forceRelease();
|
|
1238
|
-
});
|
|
1212
|
+
this.materialAssets.forEach((pointer) => pointer.forceRelease());
|
|
1239
1213
|
this.materialAssets.clear();
|
|
1240
|
-
this.textureAssets.forEach((
|
|
1241
|
-
p.forceRelease();
|
|
1242
|
-
});
|
|
1214
|
+
this.textureAssets.forEach((pointer) => pointer.forceRelease());
|
|
1243
1215
|
this.textureAssets.clear();
|
|
1244
|
-
// let pointers = Array.from(this.assetPointer.values());
|
|
1245
|
-
// pointers.forEach((p) =>
|
|
1246
|
-
// {
|
|
1247
|
-
// p.forceRelease();
|
|
1248
|
-
// });
|
|
1249
|
-
// this.assetPointer.clear();
|
|
1250
1216
|
}
|
|
1251
1217
|
}
|
|
1252
1218
|
|
|
@@ -1521,12 +1487,7 @@ class Viewport {
|
|
|
1521
1487
|
}
|
|
1522
1488
|
get renderer() {
|
|
1523
1489
|
if (!this._renderer) {
|
|
1524
|
-
|
|
1525
|
-
return this._webGLRenderer;
|
|
1526
|
-
}
|
|
1527
|
-
else {
|
|
1528
|
-
throw Error("Renderer is not initialized");
|
|
1529
|
-
}
|
|
1490
|
+
throw Error("Renderer is not initialized");
|
|
1530
1491
|
}
|
|
1531
1492
|
return this._renderer;
|
|
1532
1493
|
}
|
|
@@ -1539,7 +1500,6 @@ class Viewport {
|
|
|
1539
1500
|
constructor(app, viewportParam, rendererParam, postProcessParam) {
|
|
1540
1501
|
this._uiDom = null;
|
|
1541
1502
|
this._renderer = null;
|
|
1542
|
-
this._webGLRenderer = null;
|
|
1543
1503
|
this.labelRenderer = null;
|
|
1544
1504
|
this._app = null;
|
|
1545
1505
|
this.resizeObserver = null;
|
|
@@ -1553,7 +1513,6 @@ class Viewport {
|
|
|
1553
1513
|
if (viewportParam.elementId) {
|
|
1554
1514
|
this._outerContainer = document.getElementById(viewportParam.elementId);
|
|
1555
1515
|
}
|
|
1556
|
-
this.viewportParam = Object.assign({}, viewportParam);
|
|
1557
1516
|
this.createRenderer(rendererParam);
|
|
1558
1517
|
if (viewportParam.isLabelRendererNeeded) {
|
|
1559
1518
|
this.createLabelRenderer();
|
|
@@ -1575,7 +1534,7 @@ class Viewport {
|
|
|
1575
1534
|
this.setupPostProcess();
|
|
1576
1535
|
});
|
|
1577
1536
|
}
|
|
1578
|
-
|
|
1537
|
+
createRenderer(rendererParam) {
|
|
1579
1538
|
if (this._outerContainer) {
|
|
1580
1539
|
this._canvasContainer = document.createElement("div");
|
|
1581
1540
|
this._canvasContainer.style.left = "0px";
|
|
@@ -1602,31 +1561,15 @@ class Viewport {
|
|
|
1602
1561
|
renderP.logarithmicDepthBuffer = rendererParam.logarithmicDepthBuffer;
|
|
1603
1562
|
renderP.samples = rendererParam.samples;
|
|
1604
1563
|
renderP.colorBufferType = rendererParam.colorBufferType;
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
element.appendChild(this._webGLRenderer.domElement);
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
else {
|
|
1618
|
-
this._renderer = new webgpu.WebGPURenderer(renderP);
|
|
1619
|
-
// WebGPU 需要异步初始化
|
|
1620
|
-
await this._renderer.init();
|
|
1621
|
-
this._renderer.setPixelRatio(window.devicePixelRatio);
|
|
1622
|
-
this._renderer.setSize(width, height);
|
|
1623
|
-
this._renderer.shadowMap.enabled = rendererParam.shadowMapEnabled;
|
|
1624
|
-
this._renderer.shadowMap.type = rendererParam.shadowMapType;
|
|
1625
|
-
this._renderer.toneMapping = rendererParam.toneMapping;
|
|
1626
|
-
this._renderer.toneMappingExposure = rendererParam.toneMappingExposure;
|
|
1627
|
-
if (element) {
|
|
1628
|
-
element.appendChild(this._renderer.domElement);
|
|
1629
|
-
}
|
|
1564
|
+
this._renderer = new webgpu.WebGPURenderer(renderP);
|
|
1565
|
+
this._renderer.setPixelRatio(window.devicePixelRatio);
|
|
1566
|
+
this._renderer.setSize(width, height);
|
|
1567
|
+
this._renderer.shadowMap.enabled = rendererParam.shadowMapEnabled;
|
|
1568
|
+
this._renderer.shadowMap.type = rendererParam.shadowMapType;
|
|
1569
|
+
this._renderer.toneMapping = rendererParam.toneMapping;
|
|
1570
|
+
this._renderer.toneMappingExposure = rendererParam.toneMappingExposure;
|
|
1571
|
+
if (element) {
|
|
1572
|
+
element.appendChild(this._renderer.domElement);
|
|
1630
1573
|
}
|
|
1631
1574
|
}
|
|
1632
1575
|
createLabelRenderer() {
|
|
@@ -1673,7 +1616,97 @@ class Viewport {
|
|
|
1673
1616
|
this.setupPostProcess();
|
|
1674
1617
|
}
|
|
1675
1618
|
setupPostProcess() {
|
|
1676
|
-
|
|
1619
|
+
if (this.postProcessParam.steps.length === 0) {
|
|
1620
|
+
this.destroyPostProcess();
|
|
1621
|
+
this.markRenderStateDirty();
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
if (!this.postProcessing) {
|
|
1625
|
+
this.postProcessing = new webgpu.PostProcessing(this.renderer);
|
|
1626
|
+
}
|
|
1627
|
+
const scenePass = WebGPUPostProcessFactory.constructScenePass(this.app.world.scene, this.app.camera);
|
|
1628
|
+
let finalNode = scenePass.getTextureNode('output');
|
|
1629
|
+
this.postProcessParam.steps.forEach((step) => {
|
|
1630
|
+
switch (step.type) {
|
|
1631
|
+
case exports.PostProcessStepType.Bloom:
|
|
1632
|
+
{
|
|
1633
|
+
const bloomPass = WebGPUPostProcessFactory.constructBloomPass(scenePass, step);
|
|
1634
|
+
//console.log("[PostProcess] BloomPass 构建完成");
|
|
1635
|
+
finalNode = finalNode.add(bloomPass);
|
|
1636
|
+
break;
|
|
1637
|
+
}
|
|
1638
|
+
case exports.PostProcessStepType.DepthOfField:
|
|
1639
|
+
{
|
|
1640
|
+
const dofPass = WebGPUPostProcessFactory.constructDOFPass(scenePass, step);
|
|
1641
|
+
//console.log("[PostProcess] DOFPass 构建完成");
|
|
1642
|
+
finalNode = finalNode.add(dofPass);
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
case exports.PostProcessStepType.ScreenSpaceReflection:
|
|
1646
|
+
{
|
|
1647
|
+
console.warn("[PostProcess] SSR 目前存在技术问题,暂不支持。");
|
|
1648
|
+
// const ssrPass = WebGPUPostProcessFactory.constructSSRPass(scenePass, step as SSRParam);
|
|
1649
|
+
// console.log("[PostProcess] SSRPass 构建完成");
|
|
1650
|
+
//finalNode = blendColor(finalNode, ssrPass);
|
|
1651
|
+
break;
|
|
1652
|
+
}
|
|
1653
|
+
case exports.PostProcessStepType.GroundTruthAmbientOcclusion:
|
|
1654
|
+
{
|
|
1655
|
+
console.warn("[PostProcess] AO 目前存在技术问题,暂不支持。");
|
|
1656
|
+
// const stepParam = step as GTAOParam
|
|
1657
|
+
// const GTAOPass = WebGPUPostProcessFactory.constructGTAOPass(scenePass, stepParam);
|
|
1658
|
+
// console.log("[PostProcess] GTAOPass 构建完成");
|
|
1659
|
+
// if (stepParam.denoised)
|
|
1660
|
+
// {
|
|
1661
|
+
// const denoiseGTAOPass = WebGPUPostProcessFactory.constructGTAODenoisePass(scenePass, GTAOPass, stepParam);
|
|
1662
|
+
// console.log("[PostProcess] GTAODenoisePass 构建完成");
|
|
1663
|
+
// finalNode = denoiseGTAOPass.mul(finalNode);
|
|
1664
|
+
// }
|
|
1665
|
+
// else
|
|
1666
|
+
// {
|
|
1667
|
+
// finalNode = GTAOPass.getTextureNode().mul(finalNode);
|
|
1668
|
+
// }
|
|
1669
|
+
break;
|
|
1670
|
+
}
|
|
1671
|
+
case exports.PostProcessStepType.Outline:
|
|
1672
|
+
{
|
|
1673
|
+
const outlineParam = step;
|
|
1674
|
+
const outlinePass = WebGPUPostProcessFactory.constructOutlinePass(this.app.world.scene, scenePass.camera, this.outlineObjects, outlineParam);
|
|
1675
|
+
const { visibleEdge, hiddenEdge } = outlinePass;
|
|
1676
|
+
const pulsePeriod = tsl.uniform(outlineParam.pulsePeriod);
|
|
1677
|
+
const period = tsl.time.div(pulsePeriod).mul(2);
|
|
1678
|
+
const osc = tsl.oscSine(period).mul(.5).add(.5);
|
|
1679
|
+
const outlineColor = visibleEdge.mul(tsl.uniform(new webgpu.Color(outlineParam.visibleEdgeColor))).add(hiddenEdge.mul(tsl.uniform(new webgpu.Color(outlineParam.hiddenEdgeColor)))).mul(outlineParam.edgeStrength);
|
|
1680
|
+
const outlinePulse = pulsePeriod.greaterThan(0).select(outlineColor.mul(osc), outlineColor);
|
|
1681
|
+
// if(!this.denoiseOutlinePass)
|
|
1682
|
+
// {
|
|
1683
|
+
// this.denoiseOutlinePass = WebGPUPostProcessFactory.constructDenoisePass(this.scenePass, outlinePulse, DefaultDenoiseParam);
|
|
1684
|
+
// }
|
|
1685
|
+
// outlinePulse = this.denoiseOutlinePass.mul(outlinePulse)
|
|
1686
|
+
// finalNode = this.denoiseOutlinePass.mul(outlinePulse).add(finalNode);
|
|
1687
|
+
finalNode = outlinePulse.add(finalNode);
|
|
1688
|
+
//console.log("[PostProcess] OutlinePass 构建完成");
|
|
1689
|
+
break;
|
|
1690
|
+
}
|
|
1691
|
+
case exports.PostProcessStepType.Antialiasing:
|
|
1692
|
+
{
|
|
1693
|
+
const aaParam = step;
|
|
1694
|
+
if (aaParam.method === "fxaa") {
|
|
1695
|
+
finalNode = WebGPUPostProcessFactory.constructFXAAPass(finalNode);
|
|
1696
|
+
//console.log("[PostProcess] FXAAPass 构建完成");
|
|
1697
|
+
}
|
|
1698
|
+
if (aaParam.method === "smaa") {
|
|
1699
|
+
finalNode = WebGPUPostProcessFactory.constructSMAAPass(finalNode);
|
|
1700
|
+
//console.log("[PostProcess] SMAAPass 构建完成");
|
|
1701
|
+
}
|
|
1702
|
+
break;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
});
|
|
1706
|
+
this.postProcessing.outputNode = finalNode;
|
|
1707
|
+
this.postProcessing.needsUpdate = true;
|
|
1708
|
+
//console.log("[PostProcess] setup complete", this.postProcessParam.steps);
|
|
1709
|
+
this.markRenderStateDirty();
|
|
1677
1710
|
}
|
|
1678
1711
|
updatePostProcess(steps) {
|
|
1679
1712
|
this.postProcessParam.steps = steps;
|
|
@@ -1758,7 +1791,7 @@ class Viewport {
|
|
|
1758
1791
|
return;
|
|
1759
1792
|
}
|
|
1760
1793
|
if (this.postProcessing) {
|
|
1761
|
-
this.postProcessing.
|
|
1794
|
+
this.postProcessing.render();
|
|
1762
1795
|
}
|
|
1763
1796
|
else {
|
|
1764
1797
|
this.renderer.render(this.app.world.scene, this.app.camera);
|
|
@@ -1775,13 +1808,7 @@ class Viewport {
|
|
|
1775
1808
|
await this.postProcessing.renderAsync();
|
|
1776
1809
|
}
|
|
1777
1810
|
else {
|
|
1778
|
-
|
|
1779
|
-
await this._renderer.renderAsync(this.app.world.scene, this.app.camera);
|
|
1780
|
-
}
|
|
1781
|
-
else if (this._webGLRenderer) {
|
|
1782
|
-
console.log("render with gl");
|
|
1783
|
-
this._webGLRenderer.render(this.app.world.scene, this.app.camera);
|
|
1784
|
-
}
|
|
1811
|
+
await this.renderer.renderAsync(this.app.world.scene, this.app.camera);
|
|
1785
1812
|
}
|
|
1786
1813
|
// 检查 renderer.domElement 的尺寸
|
|
1787
1814
|
const sourceWidth = this.renderer.domElement.width;
|
|
@@ -2090,7 +2117,13 @@ class Controller {
|
|
|
2090
2117
|
this.pawn.enabled = isPawnEnabled;
|
|
2091
2118
|
}
|
|
2092
2119
|
init() {
|
|
2093
|
-
if (this.viewPort.canvas)
|
|
2120
|
+
if (this.viewPort.canvas) {
|
|
2121
|
+
this.viewPort.canvas.addEventListener("pointermove", this.onPointerMove);
|
|
2122
|
+
this.viewPort.canvas.addEventListener("pointerenter", this.onPointerEnter);
|
|
2123
|
+
this.viewPort.canvas.addEventListener("pointerleave", this.onPointerLeave);
|
|
2124
|
+
this.viewPort.canvas.addEventListener("pointerup", this.onPointerUp);
|
|
2125
|
+
this.viewPort.canvas.addEventListener("pointerdown", this.onPointerDown);
|
|
2126
|
+
}
|
|
2094
2127
|
}
|
|
2095
2128
|
tick(deltaTime) {
|
|
2096
2129
|
this.pawn.tick(deltaTime);
|
|
@@ -2100,7 +2133,13 @@ class Controller {
|
|
|
2100
2133
|
clearTimeout(this.leftClickTimer);
|
|
2101
2134
|
this.leftClickTimer = null;
|
|
2102
2135
|
}
|
|
2103
|
-
if (this.viewPort.canvas)
|
|
2136
|
+
if (this.viewPort.canvas) {
|
|
2137
|
+
this.viewPort.canvas.removeEventListener("pointermove", this.onPointerMove);
|
|
2138
|
+
this.viewPort.canvas.removeEventListener("pointerenter", this.onPointerEnter);
|
|
2139
|
+
this.viewPort.canvas.removeEventListener("pointerleave", this.onPointerLeave);
|
|
2140
|
+
this.viewPort.canvas.removeEventListener("pointerup", this.onPointerUp);
|
|
2141
|
+
this.viewPort.canvas.removeEventListener("pointerdown", this.onPointerDown);
|
|
2142
|
+
}
|
|
2104
2143
|
this.pawn.unpossess();
|
|
2105
2144
|
this.pawn.destroy();
|
|
2106
2145
|
this._pawn = null;
|
|
@@ -2222,14 +2261,6 @@ class Controller {
|
|
|
2222
2261
|
focusTo(targetPos, targetQuat, distance, time, onGoing = null, onFinished = null) {
|
|
2223
2262
|
this.pawn.focusTo(targetPos, targetQuat, distance, time, onGoing, onFinished);
|
|
2224
2263
|
}
|
|
2225
|
-
setPawn(pawn) {
|
|
2226
|
-
if (this._pawn) {
|
|
2227
|
-
this._pawn.unpossess();
|
|
2228
|
-
this._pawn.destroy();
|
|
2229
|
-
}
|
|
2230
|
-
this._pawn = pawn;
|
|
2231
|
-
this._pawn.possess();
|
|
2232
|
-
}
|
|
2233
2264
|
}
|
|
2234
2265
|
|
|
2235
2266
|
class CameraFactory {
|
|
@@ -2255,7 +2286,7 @@ class CameraFactory {
|
|
|
2255
2286
|
catch (error) {
|
|
2256
2287
|
console.warn("[CameraFactory]Error occurred while creating camera: ", error);
|
|
2257
2288
|
console.warn("[CameraFactory]Create default perspective camera instead");
|
|
2258
|
-
return new webgpu.PerspectiveCamera(50, 1, 0.1,
|
|
2289
|
+
return new webgpu.PerspectiveCamera(50, 1, 0.1, 1000);
|
|
2259
2290
|
}
|
|
2260
2291
|
}
|
|
2261
2292
|
static updataCamera(param, camera) {
|
|
@@ -2269,7 +2300,6 @@ class CameraFactory {
|
|
|
2269
2300
|
camera.far = data.far;
|
|
2270
2301
|
camera.fov = data.fov;
|
|
2271
2302
|
camera.aspect = data.aspect;
|
|
2272
|
-
camera.updateProjectionMatrix();
|
|
2273
2303
|
return camera;
|
|
2274
2304
|
}
|
|
2275
2305
|
return new webgpu.PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
|
|
@@ -2284,7 +2314,6 @@ class CameraFactory {
|
|
|
2284
2314
|
camera.right = data.right;
|
|
2285
2315
|
camera.top = data.top;
|
|
2286
2316
|
camera.bottom = data.bottom;
|
|
2287
|
-
camera.updateProjectionMatrix();
|
|
2288
2317
|
return camera;
|
|
2289
2318
|
}
|
|
2290
2319
|
return new webgpu.OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
|
|
@@ -2305,7 +2334,7 @@ class CameraFactory {
|
|
|
2305
2334
|
|
|
2306
2335
|
const DefaultPerspectiveCameraParam = {
|
|
2307
2336
|
near: 0.1,
|
|
2308
|
-
far:
|
|
2337
|
+
far: 1000,
|
|
2309
2338
|
type: "Perspective",
|
|
2310
2339
|
fov: 50,
|
|
2311
2340
|
aspect: 1,
|
|
@@ -2837,14 +2866,7 @@ const DefaultWorldParam = {
|
|
|
2837
2866
|
levelActorClass: LevelActor,
|
|
2838
2867
|
};
|
|
2839
2868
|
|
|
2840
|
-
/** 动画循环启动延迟时间(毫秒) */
|
|
2841
|
-
const ANIMATION_START_DELAY = 100;
|
|
2842
|
-
/**
|
|
2843
|
-
* Three.js应用程序主类
|
|
2844
|
-
* 负责管理场景、视口、控制器和资源
|
|
2845
|
-
*/
|
|
2846
2869
|
class ThreeJsApp {
|
|
2847
|
-
// ========== 公共访问器 ==========
|
|
2848
2870
|
get camera() {
|
|
2849
2871
|
return this._camera;
|
|
2850
2872
|
}
|
|
@@ -2869,132 +2891,67 @@ class ThreeJsApp {
|
|
|
2869
2891
|
get onCameraChangedDelegate() {
|
|
2870
2892
|
return this._onCameraChangedDelegate;
|
|
2871
2893
|
}
|
|
2872
|
-
/**
|
|
2873
|
-
* 构造ThreeJs应用程序实例
|
|
2874
|
-
* @param appParam 应用程序参数配置
|
|
2875
|
-
*/
|
|
2876
2894
|
constructor(appParam = DefaultAppParam) {
|
|
2877
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2878
|
-
// ========== 私有字段 ==========
|
|
2879
|
-
this.animationFrameHandle = 0;
|
|
2880
2895
|
this._tickingFunctions = [];
|
|
2881
2896
|
this._appParam = { viewportParam: DefaultViewportParam };
|
|
2882
2897
|
this._onCameraChangedDelegate = new Delegate();
|
|
2883
|
-
|
|
2884
|
-
this._appParam.
|
|
2885
|
-
this._appParam.
|
|
2886
|
-
this._appParam.
|
|
2887
|
-
this._appParam.
|
|
2888
|
-
this._appParam.worldParam = (_e = appParam.worldParam) !== null && _e !== void 0 ? _e : DefaultWorldParam;
|
|
2889
|
-
this._appParam.isRenderEveryFrame = appParam.isRenderEveryFrame;
|
|
2890
|
-
this._appParam.classes = (_f = appParam.classes) !== null && _f !== void 0 ? _f : {
|
|
2898
|
+
this._appParam.cameraParam = appParam.cameraParam ? appParam.cameraParam : DefaultCameraParam;
|
|
2899
|
+
this._appParam.renderParam = appParam.renderParam ? appParam.renderParam : DefaultRendererParameters;
|
|
2900
|
+
this._appParam.postProcessParam = appParam.postProcessParam ? appParam.postProcessParam : DefaultPostProcessParam;
|
|
2901
|
+
this._appParam.viewportParam = appParam.viewportParam ? appParam.viewportParam : DefaultViewportParam;
|
|
2902
|
+
this._appParam.classes = appParam.classes ? appParam.classes : {
|
|
2891
2903
|
assetManagerClass: AssetManager,
|
|
2892
2904
|
controllerClass: Controller,
|
|
2893
2905
|
worldClass: World,
|
|
2894
2906
|
viewportClass: Viewport,
|
|
2895
2907
|
};
|
|
2896
|
-
|
|
2908
|
+
this._appParam.isRenderEveryFrame = appParam.isRenderEveryFrame;
|
|
2897
2909
|
this._clock = new webgpu.Clock();
|
|
2898
2910
|
this._camera = CameraFactory.createCamera(this._appParam.cameraParam);
|
|
2899
|
-
this._world = new this._appParam.classes.worldClass(this, this._appParam.worldParam);
|
|
2911
|
+
this._world = new this._appParam.classes.worldClass(this, this._appParam.worldParam ? this._appParam.worldParam : DefaultWorldParam);
|
|
2900
2912
|
this._viewport = new this._appParam.classes.viewportClass(this, this._appParam.viewportParam, this._appParam.renderParam, this._appParam.postProcessParam);
|
|
2901
2913
|
this._controller = new this._appParam.classes.controllerClass(this);
|
|
2902
2914
|
this._assetManager = new this._appParam.classes.assetManagerClass(this);
|
|
2915
|
+
this.viewport.renderer.setAnimationLoop(() => {
|
|
2916
|
+
const delta = this._clock.getDelta();
|
|
2917
|
+
this.tick(delta);
|
|
2918
|
+
});
|
|
2903
2919
|
this.postConstruct();
|
|
2904
|
-
this.startAnimationLoop();
|
|
2905
2920
|
}
|
|
2906
|
-
/**
|
|
2907
|
-
* 构造后初始化钩子
|
|
2908
|
-
* 按顺序初始化控制器、世界和视口
|
|
2909
|
-
*/
|
|
2910
2921
|
postConstruct() {
|
|
2911
2922
|
this.controller.init();
|
|
2912
2923
|
this.world.init();
|
|
2913
2924
|
this.viewport.init();
|
|
2914
2925
|
}
|
|
2915
|
-
/**
|
|
2916
|
-
* 公共初始化方法
|
|
2917
|
-
* 可由子类重写以添加自定义初始化逻辑
|
|
2918
|
-
*/
|
|
2919
2926
|
init() {
|
|
2920
|
-
|
|
2921
|
-
}
|
|
2922
|
-
/**
|
|
2923
|
-
* 启动动画循环
|
|
2924
|
-
* 使用延迟启动以确保所有组件完全初始化
|
|
2925
|
-
*/
|
|
2926
|
-
startAnimationLoop() {
|
|
2927
|
-
const tick = () => {
|
|
2928
|
-
this.animationFrameHandle = requestAnimationFrame(tick);
|
|
2929
|
-
try {
|
|
2930
|
-
const delta = this._clock.getDelta();
|
|
2931
|
-
this.tick(delta);
|
|
2932
|
-
}
|
|
2933
|
-
catch (error) {
|
|
2934
|
-
console.error('动画循环错误:', error);
|
|
2935
|
-
}
|
|
2936
|
-
};
|
|
2937
|
-
setTimeout(() => {
|
|
2938
|
-
tick();
|
|
2939
|
-
}, ANIMATION_START_DELAY);
|
|
2940
|
-
}
|
|
2941
|
-
/**
|
|
2942
|
-
* 每帧更新方法
|
|
2943
|
-
* @param deltaTime 距离上一帧的时间增量(秒)
|
|
2944
|
-
*/
|
|
2927
|
+
}
|
|
2945
2928
|
tick(deltaTime) {
|
|
2946
2929
|
this._controller.tick(deltaTime);
|
|
2947
2930
|
this.world.tick(deltaTime);
|
|
2948
|
-
// 执行所有注册的tick函数
|
|
2949
2931
|
this._tickingFunctions.forEach(func => {
|
|
2950
2932
|
func(deltaTime);
|
|
2951
2933
|
});
|
|
2952
|
-
// 根据配置决定是否每帧都渲染
|
|
2953
2934
|
if (this._appParam.isRenderEveryFrame) {
|
|
2954
2935
|
this.viewport.markRenderStateDirty();
|
|
2955
2936
|
}
|
|
2956
2937
|
this.viewport.render();
|
|
2957
2938
|
}
|
|
2958
|
-
/**
|
|
2959
|
-
* 添加每帧执行的函数
|
|
2960
|
-
* @param func 接收deltaTime参数的回调函数
|
|
2961
|
-
*/
|
|
2962
2939
|
addTickingFunction(func) {
|
|
2963
2940
|
this._tickingFunctions.push(func);
|
|
2964
2941
|
}
|
|
2965
|
-
/**
|
|
2966
|
-
* 移除已注册的tick函数
|
|
2967
|
-
* @param func 要移除的函数引用
|
|
2968
|
-
*/
|
|
2969
2942
|
removeTickingFunction(func) {
|
|
2970
2943
|
const index = this._tickingFunctions.indexOf(func);
|
|
2971
2944
|
if (index >= 0) {
|
|
2972
2945
|
this._tickingFunctions.splice(index, 1);
|
|
2973
2946
|
}
|
|
2974
2947
|
}
|
|
2975
|
-
/**
|
|
2976
|
-
* 销毁应用程序并清理所有资源
|
|
2977
|
-
*/
|
|
2978
2948
|
destroy() {
|
|
2979
|
-
// 停止动画循环
|
|
2980
|
-
if (this.animationFrameHandle) {
|
|
2981
|
-
cancelAnimationFrame(this.animationFrameHandle);
|
|
2982
|
-
this.animationFrameHandle = 0;
|
|
2983
|
-
}
|
|
2984
|
-
// 清理委托
|
|
2985
2949
|
this.onCameraChangedDelegate.clear();
|
|
2986
|
-
// 销毁各个组件
|
|
2987
2950
|
this.controller.destroy();
|
|
2988
2951
|
this.world.destroy();
|
|
2989
2952
|
this.viewport.destroy();
|
|
2990
2953
|
this._assetManager.clearAssets();
|
|
2991
|
-
// 清空tick函数列表
|
|
2992
|
-
this._tickingFunctions = [];
|
|
2993
2954
|
}
|
|
2994
|
-
/**
|
|
2995
|
-
* 更新相机参数
|
|
2996
|
-
* @param param 新的相机参数
|
|
2997
|
-
*/
|
|
2998
2955
|
updateCamera(param) {
|
|
2999
2956
|
const previousCam = this.camera;
|
|
3000
2957
|
this._camera = CameraFactory.updataCamera(param, this.camera);
|
|
@@ -3005,31 +2962,16 @@ class ThreeJsApp {
|
|
|
3005
2962
|
this._camera.updateProjectionMatrix();
|
|
3006
2963
|
this.viewport.markRenderStateDirty();
|
|
3007
2964
|
}
|
|
3008
|
-
/**
|
|
3009
|
-
* 窗口大小改变时的处理
|
|
3010
|
-
* @param width 新的宽度
|
|
3011
|
-
* @param height 新的高度
|
|
3012
|
-
*/
|
|
3013
2965
|
onWindowResize(width, height) {
|
|
3014
2966
|
if (this.camera instanceof webgpu.PerspectiveCamera) {
|
|
3015
2967
|
this.camera.aspect = width / height;
|
|
3016
2968
|
}
|
|
3017
|
-
//
|
|
3018
|
-
//
|
|
3019
|
-
//
|
|
3020
|
-
// this.camera.left = -width / 2;
|
|
3021
|
-
// this.camera.right = width / 2;
|
|
3022
|
-
// this.camera.top = height / 2;
|
|
3023
|
-
// this.camera.bottom = -height / 2;
|
|
2969
|
+
// if(this.camera instanceof OrthographicCamera)
|
|
2970
|
+
// {
|
|
2971
|
+
// // to do
|
|
3024
2972
|
// }
|
|
3025
2973
|
this.camera.updateProjectionMatrix();
|
|
3026
2974
|
}
|
|
3027
|
-
/**
|
|
3028
|
-
* 将当前场景渲染为图片
|
|
3029
|
-
* @param width 图片宽度,默认1024
|
|
3030
|
-
* @param height 图片高度,默认1024
|
|
3031
|
-
* @returns 图片的DataURL
|
|
3032
|
-
*/
|
|
3033
2975
|
async renderAsImage(width = 1024, height = 1024) {
|
|
3034
2976
|
return await this.viewport.renderAsImage(width, height);
|
|
3035
2977
|
}
|
|
@@ -3161,7 +3103,7 @@ class AmbientLightComponent extends LightComponent {
|
|
|
3161
3103
|
this.threeObject.intensity = intensity;
|
|
3162
3104
|
}
|
|
3163
3105
|
createDefaultObject() {
|
|
3164
|
-
return new
|
|
3106
|
+
return new webgpu.AmbientLight(0xffffff, 10);
|
|
3165
3107
|
}
|
|
3166
3108
|
setPosition(...args) {
|
|
3167
3109
|
if (args.length === 1) {
|
|
@@ -3205,7 +3147,7 @@ class AmbientLightActor extends Actor {
|
|
|
3205
3147
|
}
|
|
3206
3148
|
|
|
3207
3149
|
class BoxComponent extends MeshComponent {
|
|
3208
|
-
constructor(app, width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1, material = new webgpu.MeshStandardMaterial(
|
|
3150
|
+
constructor(app, width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1, material = new webgpu.MeshStandardMaterial(), uuid) {
|
|
3209
3151
|
super(app, new webgpu.BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments), material, uuid);
|
|
3210
3152
|
}
|
|
3211
3153
|
}
|
|
@@ -3352,120 +3294,6 @@ class LabelComponent extends SceneComponent {
|
|
|
3352
3294
|
// labelStyle.style.fontSize = "10px";
|
|
3353
3295
|
// labelStyle.style.pointerEvents = 'auto';
|
|
3354
3296
|
|
|
3355
|
-
class CurveComponent extends SceneComponent {
|
|
3356
|
-
get threeObject() {
|
|
3357
|
-
if (!this.obj) {
|
|
3358
|
-
throw new Error("threeObject is null");
|
|
3359
|
-
}
|
|
3360
|
-
return this.obj;
|
|
3361
|
-
}
|
|
3362
|
-
set threeObject(newThreeObject) {
|
|
3363
|
-
this.obj = newThreeObject;
|
|
3364
|
-
if (this.obj) {
|
|
3365
|
-
this.obj.userData["LYObject"] = this;
|
|
3366
|
-
}
|
|
3367
|
-
}
|
|
3368
|
-
get material() {
|
|
3369
|
-
return this.threeObject.material;
|
|
3370
|
-
}
|
|
3371
|
-
constructor(app, points, setup = { color: 0xffffff }, bCreateLine = true, uuid) {
|
|
3372
|
-
var _a, _b, _c;
|
|
3373
|
-
super(app, uuid);
|
|
3374
|
-
this.closed = (_a = setup.closed) !== null && _a !== void 0 ? _a : false;
|
|
3375
|
-
this.curveType = (_b = setup.type) !== null && _b !== void 0 ? _b : 'centripetal';
|
|
3376
|
-
this.tension = (_c = setup.tension) !== null && _c !== void 0 ? _c : 0;
|
|
3377
|
-
this.sourcePoints = points;
|
|
3378
|
-
this.curve = new three.CatmullRomCurve3(points, this.closed, this.curveType, this.tension);
|
|
3379
|
-
this.points = this.curve.getPoints(points.length * (this.tension === 0 ? 1 : 10) - 1);
|
|
3380
|
-
this.material.color = new three.Color(setup.color);
|
|
3381
|
-
this.bCreateLine = bCreateLine;
|
|
3382
|
-
this.name = "CurveComponent";
|
|
3383
|
-
if (this.bCreateLine) {
|
|
3384
|
-
this.createLine();
|
|
3385
|
-
}
|
|
3386
|
-
}
|
|
3387
|
-
isValid() {
|
|
3388
|
-
return this.threeObject != null;
|
|
3389
|
-
}
|
|
3390
|
-
createDefaultObject() {
|
|
3391
|
-
// 创建默认材质
|
|
3392
|
-
const material = new three.LineBasicMaterial({
|
|
3393
|
-
color: 0xffffff,
|
|
3394
|
-
transparent: true,
|
|
3395
|
-
opacity: 1
|
|
3396
|
-
});
|
|
3397
|
-
// 创建空的几何体和线对象
|
|
3398
|
-
const geometry = new three.BufferGeometry();
|
|
3399
|
-
const line = new three.Line(geometry, material);
|
|
3400
|
-
return line;
|
|
3401
|
-
}
|
|
3402
|
-
resetPoints(points) {
|
|
3403
|
-
this.sourcePoints = points;
|
|
3404
|
-
this.curve = new three.CatmullRomCurve3(points, this.closed, this.curveType, this.tension);
|
|
3405
|
-
this.points = this.curve.getPoints(points.length * (this.tension === 0 ? 1 : 10) - 1);
|
|
3406
|
-
if (this.bCreateLine) {
|
|
3407
|
-
this.createLine();
|
|
3408
|
-
}
|
|
3409
|
-
}
|
|
3410
|
-
createLine() {
|
|
3411
|
-
const positions = [];
|
|
3412
|
-
for (let i = 0; i < this.points.length; ++i) {
|
|
3413
|
-
positions.push(this.points[i].x);
|
|
3414
|
-
positions.push(this.points[i].y);
|
|
3415
|
-
positions.push(this.points[i].z);
|
|
3416
|
-
}
|
|
3417
|
-
const geometry = this.threeObject.geometry;
|
|
3418
|
-
geometry.setAttribute('position', new three.Float32BufferAttribute(positions, 3));
|
|
3419
|
-
}
|
|
3420
|
-
destroy() {
|
|
3421
|
-
if (this.isValid() && this.threeObject) {
|
|
3422
|
-
if (this.threeObject.geometry) {
|
|
3423
|
-
this.threeObject.geometry.dispose();
|
|
3424
|
-
}
|
|
3425
|
-
if (this.material) {
|
|
3426
|
-
this.material.dispose();
|
|
3427
|
-
}
|
|
3428
|
-
}
|
|
3429
|
-
super.destroy();
|
|
3430
|
-
}
|
|
3431
|
-
get SourcePoints() {
|
|
3432
|
-
return this.sourcePoints;
|
|
3433
|
-
}
|
|
3434
|
-
get Curve() {
|
|
3435
|
-
return this.curve;
|
|
3436
|
-
}
|
|
3437
|
-
get Points() {
|
|
3438
|
-
return this.points;
|
|
3439
|
-
}
|
|
3440
|
-
getPointAt(u) {
|
|
3441
|
-
return this.curve.getPointAt(u);
|
|
3442
|
-
}
|
|
3443
|
-
getTangentAt(u) {
|
|
3444
|
-
return this.curve.getTangentAt(u);
|
|
3445
|
-
}
|
|
3446
|
-
// 返回曲线在参数 u 处的世界坐标点
|
|
3447
|
-
getWorldPointAt(u) {
|
|
3448
|
-
const p = this.curve.getPointAt(u).clone();
|
|
3449
|
-
if (this.obj) {
|
|
3450
|
-
this.obj.updateMatrixWorld(true);
|
|
3451
|
-
return this.localToWorld(p);
|
|
3452
|
-
}
|
|
3453
|
-
return p;
|
|
3454
|
-
}
|
|
3455
|
-
// 返回曲线在参数 u 处的世界坐标系下的单位切线方向
|
|
3456
|
-
getWorldTangentAt(u) {
|
|
3457
|
-
const t = this.curve.getTangentAt(u).clone();
|
|
3458
|
-
if (this.obj) {
|
|
3459
|
-
this.obj.updateMatrixWorld(true);
|
|
3460
|
-
t.transformDirection(this.obj.matrixWorld);
|
|
3461
|
-
}
|
|
3462
|
-
return t;
|
|
3463
|
-
}
|
|
3464
|
-
getLength() {
|
|
3465
|
-
return this.curve.getLength();
|
|
3466
|
-
}
|
|
3467
|
-
}
|
|
3468
|
-
|
|
3469
3297
|
const DefaultBloomParam = {
|
|
3470
3298
|
type: exports.PostProcessStepType.Bloom,
|
|
3471
3299
|
threshold: 0,
|
|
@@ -3747,7 +3575,6 @@ exports.AssetManager = AssetManager;
|
|
|
3747
3575
|
exports.BoxActor = BoxActor;
|
|
3748
3576
|
exports.BoxComponent = BoxComponent;
|
|
3749
3577
|
exports.Controller = Controller;
|
|
3750
|
-
exports.CurveComponent = CurveComponent;
|
|
3751
3578
|
exports.DefaultAAParams = DefaultAAParams;
|
|
3752
3579
|
exports.DefaultAppParam = DefaultAppParam;
|
|
3753
3580
|
exports.DefaultBloomParam = DefaultBloomParam;
|
|
@@ -3775,7 +3602,6 @@ exports.LevelComponent = LevelComponent;
|
|
|
3775
3602
|
exports.MaterialAssetPointer = MaterialAssetPointer;
|
|
3776
3603
|
exports.MeshComponent = MeshComponent;
|
|
3777
3604
|
exports.Orbital = Orbital;
|
|
3778
|
-
exports.Pawn = Pawn;
|
|
3779
3605
|
exports.PlaneActor = PlaneActor;
|
|
3780
3606
|
exports.PlaneComponent = PlaneComponent;
|
|
3781
3607
|
exports.SceneComponent = SceneComponent;
|