Browse Source

提交吸附功能

dev
刘向辉 3 years ago
parent
commit
65ed4698f9
  1. 13
      src/app/babylon/controller/scene-manager.ts
  2. 51
      src/app/babylon/tool/babylon-tool.ts

13
src/app/babylon/controller/scene-manager.ts

@ -61,6 +61,8 @@ import { LoadTool } from '../tool/load-tool';
//场景管理器
export class SceneManager {
//----------------Camera-----------------\\
public engine: Engine;
@ -875,11 +877,20 @@ export class SceneManager {
ModeManager.log("吸附模型" + target);
let targetRoot = SceneManager.getRootTransformNode(target);
let targetRoot = SceneManager.getRootTransformNode(target) as AbstractMesh;
if (mover == targetRoot) {
return;
}
//先通过吸附点吸附
let byAdsorbPoint = BabylonTool.adsorb2MeshByPoint(mover, targetRoot, "WAI")
//完成吸附了
if (byAdsorbPoint) {
return;
}
let aimPos_y: number = 0;
let direction = 0.5;

51
src/app/babylon/tool/babylon-tool.ts

@ -10,6 +10,7 @@ import {
ISceneLoaderPluginAsync,
ISceneLoaderProgressEvent,
Mesh,
Node,
NodeMaterial,
PBRMaterial,
QuadraticEase,
@ -537,6 +538,56 @@ export class BabylonTool {
}
/**
* mesh
* key的节点
* @param mover
* @param targetRoot
* @param key
*/
public static adsorb2MeshByPoint(mover: AbstractMesh, targetRoot: AbstractMesh, key: string) {
//吸附成功
let isSuccess = false;
//找到移动者的对齐点
let moverAdsorbNode = BabylonTool.getNodeContainKey(mover, key);
if (moverAdsorbNode != null && moverAdsorbNode.length > 0 && targetRoot instanceof Mesh) {
let moverAdsorbPoint = moverAdsorbNode[0] as AbstractMesh;
let aimNode = BabylonTool.getNodeContainKey(targetRoot, moverAdsorbPoint.name);
if (aimNode != null && aimNode.length > 0) {
let aimAdsorbPoint = aimNode[0] as AbstractMesh;
let aimPos = aimAdsorbPoint.getAbsolutePosition();
//世界坐标下,移动者的吸附点相对于根节点的偏移
let moverLocalPos = moverAdsorbPoint.getAbsolutePosition().subtract(mover.getAbsolutePosition());
let moverNewPos = aimPos.subtract(moverLocalPos);
mover.setAbsolutePosition(moverNewPos);
isSuccess = true;
}
}
return isSuccess;
}
/**
*
* Adsorb_
* @param mesh
*/
public static getNodeContainKey(mesh: AbstractMesh, key: string) {
let moverAdsorbNode = mesh.getChildren((node: Node) => {
if (TsTool.stringContain(node.name, key)) {
return true;
}
else {
return false;
}
}, false)
return moverAdsorbNode;
}
}
//输入提示界面

Loading…
Cancel
Save