Vue+Three.js 渲染模型glb/gltf

引入模型的方法都大差不差的,这里以gltf模型为例。

import * as THREE from 'three';
import {GLTFLoader} from "three/examples/jsm/loaders/GLTFLoader.js"; // 根据需要自行选择模型加载器,glb/gltf使用GLTFLoader
import {OBJLoader} from "three/examples/jsm/loaders/OBJLoader.js"; // obj模型使用这个
// 1.创建场景
function createScene(){
    const loader = new GLTFLoader();
    const scene = new THREE.Scene();
    
    const axesHelper = new THREE.AxesHelper(5); // 坐标轴辅助线

    const gridHelper = new THREE.GridHelper(1000) // 地面网格辅助线
    // X轴红色,Y轴绿色,Z轴蓝色
    scene.add(axesHelper);
    scene.add(gridHelper);

    const group = new THREE.Group();
    const modelPaths = ["public/model/lada_largus/scene.gltf","public/model/lada_largus/scene.gltf","public/model/lada_largus/scene.gltf"]
    modelPaths.forEach(function (path,index) {
        loader.load(path, function(gltf) {
            const model = gltf.scene;
            // 设置不同的位置
            switch (index) {
                case 0:
                    model.position.set(0, 10, -30); // 第一个模型位置
                    break;
                case 1:
                    model.position.set(0, 10, 0); // 第二个模型位置
                    break;
                case 2:
                    model.position.set(0, 10, 30); // 第三个模型位置
                    break;
            }
                    scene.add(model);
            }, undefined, function(error) {
                console.error(error);
            });
    })
    group.add(scene)
    // group.children[group.children.length].visible = false


    return group;
}

export default createScene;

效果图:

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值