The first use of three.js to load the obj model was unsuccessful

Follow this, https://blog.csdn.net/bcbobo21cn/article/details/110676331

The basic code is as follows;

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>第一个three.js 示例</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
    }
  </style>
  <script src="three.js-master/build/three.js"></script>
  <script src="three.js-master/build/three.module.js"></script>
  <script src="three.js-master/examples/js/loaders/OBJLoader.js"></script>
</head>

<body>
  <script>

    var scene = new THREE.Scene();


    var loader = new OBJLoader();

            loader.load( './3d/worker.obj', function ( obj ) {
                let object = obj;
                
                object.scale.set(3,3,3);
                object.children[0].material.color.set(0xe8b73b);
                object.rotation.x = 1;
                object.rotation.y = 0.3;
                scene.add(object);
            });

            var light = new THREE.DirectionalLight(0xffffff);//光源颜色
            light.position.set(20, 10, 1305);//光源位置
            scene.add(light);//光源添加到场景中

  </script>
</body>
</html>

    According to relevant information, include 3 js files in the code; then define a loader to load the model;

But unsuccessful

The loader class was not found; look at the loader class should be included in OBJLoader.js;

three.js uses different loaders to load 3D models in different formats;

 

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/113856189