R
R
ruzaev20192021-09-11 15:21:15
three.js
ruzaev2019, 2021-09-11 15:21:15

Why is three.js not loading vox format?

We need to load the model from magica-voxel, (vox format), using webpack 5. THREE.JS is included locally. Writes:
613c9dbb46bf7713855487.png, the same thing happens with gltf. I need a voxel graphics loader for webpack. host takes files from the dist/build folder. But I did not find such a loader.
threejs file:

import * as THREE from '../build/three.module.js';
import {
  VOXLoader,
  VOXMesh
} from '../examples/jsm/loaders/VOXLoader.js';

// ***** sizes *****
const sizes = {
  width: window.innerWidth,
  height: window.innerHeight
};

// ***** scene, camera, renderer *****
const scene = new THREE.Scene();

const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height);
camera.position.set(-3, 2, 4);

const renderer = new THREE.WebGLRenderer({
  antialias: true
});
renderer.setSize(sizes.width, sizes.height);

document.body.appendChild(renderer.domElement);

// // ***** VOXLoader *****
// const loader = new VOXLoader();
// loader.load('../models/a.vox', (vox) => {
// 	scene.add(vox.scene);
// });

const loader = new VOXLoader();
loader.load('../models/a.vox', function (chunks) {
  for (let i = 0; i < chunks.length; i++) {
    const chunk = chunks[i];
    const mesh = new VOXMesh(chunk);
    mesh.scale.setScalar(0.0015);
    scene.add(mesh);

  }
});

// ***** resize screen and camera *****
window.addEventListener('resize', () => {
  camera.aspect = sizes.width / sizes.height;
  camera.updateProjectionMatrix();

  renderer.setSize(sizes.width, sizes.height);
});

// ***** render function *****
const animate = () => {
  requestAnimationFrame(animate);
  renderer.render(scene, camera);
};

animate();

folder structure:
613c9f34e621c990079750.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
My joy, 2021-10-12
@t-alexashka

Well it is obvious that a problem with ways. try to open the vox model in the browser along the paths. where exactly is it located after assembly? can it be transferred to dist?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question