Compare commits
No commits in common. "34f1b1c11fe44b207e6ea837a5373c6500cffdd1" and "21815b8c880066fb733a3669e86df6537574494a" have entirely different histories.
34f1b1c11f
...
21815b8c88
|
@ -59,21 +59,31 @@ watch(() => props.sceneUrl, val => {
|
||||||
init();
|
init();
|
||||||
loadSence();
|
loadSence();
|
||||||
});
|
});
|
||||||
let objArr = [];
|
|
||||||
let objM = [];
|
|
||||||
// 建筑树点击
|
// 建筑树点击
|
||||||
Bus.on('clickBuild', (isParent) => {
|
Bus.on('clickBuild', (isParent) => {
|
||||||
// Todo
|
// Todo
|
||||||
console.log('clickBuild', isParent);
|
console.log('clickBuild', isParent);
|
||||||
if (!isParent) {// 点击子级
|
if (!isParent) {// 点击子级
|
||||||
var clickName = bimStore().activateTree.clickName;
|
var clickName = bimStore().activateTree.clickName;
|
||||||
cleanColor();
|
console.log(123, clickName);
|
||||||
|
// 恢复之前被选中模型的材质
|
||||||
|
if (selectedObject && selectedMaterial) {
|
||||||
|
selectedObject.material = selectedMaterial;
|
||||||
|
selectedObject = null;
|
||||||
|
selectedMaterial = null;
|
||||||
|
}
|
||||||
var Floor = gltfObj.value.scene.getObjectByName(clickName);
|
var Floor = gltfObj.value.scene.getObjectByName(clickName);
|
||||||
|
if (Floor.length > 0) {
|
||||||
|
// 储存被选中的模型和材质
|
||||||
|
selectedObject = Floor;
|
||||||
|
selectedMaterial = selectedObject.material;
|
||||||
|
}
|
||||||
|
console.log(1, Floor);
|
||||||
Floor.traverse(e => {
|
Floor.traverse(e => {
|
||||||
e.material = new THREE.MeshLambertMaterial({
|
e.material = new THREE.MeshLambertMaterial({
|
||||||
color: 0x00ff00,
|
color: 0x00ff00,
|
||||||
});
|
});
|
||||||
|
nearCamera(e);
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -97,29 +107,12 @@ onMounted(() => {
|
||||||
renderScene();
|
renderScene();
|
||||||
document.addEventListener("click", onMouseDown);
|
document.addEventListener("click", onMouseDown);
|
||||||
});
|
});
|
||||||
|
|
||||||
const cleanColor = () => {
|
|
||||||
|
|
||||||
// 恢复之前被选中模型的材质
|
|
||||||
if (objArr.length > 0 && objM.length > 0) {
|
|
||||||
objArr.forEach((ele, index) => {
|
|
||||||
console.log(objM[index]);
|
|
||||||
ele.material = objM[index]
|
|
||||||
})
|
|
||||||
objArr = [];
|
|
||||||
objM = [];
|
|
||||||
}
|
|
||||||
gltfObj.value.scene.traverse(e => {
|
|
||||||
objArr.push(e);
|
|
||||||
objM.push(e.material);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
scene = new THREE.Scene("#00ffff");
|
scene = new THREE.Scene("#00ffff");
|
||||||
const texture = new THREE.TextureLoader().load(homeIcon);
|
// const texture = new THREE.TextureLoader().load(homeIcon);
|
||||||
texture.mapping = THREE.EquirectangularReflectionMapping;
|
// texture.mapping = THREE.EquirectangularReflectionMapping;
|
||||||
scene.background = texture
|
// scene.background = texture
|
||||||
scene.environment = texture
|
// scene.environment = texture
|
||||||
|
|
||||||
const canvas = document.querySelector("#three");
|
const canvas = document.querySelector("#three");
|
||||||
var cubeLoader = new THREE.CubeTextureLoader();
|
var cubeLoader = new THREE.CubeTextureLoader();
|
||||||
|
@ -134,6 +127,11 @@ const init = () => {
|
||||||
// 将摄像机对准场景的中心
|
// 将摄像机对准场景的中心
|
||||||
camera.position.set(-192.936, 180.990, -28.179);
|
camera.position.set(-192.936, 180.990, -28.179);
|
||||||
camera.lookAt(scene.position);
|
camera.lookAt(scene.position);
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
=======
|
||||||
|
|
||||||
|
>>>>>>> c61eb163e061fb935e88a57641d1dc70e363d7b5
|
||||||
// 创建控件对象
|
// 创建控件对象
|
||||||
orbit = new OrbitControls(camera, renderer.domElement);
|
orbit = new OrbitControls(camera, renderer.domElement);
|
||||||
orbit.autoRotate = true;
|
orbit.autoRotate = true;
|
||||||
|
@ -209,12 +207,17 @@ let selectedObject = null;
|
||||||
let selectedMaterial = null;
|
let selectedMaterial = null;
|
||||||
|
|
||||||
const onMouseDown = (event) => {
|
const onMouseDown = (event) => {
|
||||||
|
var raycaster = new THREE.Raycaster()
|
||||||
|
// 恢复之前被选中模型的材质
|
||||||
|
if (selectedObject && selectedMaterial) {
|
||||||
|
selectedObject.material = selectedMaterial;
|
||||||
|
selectedObject = null;
|
||||||
|
selectedMaterial = null;
|
||||||
|
}
|
||||||
// 计算鼠标点击位置的归一化设备坐标
|
// 计算鼠标点击位置的归一化设备坐标
|
||||||
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||||
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||||
|
|
||||||
var raycaster = new THREE.Raycaster()
|
|
||||||
cleanColor();
|
|
||||||
// 更新射线的起点和方向
|
// 更新射线的起点和方向
|
||||||
raycaster.setFromCamera(mouse, camera);
|
raycaster.setFromCamera(mouse, camera);
|
||||||
// 计算射线和场景中所有可点击物体的相交情况
|
// 计算射线和场景中所有可点击物体的相交情况
|
||||||
|
@ -224,6 +227,7 @@ const onMouseDown = (event) => {
|
||||||
const clickedObject = intersects[0].object;
|
const clickedObject = intersects[0].object;
|
||||||
// 储存被选中的模型和材质
|
// 储存被选中的模型和材质
|
||||||
selectedObject = clickedObject;
|
selectedObject = clickedObject;
|
||||||
|
selectedMaterial = clickedObject.material;
|
||||||
// 修改材质为绿色
|
// 修改材质为绿色
|
||||||
selectedObject.material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
selectedObject.material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
||||||
nearCamera(intersects);
|
nearCamera(intersects);
|
||||||
|
@ -232,32 +236,30 @@ const onMouseDown = (event) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const nearCamera = (intersects) => {
|
const nearCamera = (intersects) => {
|
||||||
console.log(5555, intersects)
|
// 拉近场景
|
||||||
// 拉近场景
|
if (!intersects[0]) {
|
||||||
if (!intersects[0]) {
|
return;
|
||||||
return;
|
} else {
|
||||||
} else {
|
if (intersects[0].object.name) {
|
||||||
if (intersects[0].object.name) {
|
selectedObjects = [];
|
||||||
selectedObjects = [];
|
selectedObjects.push(intersects[0].object);
|
||||||
selectedObjects.push(intersects[0].object);
|
positionObj = {
|
||||||
positionObj = {
|
x: intersects[0].object.position.x,
|
||||||
x: intersects[0].object.position.x,
|
y: intersects[0].object.position.y,
|
||||||
y: intersects[0].object.position.y,
|
z: intersects[0].object.position.z,
|
||||||
z: intersects[0].object.position.z,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
initTween(
|
initTween(
|
||||||
positionObj.x,
|
positionObj.x,
|
||||||
positionObj.y,
|
positionObj.y,
|
||||||
positionObj.z + 10
|
positionObj.z+10
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const toHomeView = () => {
|
const toHomeView = () => {
|
||||||
camera.position.set(-192.936, 180.990, -28.179);
|
camera.position.set(-192.936, 180.990, -28.179);
|
||||||
camera.lookAt(scene.position);
|
camera.lookAt(scene.position);
|
||||||
cleanColor();
|
|
||||||
}
|
}
|
||||||
// 返回主页
|
// 返回主页
|
||||||
const toHomeView1 = () => {
|
const toHomeView1 = () => {
|
||||||
|
|
Loading…
Reference in New Issue