Hi ,
I am rendering a 3D model using MTL/OBJ loader. But Model appearence is not so good as compared to sketchfab. I have uploaded same 3d model in sketchfab but there after rendering 3D model looks quite smooth and good but same is not happening in my case. Please refer below screenshots of 3d model for both cases i have mentioned above and the code snippet.
My Model:
Sketchfab Model:
Code Snippet:
this.container = document.getElementById("threedViewer");
this.rendererW = this.container.offsetWidth;
this.rendererH = 680;
/* Scene */
this.scene = new THREE.Scene();
/* Camera */
this.camera = new THREE.PerspectiveCamera(70, this.rendererW / this.rendererH, 0.1, 7000);
this.camera.up.set(0, 0, 1);
this.camera.position.set(-5, -1500, -130);
this.scene.add(this.camera);
//Ambient LIGHTING
this.ambient = new THREE.AmbientLight(0x404040);
this.scene.add(this.ambient);
//Hemisphere LIGHTING
this.hemiLight = new THREE.HemisphereLight(new THREE.Color('hsl(0, 0%, 10%)'), new THREE.Color('hsl(0, 0%, 50%)'), .1);
this.hemiLight.intensity = 150;
this.scene.add(this.hemiLight);
var manager = new THREE.LoadingManager();
manager.onStart = function (item, loaded, total) {
console.log('Loading started');
};
manager.onLoad = function () {
console.log('Loading complete');
scope.get3DAnnotations(scope.missionId);
bar.destroy();
};
manager.onProgress = function (item, loaded, total) {
console.log(item, loaded, total);
console.log('Loaded:', Math.round(loaded / total * 100, 2) + '%')
bar.animate(loaded / total);
};
manager.onError = function (url) {
console.log('Error loading');
};
//3D MTL & Object Loading
var mtlLoader = new MTLLoader(manager);
var mtl = this.missionUploads.find(this.findUpload.bind(this, 'MTL'));
var objfile = this.missionUploads.find(this.findUpload.bind(this, 'OBJ'));
mtlLoader.setPath('media/' + this.missionId + '/3D/Mesh OBJ/');
mtlLoader.load(mtl.FileName, function(materials) {
materials.preload();
materials.materials.texture.map.magFilter = THREE.NearestFilter;
materials.materials.texture.map.minFilter = THREE.LinearFilter;
//var manager = new THREE.LoadingManager();
OBJLoader(THREE);
var objLoader = new THREE.OBJLoader(manager);
objLoader.setMaterials(materials);
objLoader.setPath('media/' + scope.missionId + '/3D/Mesh OBJ/');
objLoader.load(objfile.FileName, function (object) {
object.traverse(function(child) {
if (child instanceof THREE.Mesh) {
scope.objects.push(child);
}
});
object.up.set(0, 0, 1);
scope.scene.add(object);
console.log('Object::', object);
});
});
this.raycaster = new THREE.Raycaster();
this.mouse = new THREE.Vector2();
/* Renderer */
this.renderer = new THREE.WebGLRenderer();
this.renderer.physicallyCorrectLights = true;
this.renderer.gammaInput = true;
this.renderer.gammaOutput = true;
this.renderer.shadowMap.enabled = true;
this.renderer.toneMapping = THREE.ReinhardToneMapping;
this.renderer.setPixelRatio(window.devicePixelRatio);
this.renderer.setSize(this.rendererW, this.rendererH);
this.renderer.setClearColor(scope.threedSettings.renderer.background);
this.container.appendChild(this.renderer.domElement);
/* Controls */
this.controls = new OrbitControls(this.camera, this.renderer.domElement);
this.controls.enableDamping = true;
this.controls.dampingFactor = 0.25;
this.controls.enableZoom = true;
//this.get3DAnnotations(scope.missionId);
/* Events */
var self = this;
document.addEventListener('dblclick', function() { scope.onDocumentMouseDown(event, self); }, false);
document.addEventListener('resize', this.onWindowResize, false);
this.container.addEventListener('click', function() { scope.showAnnotationDetails(event, self); }, false);
}
animate() {
requestAnimationFrame(this.animate.bind(this));
this.controls.update();
this.render();
}
render() {
this.renderer.toneMappingExposure = Math.pow(.68, 5.0); // to allow for very bright scenes.
this.renderer.shadowMap.enabled = true;
this.renderer.render(this.scene, this.camera);
}
Other Issue is, in sketchfab model, its inner side is filled which gives this a 3D look but in my case, my model inner area is transparent if you look inside. Please refer below screenshot for this case.
My Model:
sketchfab Model:
Please Help.
Thanks
Avinash