|
@@ -1,9 +1,12 @@
|
|
|
import * as THREE from 'three';
|
|
import * as THREE from 'three';
|
|
|
import UseThree from '../../../../utils/threejs/useThree';
|
|
import UseThree from '../../../../utils/threejs/useThree';
|
|
|
import ModelContext from './spray.threejs.base';
|
|
import ModelContext from './spray.threejs.base';
|
|
|
|
|
+import PenshaContext from './spray.threejs.pensha';
|
|
|
import { animateCamera } from '/@/utils/threejs/util';
|
|
import { animateCamera } from '/@/utils/threejs/util';
|
|
|
import useEvent from '../../../../utils/threejs/useEvent';
|
|
import useEvent from '../../../../utils/threejs/useEvent';
|
|
|
|
|
|
|
|
|
|
+type modelName = 'spray' | 'pensha';
|
|
|
|
|
+
|
|
|
/** 模型总控制器 */
|
|
/** 模型总控制器 */
|
|
|
let model: UseThree;
|
|
let model: UseThree;
|
|
|
/** 当前展示的具体模型的 Object3D 对象 */
|
|
/** 当前展示的具体模型的 Object3D 对象 */
|
|
@@ -11,7 +14,7 @@ let group: THREE.Object3D;
|
|
|
/** 具体模型内容列表,包含此模型总控制器下的所有可用的具体模型内容 */
|
|
/** 具体模型内容列表,包含此模型总控制器下的所有可用的具体模型内容 */
|
|
|
const modelContextList: {
|
|
const modelContextList: {
|
|
|
/** 当前模型类型,在控制器下有多个具体模型时分辨它们 */
|
|
/** 当前模型类型,在控制器下有多个具体模型时分辨它们 */
|
|
|
- type: string;
|
|
|
|
|
|
|
+ type: modelName;
|
|
|
/** 模型的具体内容,即负责模型导入、绘制的上下文对象,一个控制器可以新建多个 */
|
|
/** 模型的具体内容,即负责模型导入、绘制的上下文对象,一个控制器可以新建多个 */
|
|
|
context?: ModelContext;
|
|
context?: ModelContext;
|
|
|
}[] = [];
|
|
}[] = [];
|
|
@@ -52,11 +55,12 @@ function initEventListender() {
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
/** 设置模型类型并切换,不同的类型通常对应不同的具体模型,在模型总控制器下的具体模型会根据传入的参数彼此交互、切换 */
|
|
/** 设置模型类型并切换,不同的类型通常对应不同的具体模型,在模型总控制器下的具体模型会根据传入的参数彼此交互、切换 */
|
|
|
-export function setModelType(modelType: 'spray') {
|
|
|
|
|
|
|
+export function setModelType(modelType: modelName) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
if (!model) return reject('模型未初始化');
|
|
if (!model) return reject('模型未初始化');
|
|
|
modelContextList.forEach(({ type, context }) => {
|
|
modelContextList.forEach(({ type, context }) => {
|
|
|
if (!context) return reject('模型未初始化');
|
|
if (!context) return reject('模型未初始化');
|
|
|
|
|
+ // 如果是指定类型的模型,则显示该模型,否则应该检查是否已经存在该模型,如果存在则隐藏
|
|
|
if (modelType === type) {
|
|
if (modelType === type) {
|
|
|
group = context?.group as THREE.Object3D;
|
|
group = context?.group as THREE.Object3D;
|
|
|
setTimeout(async () => {
|
|
setTimeout(async () => {
|
|
@@ -66,6 +70,12 @@ export function setModelType(modelType: 'spray') {
|
|
|
await animateCamera({ x: -693, y: 474, z: 398 }, { x: 0, y: 0, z: 0 }, context.cameraPostion, context.orbitTarget, model, 0.8);
|
|
await animateCamera({ x: -693, y: 474, z: 398 }, { x: 0, y: 0, z: 0 }, context.cameraPostion, context.orbitTarget, model, 0.8);
|
|
|
resolve(null);
|
|
resolve(null);
|
|
|
}, 400);
|
|
}, 400);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const group = context?.group;
|
|
|
|
|
+ const name = group?.name;
|
|
|
|
|
+ if (name && group && model.scene?.getObjectByName(name)) {
|
|
|
|
|
+ model.scene?.remove(group);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -87,6 +97,13 @@ export function mountedThree(sceneSelctor: string, cssSelectors: string[]) {
|
|
|
type: 'spray',
|
|
type: 'spray',
|
|
|
context: model1,
|
|
context: model1,
|
|
|
});
|
|
});
|
|
|
|
|
+ const model2 = new PenshaContext(model);
|
|
|
|
|
+ await model2.mountedThree();
|
|
|
|
|
+ model2.initCssElement(selectors);
|
|
|
|
|
+ modelContextList.push({
|
|
|
|
|
+ type: 'pensha',
|
|
|
|
|
+ context: model2,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
initEventListender();
|
|
initEventListender();
|
|
|
model.animate();
|
|
model.animate();
|