<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      vue3+3d-force-graph渲染glb模型

      準備工作:

      1.找好要渲染的glb/gltf模型

      2.安裝three.js

      3.安裝3d-force-graph

      4.準備圖譜數據

      開始操作

      1、聲明一個div標簽 通過ref獲取此div元素

       <div class="force_style" ref="graphRef"></div>

      2、定義初始化圖譜方法(initGraph )

      將準備好的glb加載進來

      const loadGLBModel = async (url: string) => {
        if (modelCache.has(url)) return modelCache.get(url).clone()
      
        const loader = new GLTFLoader()
        return new Promise<THREE.Object3D>((resolve, reject) => {
          loader.load(
              url,
              gltf => {
                const model = gltf.scene
                model.traverse(child => {
                  if (child instanceof THREE.Mesh) {
                    child.castShadow = true
                    child.receiveShadow = true
                  }
                })
                modelCache.set(url, model.clone())
                resolve(model)
              },
              undefined,
              reject
          )
        })
      }

      定義力導向圖譜

       graphInstance = ForceGraph3D()(graphRef.value)

      加載圖譜數據

      graphInstance .graphData({
              nodes: nodes,
              links: links
            })

      將默認節點替換為模型

      graphInstance .nodeThreeObject(({ model }) => {
      if (!model) return new THREE.Mesh() // 默認節點
              // 克隆緩存的模型
              const modelClone = modelCache.get('/models/MaiRealhot.glb').clone()
              modelClone.scale.set(10, 10, 10) // 調整模型大小
              return modelClone
            })

      效果圖

      完整代碼: 

      <template>
        <div class="force_style" ref="graphRef"></div>
      </template>
      
      <script setup lang="ts">
      import { onMounted, ref, onUnmounted } from 'vue' import ForceGraph3D from '3d-force-graph' import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader' import * as THREE from 'three' import {nodes, links} from '@/assets/graphData/miserables.json' import SpriteText from "three-spritetext"; const graphRef = ref<HTMLElement | null>(null) let graphInstance: any = null const modelCache = new Map() // 模型緩存 // 加載 GLB 模型 const loadGLBModel = async (url: string) => { if (modelCache.has(url)) return modelCache.get(url).clone() const loader = new GLTFLoader() return new Promise<THREE.Object3D>((resolve, reject) => { loader.load( url, gltf => { const model = gltf.scene model.traverse(child => { if (child instanceof THREE.Mesh) { child.castShadow = true child.receiveShadow = true } }) modelCache.set(url, model.clone()) resolve(model) }, undefined, reject ) }) } // 初始化圖表 const initGraph = async () => { if (!graphRef.value) return // 加載示例模型(替換為你的實際模型路徑) const model = await loadGLBModel('/models/MaiRealhot.glb') graphInstance = ForceGraph3D()(graphRef.value) .graphData({ nodes: nodes, links: links }) .nodeThreeObject(({ model }) => { if (!model) return new THREE.Mesh() // 默認節點 // 克隆緩存的模型 const modelClone = modelCache.get('/models/MaiRealhot.glb').clone() modelClone.scale.set(10, 10, 10) // 調整模型大小 return modelClone }) .nodeColor(() => '#ffffff') .nodeLabel((node) => { return node.id }) .nodeOpacity(0.8) .linkColor(() => 'rgba(255,255,255,0.2)') .linkWidth(0.5) .onNodeClick(node => { handleNodeClick(node) }) .cameraPosition({ z: 1000 }) // 添加環境光 const ambientLight = new THREE.AmbientLight(0xffffff, 0.8) graphInstance.scene().add(ambientLight) // 添加點光源 const pointLight = new THREE.PointLight(0xffffff, 1, 1000) pointLight.position.set(500, 500, 500) graphInstance.scene().add(pointLight) } // 節點點擊處理 const handleNodeClick = (node: any) => { const distance = 100 const distRatio = 1 + distance / Math.hypot(node.x, node.y, node.z) graphInstance.cameraPosition( { x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio }, node, 3000 ) } onMounted(async () => { await initGraph() }) onUnmounted(() => { if (graphInstance) { graphInstance._destructor() modelCache.clear() } }) </script> <style scoped lang="scss">.force_style { width: 100%; height: 100vh; background: #1a1a1a; overflow: hidden; } </style>

       

      posted @ 2025-04-03 15:27  小楊同學906  閱讀(73)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 日本深夜福利在线观看| 国产精品久久久久7777| 少妇被无套内谢免费看| 欧美xxxxhd高清| 蜜臀av久久国产午夜| 强奷漂亮人妻系列老师| 国产一区在线播放av| 国产免费午夜福利蜜芽无码| 国产精品一线天粉嫩av| 欧美牲交a欧美牲交aⅴ图片| 国产麻花豆剧传媒精品mv在线 | 白嫩日本少妇做爰| 欧美人与zoxxxx另类| 十八禁国产精品一区二区| 国产一区二区三区不卡视频| 忘忧草在线社区www中国中文 | 亚洲人成人影院在线观看| 中文字幕制服国产精品| 在线精品国产中文字幕| 沙雅县| 国产线播放免费人成视频播放 | 亚洲AV高清一区二区三区尤物| 最新日韩精品视频在线| 99久久精品久久久久久婷婷| 精品国产亚洲一区二区三区| 精品福利一区二区三区免费视频| 男女啪啪高清无遮挡免费| 天堂mv在线mv免费mv香蕉| 噶尔县| 精品亚洲国产成人| 欧美xxxxhd高清| 一个色的导航| 扒开粉嫩的小缝隙喷白浆视频| 最新中文字幕国产精品| 亚洲色大成网站www久久九九| Y111111国产精品久久久| 国语精品一区二区三区| 亚洲一区二区偷拍精品| 激情综合网一区二区三区| 成人午夜免费无码视频在线观看 | 亚洲综合中文字幕第一页|