ThreeJS渲染Glb模型
sonder 大杯

最近做了一个小程序,需要渲染 GlB 模型的文件,所以记录一下,开发的过程

three-platformize

由于小程序中不支持 document 的操作,所以不能直接使用 ThreeJS 来渲染 3D 模型, three-platformize 目前已适配微信,淘宝,字节小程序.

地址: https://github.com/deepkolos/three-platformize

如何使用

安装依赖库

1
npm  install three-platformize

引入相关函数

1
2
3
4
5
6
7
8
9
10
import * as THREE from 'three-platformize';
import {
WechatPlatform
} from 'three-platformize/src/WechatPlatform';
import {
GLTFLoader
} from 'three-platformize/examples/jsm/loaders/GLTFLoader';
import {
OrbitControls
} from 'three-platformize/examples/jsm/controls/OrbitControls';

渲染模型

1
2
3
4
5
6
7
const loader = new GLTFLoader();
loader.load(this.baseUrl, (gltf) => {
this.model = gltf.scene;
}, undefined,
function(e) {
console.error(e);
});

以上是示例代码,如果你需要源码可以到插件:Three-Glb查看示例。

目前正在开发FBXLoader渲染.fbx模型相关的功能,敬请期待。

  • 本文标题:ThreeJS渲染Glb模型
  • 本文作者:sonder
  • 创建时间:2023-09-15 13:20:26
  • 本文链接:https://sonderss.github.io/2023/09/15/ThreeJS渲染Glb模型/
 评论