From 21321a6ff738bca730c43af8f877e5be6453372d Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Tue, 16 Jun 2015 14:33:54 +0200 Subject: [PATCH] ProgressiveLoader seems finished... I don't like the perfs :s --- geo/Mesh.js | 1 - geo/MeshStreamer.js | 7 +++++++ js/ProgressiveLoader.js | 22 ++++++++++++---------- js/prototype/initScene.js | 19 +++++++++++++++---- js/prototype/main.js | 4 ++-- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/geo/Mesh.js b/geo/Mesh.js index 91b1f52..f0cf48e 100644 --- a/geo/Mesh.js +++ b/geo/Mesh.js @@ -253,7 +253,6 @@ mesh.Face.prototype.toString = function() { mesh.Material = function() { var split = arguments[0].replace(/\s+/g, ' ').trim().split(' '); this.name = split[1]; - console.log(this.name); } mesh.Material.prototype.toString = function() { diff --git a/geo/MeshStreamer.js b/geo/MeshStreamer.js index 9f7436d..f0b2e85 100644 --- a/geo/MeshStreamer.js +++ b/geo/MeshStreamer.js @@ -94,6 +94,13 @@ geo.MeshStreamer.prototype.loadFromFile = function(path, callback) { } + if (currentMesh.faces.length * 3 * 3 > 60000) { + var previousMesh = currentMesh; + currentMesh = new mesh.Mesh(); + self.meshes.push(currentMesh); + currentMesh.material = previousMesh.material; + } + } else if (line[0] === 'u') { // usemtl diff --git a/js/ProgressiveLoader.js b/js/ProgressiveLoader.js index 7e0ff15..c13da32 100644 --- a/js/ProgressiveLoader.js +++ b/js/ProgressiveLoader.js @@ -1,9 +1,5 @@ var _parseList = function(arr) { - // For example - // arr = [ 'f', 0, 0, 1, 2]; - // type index first second third - var ret = {}; ret.index = arr[1]; @@ -104,6 +100,10 @@ ProgressiveLoader.prototype.initIOCallbacks = function() { this.socket.on('usemtl', function(materialName, verticesNumber, facesNumber, texCoordsExist, normalsExist) { // console.log("New mesh arrived : " + materialName); + if (self.currentMesh !== undefined && self.currentMesh.visible === false) { + self.currentMesh.geometry.computeBoundingSphere(); + self.currentMesh.visible = true; + } // Create mesh material var material; @@ -160,6 +160,7 @@ ProgressiveLoader.prototype.initIOCallbacks = function() { self.currentMesh = mesh; self.obj.add(mesh); + mesh.visible = false; if (typeof self.callback === 'function') { self.callback(mesh); @@ -236,16 +237,17 @@ ProgressiveLoader.prototype.initIOCallbacks = function() { if (elt.aTexture !== undefined) { - self.currentMesh.geometry.attributes.uv.array[elt.index * 9 ] = self.texCoords[elt.aTexture][0]; - self.currentMesh.geometry.attributes.uv.array[elt.index * 9 + 1] = self.texCoords[elt.aTexture][1]; + self.currentMesh.geometry.attributes.uv.array[elt.index * 6 ] = self.texCoords[elt.aTexture][0]; + self.currentMesh.geometry.attributes.uv.array[elt.index * 6 + 1] = self.texCoords[elt.aTexture][1]; - self.currentMesh.geometry.attributes.uv.array[elt.index * 9 + 2] = self.texCoords[elt.bTexture][0]; - self.currentMesh.geometry.attributes.uv.array[elt.index * 9 + 3] = self.texCoords[elt.bTexture][1]; + self.currentMesh.geometry.attributes.uv.array[elt.index * 6 + 2] = self.texCoords[elt.bTexture][0]; + self.currentMesh.geometry.attributes.uv.array[elt.index * 6 + 3] = self.texCoords[elt.bTexture][1]; - self.currentMesh.geometry.attributes.uv.array[elt.index * 9 + 4] = self.texCoords[elt.cTexture][0]; - self.currentMesh.geometry.attributes.uv.array[elt.index * 9 + 5] = self.texCoords[elt.cTexture][1]; + self.currentMesh.geometry.attributes.uv.array[elt.index * 6 + 4] = self.texCoords[elt.cTexture][0]; + self.currentMesh.geometry.attributes.uv.array[elt.index * 6 + 5] = self.texCoords[elt.cTexture][1]; self.currentMesh.geometry.attributes.uv.needsUpdate = true; + } } diff --git a/js/prototype/initScene.js b/js/prototype/initScene.js index 025648e..4a5f345 100644 --- a/js/prototype/initScene.js +++ b/js/prototype/initScene.js @@ -13,10 +13,10 @@ function addLight(scene) { function initPeachCastle(scene, collidableObjects, loader, static_path) { - ProgressiveLoader( - '/static/data/castle/princess peaches castle (outside).obj', + var loader = new ProgressiveLoader( + 'static/data/castle/princess peaches castle (outside).obj', scene, - function(object, container) { + function(object) { collidableObjects.push(object); object.raycastable = true; if (object.material.name === 'Material.103_princess_peaches_cast') { @@ -30,6 +30,7 @@ function initPeachCastle(scene, collidableObjects, loader, static_path) { } } ); + loader.load(); } @@ -600,7 +601,17 @@ function initMountain(camera, scene, static_path, coins) { function initSponzaScene(scene, collidableObjects, loader, static_path) { - var loader = new ProgressiveLoader('static/data/sponza/sponza.obj', scene); + var loader = new ProgressiveLoader('static/data/sponza/sponza.obj', scene, function(obj) { + if (obj.material.name === 'chain' || + obj.material.name === 'leaf' || + obj.material.name === 'Material__57') { + + THREEx.Transparency.push(obj); + + } + + }); + loader.load(); glob = loader.obj; loader.obj.scale.set(0.1,0.1,0.1); diff --git a/js/prototype/main.js b/js/prototype/main.js index d986abc..a657e10 100644 --- a/js/prototype/main.js +++ b/js/prototype/main.js @@ -78,8 +78,8 @@ function init() { // Initialize pointer camera var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, container); - cameras = initMainScene(camera1, scene, static_path, coins); - // cameras = initPeach(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 = initWhomp(camera1, scene, static_path, coins); // cameras = initMountain(camera1, scene, static_path, coins);