Hello, I have an Object and a texture that come from an API to apply to my object. I’m using ObjectLoader to load the JSON object and everything works just fine.
Otherwise, to load the JSON texture/material, I’m using MaterialLoader and it gives a warning saying:
THREE.MaterialLoader: Undefined texture E0C0F117-56BD-4B63-983A-081E086FA617
This is the JSON file with the texture: https://jsonblob.com/4af185bb-aaa8-11e8-9316-331e2397d779
And I’ll leave my code here too:
import React from 'react';
const THREE = require('three');
const OrbitControls = require("three-orbit-controls")(require("three"));
const url = 'myUrlAPI';
export class ThreeScene extends React.Component {
constructor(props) {
super(props);
this.rootRef = React.createRef();
}
componentDidMount() {
const { width, height, json, texture } = this.props;
//CREATE SCENE
var scene = new THREE.Scene();
//CAMERA
var camera = new THREE.OrthographicCamera(window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 1, 2000);
camera.position.set(0, 10, 200);
scene.add(camera);
//LIGHTS
var light = new THREE.HemisphereLight(0xffffbb, 0x080820, 1);
scene.add(light);
//RENDERER
var renderer = new THREE.WebGLRenderer({
alpha: true
});
renderer.setSize(width, height);
renderer.setClearColor(0x000000, 0);
this.rootRef.current.appendChild(renderer.domElement);
//OBJECT LOADER
var loader = new THREE.ObjectLoader();
loader.load(url + json, verLoad);
function verLoad(obj) {
obj.position.z = -10;
scene.add(obj);
obj.scale.set = (2, 1, 1);
//TEXTURE
var textureLoader = new THREE.MaterialLoader();
textureLoader.load(
url + texture, function (material) {
obj.material = material;
}
);
}
//CONTROLS
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableZoom = true;
controls.maxDistance = 500;
controls.minDistance = 100;
controls.maxPolarAngle = Math.PI / 2;
//ANIMATION
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
controls.update();
}
animate();
}
render() {
return (
<div ref={this.rootRef} id="ImagemSofa"></div>
)
}
}
Object json file: jsonObject.zip (3.5 MB)
Texture json file: jsonTexture.txt (3.5 MB)