1 如果出现错误 "THREE.WebGLRenderer: Error creating WebGL context.

        需要开启浏览器的gpu加速(GPU-acceleration);地址栏输入:chrome://flags/#ignore-gpu-blacklist,将GPU-acceleration设置可用

 2 出现错误:Uncaught Error: THREE.OBJLoader: Unexpected line: "<!DOCTYPE html>"

 该错误出现在vue脚手架项目中,使用objloader加载obj模型路径时候,错误路径如下:

let path="/statics/models/obj/IronMan/";

 正确方式:

const assetsUrl = process.env.BASE_URL + process.env.VUE_APP_ASSETS;
const path=assetsUrl+"/models/obj/IronMan/";

3 出现解析失败错误:

解析失败 TypeError: Class constructor Loader cannot be invoked without 'new'

出现该问题,是加载器引入不正确,用以下方式解决

import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
import { OBJLoader, MTLLoader } from 'three-obj-mtl-loader'
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";

Logo

前往低代码交流专区

更多推荐