ObjLoader should now support textures correctly

This commit is contained in:
Thomas FORGIONE
2015-06-12 11:07:05 +02:00
parent 99019c217f
commit 453d199c27
7 changed files with 61 additions and 18 deletions

View File

@@ -1,4 +1,8 @@
var ProgressiveLoader = function(path, scene, materialCreator) {
var ProgressiveLoader = function(path, scene, materialCreator, transparentElements) {
if (transparentElements === undefined) {
transparentElements = [];
}
// Create mesh
var obj = new THREE.Object3D();
obj.up = new THREE.Vector3(0,0,1);
@@ -105,16 +109,29 @@ var ProgressiveLoader = function(path, scene, materialCreator) {
var geo = new THREE.Geometry();
geo.vertices = vertices;
geo.faces = faces;
geo.faceVertexUvs = [uvs];
var material;
var material, tmp = currentMaterial;
if (currentMaterial === undefined || currentMaterial === null) {
material = new THREE.MeshLambertMaterial({color: 'red'});
} else {
material = materialCreator.create(currentMaterial);
material = materialCreator.materials[currentMaterial.trim()];
material.side = THREE.DoubleSide;
material.map.wrapS = material.map.wrapT = THREE.RepeatWrapping;
currentMaterial = null;
}
currentMesh = new THREE.Mesh(geo, material);
if (transparentElements.indexOf(tmp.trim()) !== -1) {
THREEx.Transparency.push(currentMesh);
} else {
currentMesh.raycastable = true;
}
}
currentMesh.geometry.computeFaceNormals();
obj.add(currentMesh);
} else if (elts[0] === 'u') {
@@ -129,6 +146,8 @@ var ProgressiveLoader = function(path, scene, materialCreator) {
uvs = [];
// currentMesh.geometry.computeFaceNormals();
if (currentMesh) {
currentMesh.geometry.computeFaceNormals();
currentMesh.geometry.computeBoundingSphere();
currentMesh.geometry.groupsNeedUpdate = true;
currentMesh.geometry.elementsNeedUpdate = true;
currentMesh.geometry.normalsNeedUpdate = true;
@@ -146,6 +165,7 @@ var ProgressiveLoader = function(path, scene, materialCreator) {
if (currentMesh) {
currentMesh.geometry.computeFaceNormals();
currentMesh.geometry.computeBoundingSphere();
currentMesh.geometry.groupsNeedUpdate = true;
currentMesh.geometry.elementsNeedUpdate = true;
currentMesh.geometry.normalsNeedUpdate = true;

View File

@@ -83,7 +83,6 @@ Previewer.prototype.clear = function() {
if (this.clearNeeded) {
this.domElement.width = this.domElement.width;
this.clearNeeded = false;
console.log("Clear");
}
}

View File

@@ -34,6 +34,7 @@ function initPeachCastle(scene, collidableObjects, loader, static_path) {
static_path + 'data/castle/princess peaches castle (outside).obj',
static_path + 'data/castle/princess peaches castle (outside).mtl',
function ( object ) {
glob = object;
object.up = new THREE.Vector3(0,0,1);
scene.add(object);
collidableObjects.push(object);
@@ -249,6 +250,27 @@ function createPeachCameras(width, height) {
}
function initBobombScene(scene, collidableObjects, loader, static_path) {
// var loader = new THREE.MTLLoader('/static/data/bobomb/');
// loader.load('/static/data/bobomb/bobomb battlefeild.mtl', function(materialCreator) {
// materialCreator.preload();
// var mesh = ProgressiveLoader('static/data/bobomb/bobomb battlefeild.obj', scene, materialCreator, [
// 'Material.071_574B138E_c.bmp',
// 'Material.070_41A41EE3_c.bmp'
// ]);
// // object.position.z -= 10.9;
// // object.position.y += 0.555;
// // object.position.x += 3.23;
// var theta = 0.27;
// mesh.rotation.y = Math.PI - theta;
// mesh.up = new THREE.Vector3(0,0,1);
// collidableObjects.push(mesh);
// });
// Create loader if not already done
if (loader === undefined) {
loader = new THREE.OBJMTLLoader();
@@ -763,7 +785,6 @@ function initSponzaScene(scene, collidableObjects, loader, static_path) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log( Math.round(percentComplete, 2) + '% downloaded' );
console.log(xhr);
}
};

View File

@@ -79,9 +79,9 @@ function init() {
// Initialize pointer camera
var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.1, 100000, renderer, container);
cameras = initMainScene(camera1, scene, static_path, coins);
// cameras = initMainScene(camera1, scene, static_path, coins);
// cameras = initPeach(camera1, scene, static_path, coins);
// cameras = initBobomb(camera1, scene, static_path, coins);
cameras = initBobomb(camera1, scene, static_path, coins);
// cameras = initWhomp(camera1, scene, static_path, coins);
// cameras = initMountain(camera1, scene, static_path, coins);
// cameras = initSponza(camera1, scene, static_path, coins);

View File

@@ -133,7 +133,7 @@ THREE.MTLLoader.MaterialCreator.prototype = {
setMaterials: function( materialsInfo ) {
this.materialsInfo = this.convert( materialsInfo );
this.materials = {};
this.materials = {};
this.materialsArray = [];
this.nameLookup = {};
@@ -255,6 +255,8 @@ THREE.MTLLoader.MaterialCreator.prototype = {
create: function ( materialName ) {
// console.log(materialName.indexOf(' ') === -1);
if ( this.materials[ materialName ] === undefined ) {
this.createMaterial_( materialName );