J
J
Jacon2020-12-19 17:28:02
JavaScript
Jacon, 2020-12-19 17:28:02

Can't create 3D model (ThreeJS). Where is the mistake?

A beginner in JS tried to create a 3d model, it didn’t work, here is the code:

<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r123/three.min.js"></script>
    <script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/loaders/GLTFLoader.js"></script>
    
    <script language="JavaScript">
    scene = new THREE.Scene();
    camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
    camera.position.z = 10;
    
    renderer = new THREE.WebGLRenderer({alpha: true, antialias: true});
    renderer.setClearColor(0x000000, 0);
    renderer.setSize(1280, 720);
    
    renderer.domElement.setAttribute("id", "Minecraft3DObj" );
    document.head.insertBefore(renderer.domElement, document.head.firstChild);
    
    const aLight = new THREE.AmbientLight(0x404040, 1.2);
    scene.add(aLight);
        
    const pLight = new THREE.PointLight(0xFFFFFF, 1.2);
    pLight.position.set(0, -3, 7);
    scene.add(pLight);
    
    //const helper = new THREE.PointLightHelper(pLight)
    //scene.add(helper);
    
    let loader = new THREE.GLTFLoader();
    let obj = null;
        
        loader.load('C://Users/yakov/Downloads/minecraft_-_pig/scene.gltf', function(gltf) {
        obj = gltf;
        obf.scene.scale.set(1.3, 1.3, 1.3);
        
        scene.add(obj.scene);
        });
    </script>
</head>
</html>

the file with the 3d model is ok, I checked
the path to the file with the model
C://Users/yakov/Downloads/minecraft_-_pig/scene.gltf

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2020-12-24
@Jacon

Give the browser permission to read local files.

"path_chrome_dir\chrome.exe" --allow-file-access-from-files

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question