欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

three.js載入常用類型3D模型的幾種方法

 更新時(shí)間:2024年04月17日 10:28:32   作者:努力的小桑  
通過(guò)Three.js的材質(zhì)和幾何體,我們可以很方便的創(chuàng)建基礎(chǔ)3D模型,下面這篇文章主要給大家介紹了關(guān)于three.js載入常用類型3D模型的幾種方法,需要的朋友可以參考下

three.js 載入 3D 模型的方法有很多種。以下是其中的一些:

1. OBJLoader模型加載器

import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js';

// 創(chuàng)建一個(gè) OBJLoader 的實(shí)例
const loader = new OBJLoader();

// 載入模型文件,參數(shù)url是模型文件的路徑,此處以 "example.obj" 為例
loader.load(
  'example.obj',

  // 加載完成后的回調(diào)函數(shù)
  function (obj) {
    // 當(dāng)模型加載完成后會(huì)調(diào)用該函數(shù)

    // 將模型添加到場(chǎng)景中
    scene.add(obj);
  },

  // 正在加載模型時(shí)的回調(diào)函數(shù)
  function (xhr) {
    // 進(jìn)度條代碼,可以在此編寫(xiě)代碼,傳入 xhr.loaded 和 xhr.total,計(jì)算出加載進(jìn)度
  },

  // 加載出錯(cuò)的回調(diào)函數(shù)
  function (err) {
    console.error('An error happened.');
  }
);

2. GLTFLoader模型加載器

import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';

// 創(chuàng)建一個(gè) GLTFLoader 的實(shí)例
const loader = new GLTFLoader();

// 載入模型文件,參數(shù)url是模型文件的路徑,此處以 "example.gltf" 為例
loader.load(
  'example.gltf',

  // 加載完成后的回調(diào)函數(shù)
  function (gltf) {
    // 當(dāng)模型加載完成后會(huì)調(diào)用該函數(shù)

    // 將模型添加到場(chǎng)景中
    scene.add(gltf.scene);
  },

  // 正在加載模型時(shí)的回調(diào)函數(shù)
  function (xhr) {
    // 進(jìn)度條代碼,可以在此編寫(xiě)代碼,傳入 xhr.loaded 和 xhr.total,計(jì)算出加載進(jìn)度
  },

  // 加載出錯(cuò)的回調(diào)函數(shù)
  function (err) {
    console.error('An error happened.');
  }
);

3. FBXLoader模型加載器

import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';

// 創(chuàng)建一個(gè) FBXLoader 的實(shí)例
const loader = new FBXLoader();

// 載入模型文件,參數(shù)url是模型文件的路徑,此處以 "example.fbx" 為例
loader.load(
  'example.fbx',

  // 加載完成后的回調(diào)函數(shù)
  function (object) {
    // 當(dāng)模型加載完成后會(huì)調(diào)用該函數(shù)

    // 將模型添加到場(chǎng)景中
    scene.add(object);
  },

  // 正在加載模型時(shí)的回調(diào)函數(shù)
  function (xhr) {
    // 進(jìn)度條代碼,可以在此編寫(xiě)代碼,傳入 xhr.loaded 和 xhr.total,計(jì)算出加載進(jìn)度
  },

  // 加載出錯(cuò)的回調(diào)函數(shù)
  function (err) {
    console.error('An error happened.');
  }
);

4. ColladaLoader模型加載器

import { ColladaLoader } from 'three/examples/jsm/loaders/ColladaLoader.js';

// 創(chuàng)建一個(gè) ColladaLoader 的實(shí)例
const loader = new ColladaLoader();

// 載入模型文件,參數(shù)url是模型文件的路徑,此處以 "example.dae" 為例
loader.load(
  'example.dae',

  // 加載完成后的回調(diào)函數(shù)
  function (collada) {
    // 當(dāng)模型加載完成后會(huì)調(diào)用該函數(shù)

    // 將模型添加到場(chǎng)景中
    scene.add(collada.scene);
  },

  // 正在加載模型時(shí)的回調(diào)函數(shù)
  function (xhr) {
    // 進(jìn)度條代碼,可以在此編寫(xiě)代碼,傳入 xhr.loaded 和 xhr.total,計(jì)算出加載進(jìn)度
  },

  // 加載出錯(cuò)的回調(diào)函數(shù)
  function (err) {
    console.error('An error happened.');
  }
);

以上是幾種常用類型的三維模型的加載器及其使用方法,可以根據(jù)需要使用相應(yīng)的模型加載器來(lái)加載模型。

總結(jié)

到此這篇關(guān)于three.js載入常用類型3D模型的幾種方法的文章就介紹到這了,更多相關(guān)three.js載入3D模型內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論