Answer the question
In order to leave comments, you need to log in
Variable scope?
Hello everyone, tell me how you can use it further in the code, namely in switche and beyond
var _loaders = {};
_loaders.loadCurrentObject = function (a) {
_loaders.object = a;
console.log(a);
function init() {
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 50000);
scene.add(camera);
var webGLRenderer = new THREE.WebGLRenderer();
webGLRenderer.setClearColor(new THREE.Color(0xffffff, 1.0));
webGLRenderer.setSize(window.innerWidth, window.innerHeight);
webGLRenderer.shadowMapEnabled = true;
camera.position.x = 5;
camera.position.y = 5;
camera.position.z = 5;
camera.lookAt(scene.position);
scene.add(camera);
var orbitControls = new THREE.OrbitControls(camera);
orbitControls.autoRotate = true;
var clock = new THREE.Clock();
var directionalLight = new THREE.DirectionalLight(0xffeedd);
directionalLight.position.set(100, 100, 150);
camera.add(directionalLight);
document.getElementById("WebGL-output").appendChild(webGLRenderer.domElement);
var step = 0;
var mesh;
switch (a.extension) {
case 'obj':
if (a.texture != "http://placehold.it/200x200") {
_loaders.loader = new THREE.OBJMTLLoader();
_loaders.loadObjMtl(_loaders.object);
} else {
_loaders.loader = new THREE.OBJLoader();
_loaders.loadObj(_loaders.object);
}
break;
case 'stl':
_loaders.loader = new THREE.STLLoader();
_loaders.loadStl(_loaders.object);
break;
}
_loaders.loadObj = function (a) {
_loaders.loader.load('/files/uploads/objects/'+ a.id + '/' + a.url, function (loadedMesh) {
loadedMesh.children.forEach(function (child) {
child.material = material;
child.geometry.computeFaceNormals();
child.geometry.computeVertexNormals();
});
mesh = loadedMesh;
loadedMesh.scale.set.x = 45;
loadedMesh.scale.set.y = 45;
loadedMesh.scale.set.z = 45;
loadedMesh.rotation.x = -0.3;
scene.add(loadedMesh);
});
};
render();
function render() {
var delta = clock.getDelta();
orbitControls.update(delta);
requestAnimationFrame(render);
webGLRenderer.render(scene, camera);
}
}
window.onload = init;
};
Answer the question
In order to leave comments, you need to log in
There was such a problem. It is necessary to pass directly in when declaring , and init(a)
also pass before the call . Change the structure of the code a little. init() should preferably be declared asа
init()
init()
var init = function(a) {};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question