ProgressiveLoader seems finished... I don't like the perfs :s

This commit is contained in:
Thomas FORGIONE 2015-06-16 14:33:54 +02:00
parent c6062e6a50
commit 21321a6ff7
5 changed files with 36 additions and 17 deletions

View File

@ -253,7 +253,6 @@ mesh.Face.prototype.toString = function() {
mesh.Material = function() { mesh.Material = function() {
var split = arguments[0].replace(/\s+/g, ' ').trim().split(' '); var split = arguments[0].replace(/\s+/g, ' ').trim().split(' ');
this.name = split[1]; this.name = split[1];
console.log(this.name);
} }
mesh.Material.prototype.toString = function() { mesh.Material.prototype.toString = function() {

View File

@ -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') { } else if (line[0] === 'u') {
// usemtl // usemtl

View File

@ -1,9 +1,5 @@
var _parseList = function(arr) { var _parseList = function(arr) {
// For example
// arr = [ 'f', 0, 0, 1, 2];
// type index first second third
var ret = {}; var ret = {};
ret.index = arr[1]; ret.index = arr[1];
@ -104,6 +100,10 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
this.socket.on('usemtl', function(materialName, verticesNumber, facesNumber, texCoordsExist, normalsExist) { this.socket.on('usemtl', function(materialName, verticesNumber, facesNumber, texCoordsExist, normalsExist) {
// console.log("New mesh arrived : " + materialName); // 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 // Create mesh material
var material; var material;
@ -160,6 +160,7 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
self.currentMesh = mesh; self.currentMesh = mesh;
self.obj.add(mesh); self.obj.add(mesh);
mesh.visible = false;
if (typeof self.callback === 'function') { if (typeof self.callback === 'function') {
self.callback(mesh); self.callback(mesh);
@ -236,16 +237,17 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
if (elt.aTexture !== undefined) { 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 * 6 ] = 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 + 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 * 6 + 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 + 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 * 6 + 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 + 5] = self.texCoords[elt.cTexture][1];
self.currentMesh.geometry.attributes.uv.needsUpdate = true; self.currentMesh.geometry.attributes.uv.needsUpdate = true;
} }
} }

View File

@ -13,10 +13,10 @@ function addLight(scene) {
function initPeachCastle(scene, collidableObjects, loader, static_path) { function initPeachCastle(scene, collidableObjects, loader, static_path) {
ProgressiveLoader( var loader = new ProgressiveLoader(
'/static/data/castle/princess peaches castle (outside).obj', 'static/data/castle/princess peaches castle (outside).obj',
scene, scene,
function(object, container) { function(object) {
collidableObjects.push(object); collidableObjects.push(object);
object.raycastable = true; object.raycastable = true;
if (object.material.name === 'Material.103_princess_peaches_cast') { 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) { 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(); loader.load();
glob = loader.obj; glob = loader.obj;
loader.obj.scale.set(0.1,0.1,0.1); loader.obj.scale.set(0.1,0.1,0.1);

View File

@ -78,8 +78,8 @@ function init() {
// Initialize pointer camera // Initialize pointer camera
var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, container); var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 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 = 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 = initWhomp(camera1, scene, static_path, coins);
// cameras = initMountain(camera1, scene, static_path, coins); // cameras = initMountain(camera1, scene, static_path, coins);