Hello,
I’m trying to use the sample made here: three.js examples (threejs.org)
It doen’t work and the error (from the console) is: “Impossible to import json map”.
I didn’t installed three-gpu via npm but I want to import map or… please help me!
my code is:
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);
const camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 1;
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
renderer.toneMapping = THREE.LinearToneMapping;
renderer.toneMappingExposure = 0.5; // influenza molto la resa
document.body.appendChild(renderer.domElement);
const params = {
enable: true,
toneMapping: true,
pause: false,
tiles: 3,
transparentBackground: false,
resolutionScale: 1,
download: () => {
const link = document.createElement( 'a' );
link.download = 'pathtraced-render.png';
link.href = renderer.domElement.toDataURL().replace( 'image/png', 'image/octet-stream' );
link.click();
},
roughness: 0.15,
metalness: 0.9,
};
const controls = new OrbitControls(camera, renderer.domElement);
var light = new THREE.DirectionalLight(0xffffff, 1); // colore + intensità (ora a 5, dafault è 1)
light.position.set(0, 10, 5);
let mapSize = 1024;
light.shadow.mapSize.width = mapSize;
light.shadow.mapSize.height = mapSize;
scene.add(light);
new RGBELoader().load('https://modelviewer.dev/shared-assets/environments/neutral.hdr', function (texture) {
texture.mapping = THREE.EquirectangularReflectionMapping;
texture.encoding = THREE.RGBEEncoding;
scene.environment = texture;
});
let model;
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('./draco/');
dracoLoader.setDecoderConfig({ type: 'js' });
const loader = new GLTFLoader();
loader.setDRACOLoader(dracoLoader);
loader.load(
'./model/Digityze - T-Shirt/Digityze - T-Shirt.gltf',
function (gltf) {
model = gltf.scene;
model.position.set(0, 0, 0);
model.traverse(function (child) {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
child.material.shadowIntensity = 1;
child.material.originalMap = child.material.map;
}
});
const bbox = new THREE.Box3().setFromObject(model);
const objectSize = new THREE.Vector3();
bbox.getSize(objectSize);
const center = bbox.getCenter(new THREE.Vector3());
// Imposta la posizione della fotocamera in modo che l'oggetto sia centrato
camera.position.set(center.x, center.y, center.z + 1);
// Imposta la posizione dell'oggetto al centro della scena
model.position.set(-center.x, -center.y, -center.z);
scene.add(model);
},
undefined,
function (error) {
console.error(error);
}
);
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
animate();
window.addEventListener('resize', () => {
const newWidth = window.innerWidth;
const newHeight = window.innerHeight;
camera.aspect = newWidth / newHeight;
camera.updateProjectionMatrix();
renderer.setSize(newWidth, newHeight);
});
and I want just to create a switcher in order to switch between webgl renderer mode and pathtracer…