troisjs demo

main
wangqiujuan0808 2023-12-01 23:25:09 +08:00
parent 6b3eb0dca9
commit 0730aae140
7 changed files with 125 additions and 81 deletions

View File

@ -19,6 +19,7 @@
"@vueup/vue-quill": "1.2.0", "@vueup/vue-quill": "1.2.0",
"@vueuse/core": "9.5.0", "@vueuse/core": "9.5.0",
"axios": "0.27.2", "axios": "0.27.2",
"dayjs": "^1.11.10",
"echarts": "5.4.0", "echarts": "5.4.0",
"element-plus": "2.2.27", "element-plus": "2.2.27",
"file-saver": "2.0.5", "file-saver": "2.0.5",
@ -27,11 +28,11 @@
"jsencrypt": "3.3.1", "jsencrypt": "3.3.1",
"nprogress": "0.2.0", "nprogress": "0.2.0",
"pinia": "2.0.22", "pinia": "2.0.22",
"three": "^0.148.0", "three": "^0.134.0",
"troisjs": "^0.3.4",
"vue": "3.2.45", "vue": "3.2.45",
"vue-cropper": "1.0.3", "vue-cropper": "1.0.3",
"vue-router": "4.1.4", "vue-router": "4.1.4"
"dayjs": "^1.11.10"
}, },
"devDependencies": { "devDependencies": {
"@vitejs/plugin-vue": "3.1.0", "@vitejs/plugin-vue": "3.1.0",

View File

@ -42,6 +42,9 @@ import ImagePreview from "@/components/ImagePreview"
import TreeSelect from '@/components/TreeSelect' import TreeSelect from '@/components/TreeSelect'
// 字典标签组件 // 字典标签组件
import DictTag from '@/components/DictTag' import DictTag from '@/components/DictTag'
// troisjs
import { TroisJSVuePlugin } from 'troisjs';
const app = createApp(App) const app = createApp(App)
@ -65,6 +68,7 @@ app.component('ImagePreview', ImagePreview)
app.component('RightToolbar', RightToolbar) app.component('RightToolbar', RightToolbar)
app.component('Editor', Editor) app.component('Editor', Editor)
app.use(TroisJSVuePlugin)
app.use(router) app.use(router)
app.use(store) app.use(store)
app.use(plugins) app.use(plugins)

View File

@ -62,6 +62,7 @@ export const constantRoutes = [{
path: '', path: '',
component: LayoutMain, component: LayoutMain,
redirect: '/index', redirect: '/index',
hidden: true,
children: [{ children: [{
path: '/index', path: '/index',
component: () => import('@/views/index'), component: () => import('@/views/index'),

View File

@ -1,90 +1,32 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<canvas id="three"></canvas> <div id="three">
<Renderer ref="renderer" antialias :orbit-ctrl="{ enableDamping: true }" resize>
<Camera :position="{ x: 100, y: 80, z: -150 }" />
<Scene background="#353535">
<AmbientLight></AmbientLight>
<GltfModel src="/jz/glb/jz.gltf" @load="onReady" @progress="onProgress" @error="onError" />
</Scene>
</Renderer>
</div>
</div> </div>
</template> </template>
<script setup name="bimHome"> <script setup name="bimHome">
import * as THREE from "three";
import { ref, onMounted } from "vue";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
// :
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
import { import {
CSS2DObject, AmbientLight,
CSS2DRenderer, PointLight,
} from "three/examples/jsm/renderers/CSS2DRenderer"; Camera,
let scene = ref(null); GltfModel,
let renderer = ref(null); Renderer,
let camera = ref(null); Scene,
let orbit = ref(null); } from 'troisjs';
let group = ref(null); const renderer = ref(null);
let mouse = new THREE.Vector2();
let raycaster = new THREE.Raycaster();
let labelRenderer = new CSS2DRenderer(); //CSS2DRenderer
onMounted(() => { onMounted(() => {
init(); renderer.value.onBeforeRender(() => {
loadSence(); // box.rotation.x += 0.01;
//
renderScene();
});
const init = () => {
scene = new THREE.Scene();
scene.background = new THREE.Color("#eee");
const canvas = document.querySelector("#three");
var cubeLoader = new THREE.CubeTextureLoader();
// WebGLRenderer使
renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
camera = new THREE.PerspectiveCamera(
55,
window.innerWidth / window.innerHeight,
0.1,
20000
);
//
camera.position.x = 100;
camera.position.y = 80;
camera.position.z = -150;
camera.lookAt(scene.position);
//
orbit = new OrbitControls(camera, renderer.domElement);
orbit.autoRotate = true;
setTimeout(function () {
orbit.autoRotate = false;
}, 7000);
renderer.setClearColor(new THREE.Color("#0e0934"));
renderer.setSize(window.innerWidth, window.innerHeight);
// 0x4444440x888888,threejs
// intensity 0.5
var alight = new THREE.AmbientLight(0xffffff, 0.5);
alight.name = "aLight";
scene.add(alight);
};
const loadSence = () => {
const gltfLoader = new GLTFLoader();
gltfLoader.load("/jz/glb/jz.gltf", (gltf) => {
console.log(1, gltf);
var model = gltf.scene;
scene.add(model);
// emssivematerial.coloremissiveMapmaterial.map
// gltf.scene.traverse(function (child) {
// if (child.isMesh) {
// child.material.emissive = child.material.color;
// child.material.emissiveMap = child.material.map;
// }
// });
}); });
}; });
const renderScene = () => {
orbit.update(); //
// 使requestAnimationFrame
requestAnimationFrame(renderScene);
renderer.render(scene, camera);
// requestAnimationFrame,
labelRenderer.render(scene, camera);
};
</script> </script>
<style lang='scss' scoped> <style lang='scss' scoped>
#three { #three {

View File

@ -0,0 +1,94 @@
<template>
<div class="app-container">
<canvas id="three"></canvas>
</div>
</template>
<script setup name="bimHome">
import * as THREE from "three";
import { ref, onMounted } from "vue";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
// :
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
import {
CSS2DObject,
CSS2DRenderer,
} from "three/examples/jsm/renderers/CSS2DRenderer";
let scene = ref(null);
let renderer = ref(null);
let camera = ref(null);
let orbit = ref(null);
let group = ref(null);
let mouse = new THREE.Vector2();
let raycaster = new THREE.Raycaster();
let labelRenderer = new CSS2DRenderer(); //CSS2DRenderer
onMounted(() => {
init();
loadSence();
//
renderScene();
});
const init = () => {
scene = new THREE.Scene();
scene.background = new THREE.Color("#eee");
const canvas = document.querySelector("#three");
var cubeLoader = new THREE.CubeTextureLoader();
// WebGLRenderer使
renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
camera = new THREE.PerspectiveCamera(
55,
window.innerWidth / window.innerHeight,
0.1,
20000
);
//
camera.position.x = 100;
camera.position.y = 80;
camera.position.z = -150;
camera.lookAt(scene.position);
//
orbit = new OrbitControls(camera, renderer.domElement);
orbit.autoRotate = true;
setTimeout(function () {
orbit.autoRotate = false;
}, 7000);
renderer.setClearColor(new THREE.Color("#0e0934"));
renderer.setSize(window.innerWidth, window.innerHeight);
// 0x4444440x888888,threejs
// intensity 0.5
var alight = new THREE.AmbientLight(0xffffff, 0.5);
alight.name = "aLight";
scene.add(alight);
};
const loadSence = () => {
const gltfLoader = new GLTFLoader();
gltfLoader.load("/jz/glb/jz.gltf", (gltf) => {
console.log(1, gltf);
var model = gltf.scene;
scene.add(model);
// emssivematerial.coloremissiveMapmaterial.map
// gltf.scene.traverse(function (child) {
// if (child.isMesh) {
// child.material.emissive = child.material.color;
// child.material.emissiveMap = child.material.map;
// }
// });
});
};
const renderScene = () => {
orbit.update(); //
// 使requestAnimationFrame
requestAnimationFrame(renderScene);
renderer.render(scene, camera);
// requestAnimationFrame,
labelRenderer.render(scene, camera);
};
</script>
<style lang='scss' scoped>
#three {
height: 900px;
width: 100%;
}
</style>

View File

@ -22,6 +22,8 @@ const sidebarRouters = computed(() =>
return !item.hidden; return !item.hidden;
}) })
); );
console.log(1,sidebarRouters);
const gotoPage = (item) => { const gotoPage = (item) => {
useTagsViewStore().delAllViews(); useTagsViewStore().delAllViews();
localStorage.setItem("CURRENT_MENU", item.path); localStorage.setItem("CURRENT_MENU", item.path);