this is the first time I write on stackoverflow ...a couple of days I'm trying to use the javascript library Three.js (actually version n° r99), I correctly entered the 3D model but when I see it loaded is seen from behind and not centered on the viewport, how can I fix it?
The code is this:
<script>
var scene = new THREE.scene();
var camera = new THREE.PerspectiveCamera ( 50, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.z = 15;
var render = new THREE.WebGLRenderer();
renderer.setSize ( window.InnerWidth, window.InnerHeight );
document.body.appendChild (renderer.domElement);
window.addEventListener('resize', function(){
var width = window.innerWidth;
var height = window.innerHeight;
renderer.setSize( width, height );
camera.aspect = width / height;
camera.updateProjectMatrix();
});
controls = new THREE.OrbitControls ( camera, renderer.domElement );
var loader = new THREE.ObjectLoader();
loader.load("/models/teschio.json",function (obj)
{
scene.add( obj );
});
var animate = function (){
requestAnimateFrame ( animate );
renderer.render (scene, camera);
}
animate();
</script>
and this is a wireframe screen currently: actual wireframe
thanks in advance for any answers.
Something like this:
var loader = new THREE.ObjectLoader();
loader.load("/models/teschio.json",function (obj)
{
var box = new THREE.Box3().setFromObject( obj );
var center = new THREE.Vector3();
box.getCenter( center );
obj.position.sub( center ); // center the model
obj.rotation.y = Math.PI; // rotate the model
scene.add( obj );
});