From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- .../RDGE/src/core/script/MeshManager.js | 82 +++++++++++----------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'js/helper-classes/RDGE/src/core/script/MeshManager.js') diff --git a/js/helper-classes/RDGE/src/core/script/MeshManager.js b/js/helper-classes/RDGE/src/core/script/MeshManager.js index 768b7213..81359fc4 100755 --- a/js/helper-classes/RDGE/src/core/script/MeshManager.js +++ b/js/helper-classes/RDGE/src/core/script/MeshManager.js @@ -38,16 +38,16 @@ RDGE.Model = function (name, mesh) { }; /* - * Maintains a list of meshes to allow instancing of data + * Maintains a list of meshes to allow instancing of data */ RDGE.MeshManager = function () { - this.contentUrl = "assets_web/mesh/"; - this.modelMap = {}; - this.readyList = []; // meshes that have data ready - this.meshesLoading = true; // indicates that no meshes have loaded or that they are still loading - this.postMeshLoadCallbackList = []; - this.tempSphere = null; - this.requestCounter = 0; + this.contentUrl = "assets_web/mesh/"; + this.modelMap = {}; + this.readyList = []; // meshes that have data ready + this.meshesLoading = true; // indicates that no meshes have loaded or that they are still loading + this.postMeshLoadCallbackList = []; + this.tempSphere = null; + this.requestCounter = 0; }; /* @@ -62,7 +62,7 @@ RDGE.MeshManager.prototype.loadMesh = function (meshStump, tempMesh) { meshStump.addr = this.contentUrl + meshStump.name + "_mesh.json"; meshStump.ctxID = RDGE.globals.engine.getContext().renderer.id; - // sets a temp mesh up in place of the final mesh to load + // sets a temp mesh up in place of the final mesh to load if (!tempMesh) { if (this.tempSphere == null) { this.tempSphere = RDGE.renderUtils.makeSphere(RDGE.globals.engine.getContext().renderer.ctx, 25, 5, 5); @@ -71,7 +71,7 @@ RDGE.MeshManager.prototype.loadMesh = function (meshStump, tempMesh) { tempMesh = this.tempSphere; } - // add the temp mesh to the map of loaded meshes + // add the temp mesh to the map of loaded meshes this.modelMap[meshStump.name] = tempMesh; // update the request counter - we now have one more mesh to load @@ -86,15 +86,15 @@ RDGE.MeshManager.prototype.loadMesh = function (meshStump, tempMesh) { * Deletes the passed mesh from the manager as well as all renderers */ RDGE.MeshManager.prototype.deleteMesh = function (name) { - var model = this.modelMap[name]; - + var model = this.modelMap[name]; + if (model) { RDGE.globals.engine.ctxMan.forEach(function (context) { - context.renderer.deletePrimitive(model.primitive); - }); + context.renderer.deletePrimitive(model.primitive); + }); - delete this.modelMap[name]; - } + delete this.modelMap[name]; + } }; RDGE.MeshManager.prototype.getModelByName = function (name) { @@ -113,7 +113,7 @@ RDGE.MeshManager.prototype.getModelNames = function () { RDGE.MeshManager.prototype.processMeshData = function () { var renderer = RDGE.globals.engine.getContext().renderer; - + // loop through meshes and load ready data for (var index in this.readyList) { // if item is ready load it @@ -128,7 +128,7 @@ RDGE.MeshManager.prototype.processMeshData = function () { primset.vertexDefinition = { - // this shows two ways to map this data to an attribute + // this shows two ways to map this data to an attribute "vert": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, "a_pos": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, "normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, @@ -142,25 +142,25 @@ RDGE.MeshManager.prototype.processMeshData = function () { primset.bufferStreams = [ - model.root.data.coords, - model.root.data.normals, - model.root.data.uvs + model.root.data.coords, + model.root.data.normals, + model.root.data.uvs ]; primset.streamUsage = [ - RDGE.rdgeConstants.BUFFER_STATIC, - RDGE.rdgeConstants.BUFFER_STATIC, - RDGE.rdgeConstants.BUFFER_STATIC + RDGE.rdgeConstants.BUFFER_STATIC, + RDGE.rdgeConstants.BUFFER_STATIC, + RDGE.rdgeConstants.BUFFER_STATIC ]; primset.indexUsage = RDGE.rdgeConstants.BUFFER_STREAM; primset.indexBuffer = model.root.data.indices; - renderer.createPrimitive( primset ); - - model.root.primitive = primset; + renderer.createPrimitive( primset ); + + model.root.primitive = primset; // generate a bounding box for this mesh model.root.bbox = new RDGE.box(); @@ -185,7 +185,7 @@ RDGE.MeshManager.prototype.processMeshData = function () { }; RDGE.MeshManager.prototype.isReady = function () { - return this.readyList.length == 0; + return this.readyList.length == 0; }; RDGE.MeshManager.prototype.addOnLoadedCallback = function (callback) { @@ -201,29 +201,29 @@ RDGE.MeshManager.prototype.onLoaded = function (meshName) { RDGE.MeshManager.prototype.exportJSON = function () { for (var m in this.modelMap) { - this.modelMap[m].primitive.built = false; - } - - return JSON.stringify(this.modelMap); + this.modelMap[m].primitive.built = false; + } + + return JSON.stringify(this.modelMap); }; RDGE.MeshManager.prototype.importJSON = function (jsonMeshExport) { try { - var tempModelMap = JSON.parse(jsonMeshExport); - + var tempModelMap = JSON.parse(jsonMeshExport); + for (var m in tempModelMap) { if (!this.modelMap[m]) { - this.modelMap[m] = tempModelMap[m]; - } - } - window.console.log("meshes imported"); + this.modelMap[m] = tempModelMap[m]; + } + } + window.console.log("meshes imported"); } catch (e) { - window.console.error("error importing meshes: " + e.description ); - } + window.console.error("error importing meshes: " + e.description ); + } }; /* - * global function for the mesh manager to make mesh file requests + * global function for the mesh manager to make mesh file requests */ RDGE.requestMesh = function (mesh) { var request = new XMLHttpRequest(); -- cgit v1.2.3 From 04343eda8c2f870b0da55cfdc8003c99fe1cc4de Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:53:10 -0700 Subject: Remove trailing spaces --- .../RDGE/src/core/script/MeshManager.js | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'js/helper-classes/RDGE/src/core/script/MeshManager.js') diff --git a/js/helper-classes/RDGE/src/core/script/MeshManager.js b/js/helper-classes/RDGE/src/core/script/MeshManager.js index 81359fc4..1fff19c5 100755 --- a/js/helper-classes/RDGE/src/core/script/MeshManager.js +++ b/js/helper-classes/RDGE/src/core/script/MeshManager.js @@ -73,7 +73,7 @@ RDGE.MeshManager.prototype.loadMesh = function (meshStump, tempMesh) { // add the temp mesh to the map of loaded meshes this.modelMap[meshStump.name] = tempMesh; - + // update the request counter - we now have one more mesh to load this.requestCounter++; @@ -87,7 +87,7 @@ RDGE.MeshManager.prototype.loadMesh = function (meshStump, tempMesh) { */ RDGE.MeshManager.prototype.deleteMesh = function (name) { var model = this.modelMap[name]; - + if (model) { RDGE.globals.engine.ctxMan.forEach(function (context) { context.renderer.deletePrimitive(model.primitive); @@ -113,20 +113,20 @@ RDGE.MeshManager.prototype.getModelNames = function () { RDGE.MeshManager.prototype.processMeshData = function () { var renderer = RDGE.globals.engine.getContext().renderer; - + // loop through meshes and load ready data for (var index in this.readyList) { // if item is ready load it if (this.readyList[index] && this.readyList[index].ready && renderer.id === this.readyList[index].ctxID) { - + // pop the item var model = this.readyList[index]; this.readyList.splice(index, 1); - + var primset = new RDGE.rdgePrimitiveDefinition(); - - primset.vertexDefinition = + + primset.vertexDefinition = { // this shows two ways to map this data to an attribute "vert": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, @@ -139,27 +139,27 @@ RDGE.MeshManager.prototype.processMeshData = function () { "a_texcoords": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, "a_uv": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC } }; - - primset.bufferStreams = + + primset.bufferStreams = [ model.root.data.coords, model.root.data.normals, model.root.data.uvs ]; - - primset.streamUsage = + + primset.streamUsage = [ RDGE.rdgeConstants.BUFFER_STATIC, RDGE.rdgeConstants.BUFFER_STATIC, RDGE.rdgeConstants.BUFFER_STATIC ]; - + primset.indexUsage = RDGE.rdgeConstants.BUFFER_STREAM; - + primset.indexBuffer = model.root.data.indices; renderer.createPrimitive( primset ); - + model.root.primitive = primset; // generate a bounding box for this mesh @@ -173,10 +173,10 @@ RDGE.MeshManager.prototype.processMeshData = function () { } this.modelMap[model.root.attribs.name] = model.root; - + // now that the model is load reduce the request count this.requestCounter--; - + this.onLoaded(model.root.attribs.name); //break; } @@ -185,7 +185,7 @@ RDGE.MeshManager.prototype.processMeshData = function () { }; RDGE.MeshManager.prototype.isReady = function () { - return this.readyList.length == 0; + return this.readyList.length == 0; }; RDGE.MeshManager.prototype.addOnLoadedCallback = function (callback) { @@ -203,14 +203,14 @@ RDGE.MeshManager.prototype.exportJSON = function () { for (var m in this.modelMap) { this.modelMap[m].primitive.built = false; } - + return JSON.stringify(this.modelMap); }; RDGE.MeshManager.prototype.importJSON = function (jsonMeshExport) { try { var tempModelMap = JSON.parse(jsonMeshExport); - + for (var m in tempModelMap) { if (!this.modelMap[m]) { this.modelMap[m] = tempModelMap[m]; @@ -218,13 +218,13 @@ RDGE.MeshManager.prototype.importJSON = function (jsonMeshExport) { } window.console.log("meshes imported"); } catch (e) { - window.console.error("error importing meshes: " + e.description ); + window.console.error("error importing meshes: " + e.description ); } }; /* * global function for the mesh manager to make mesh file requests - */ + */ RDGE.requestMesh = function (mesh) { var request = new XMLHttpRequest(); request.mesh = mesh; -- cgit v1.2.3 From 3644cb6def4f681c99959e5729e78ea353441fad Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 12:34:53 -0700 Subject: Normalize to unix line terminators --- .../RDGE/src/core/script/MeshManager.js | 494 ++++++++++----------- 1 file changed, 247 insertions(+), 247 deletions(-) (limited to 'js/helper-classes/RDGE/src/core/script/MeshManager.js') diff --git a/js/helper-classes/RDGE/src/core/script/MeshManager.js b/js/helper-classes/RDGE/src/core/script/MeshManager.js index 1fff19c5..eea94b74 100755 --- a/js/helper-classes/RDGE/src/core/script/MeshManager.js +++ b/js/helper-classes/RDGE/src/core/script/MeshManager.js @@ -1,247 +1,247 @@ -/* -Copyright (c) 2012, Motorola Mobility, Inc -All Rights Reserved. -BSD License. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Motorola Mobility nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - */ - -// RDGE namespaces -var RDGE = RDGE || {}; - -RDGE.Model = function (name, mesh) { - this.name = name; - this.mesh = mesh; - this.camera = null; -}; - -/* - * Maintains a list of meshes to allow instancing of data - */ -RDGE.MeshManager = function () { - this.contentUrl = "assets_web/mesh/"; - this.modelMap = {}; - this.readyList = []; // meshes that have data ready - this.meshesLoading = true; // indicates that no meshes have loaded or that they are still loading - this.postMeshLoadCallbackList = []; - this.tempSphere = null; - this.requestCounter = 0; -}; - -/* - * Pass the scene meshNode stump, loads temp object while real mesh is downloading - */ -RDGE.MeshManager.prototype.loadMesh = function (meshStump, tempMesh) { - // if it exists already, return the mesh requested - if ( this.modelMap[meshStump.name] !== undefined ) - return this.modelMap[meshStump.name]; - - meshStump.ready = false; - meshStump.addr = this.contentUrl + meshStump.name + "_mesh.json"; - meshStump.ctxID = RDGE.globals.engine.getContext().renderer.id; - - // sets a temp mesh up in place of the final mesh to load - if (!tempMesh) { - if (this.tempSphere == null) { - this.tempSphere = RDGE.renderUtils.makeSphere(RDGE.globals.engine.getContext().renderer.ctx, 25, 5, 5); - } - - tempMesh = this.tempSphere; - } - - // add the temp mesh to the map of loaded meshes - this.modelMap[meshStump.name] = tempMesh; - - // update the request counter - we now have one more mesh to load - this.requestCounter++; - - RDGE.requestMesh(meshStump); - - return null; -}; - -/* - * Deletes the passed mesh from the manager as well as all renderers - */ -RDGE.MeshManager.prototype.deleteMesh = function (name) { - var model = this.modelMap[name]; - - if (model) { - RDGE.globals.engine.ctxMan.forEach(function (context) { - context.renderer.deletePrimitive(model.primitive); - }); - - delete this.modelMap[name]; - } -}; - -RDGE.MeshManager.prototype.getModelByName = function (name) { - return this.modelMap[name]; -}; - -RDGE.MeshManager.prototype.getModelNames = function () { - var names = []; - for (var index in this.modelMap) { - names.push(this.modelList[index].name); - } - - return names; -}; - - -RDGE.MeshManager.prototype.processMeshData = function () { - var renderer = RDGE.globals.engine.getContext().renderer; - - // loop through meshes and load ready data - for (var index in this.readyList) { - // if item is ready load it - if (this.readyList[index] && this.readyList[index].ready && renderer.id === this.readyList[index].ctxID) { - - - // pop the item - var model = this.readyList[index]; - this.readyList.splice(index, 1); - - var primset = new RDGE.rdgePrimitiveDefinition(); - - primset.vertexDefinition = - { - // this shows two ways to map this data to an attribute - "vert": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, - "a_pos": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, - "normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, - "a_norm": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, - "a_normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, - "texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, - "a_texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, - "a_texcoords": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, - "a_uv": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC } - }; - - primset.bufferStreams = - [ - model.root.data.coords, - model.root.data.normals, - model.root.data.uvs - ]; - - primset.streamUsage = - [ - RDGE.rdgeConstants.BUFFER_STATIC, - RDGE.rdgeConstants.BUFFER_STATIC, - RDGE.rdgeConstants.BUFFER_STATIC - ]; - - primset.indexUsage = RDGE.rdgeConstants.BUFFER_STREAM; - - primset.indexBuffer = model.root.data.indices; - - renderer.createPrimitive( primset ); - - model.root.primitive = primset; - - // generate a bounding box for this mesh - model.root.bbox = new RDGE.box(); - - var numCoords = model.root.data.coords.length; var idx = 0; - while (idx < numCoords - 2) { - var thisCoord = [model.root.data.coords[idx+0], model.root.data.coords[idx+1], model.root.data.coords[idx+2]]; - model.root.bbox.addVec3(thisCoord); - idx += 3; - } - - this.modelMap[model.root.attribs.name] = model.root; - - // now that the model is load reduce the request count - this.requestCounter--; - - this.onLoaded(model.root.attribs.name); - //break; - } - - } -}; - -RDGE.MeshManager.prototype.isReady = function () { - return this.readyList.length == 0; -}; - -RDGE.MeshManager.prototype.addOnLoadedCallback = function (callback) { - this.postMeshLoadCallbackList.push(callback) -}; - -RDGE.MeshManager.prototype.onLoaded = function (meshName) { - for (var index = 0 in this.postMeshLoadCallbackList) { - // call the functions - this.postMeshLoadCallbackList[index].onMeshLoaded(meshName); - } -}; - -RDGE.MeshManager.prototype.exportJSON = function () { - for (var m in this.modelMap) { - this.modelMap[m].primitive.built = false; - } - - return JSON.stringify(this.modelMap); -}; - -RDGE.MeshManager.prototype.importJSON = function (jsonMeshExport) { - try { - var tempModelMap = JSON.parse(jsonMeshExport); - - for (var m in tempModelMap) { - if (!this.modelMap[m]) { - this.modelMap[m] = tempModelMap[m]; - } - } - window.console.log("meshes imported"); - } catch (e) { - window.console.error("error importing meshes: " + e.description ); - } -}; - -/* - * global function for the mesh manager to make mesh file requests - */ -RDGE.requestMesh = function (mesh) { - var request = new XMLHttpRequest(); - request.mesh = mesh; - request.onreadystatechange = function () { - if (request.readyState == 4) { - if (request.status == 200 || window.location.href.indexOf("http") == -1) { - var mesh = eval("(" + request.responseText + ")"); //retrieve result as an JavaScript object - mesh.ready = true; - mesh.ctxID = request.mesh.ctxID; - RDGE.globals.meshMan.readyList.push(mesh); - } - else { - alert("An error has occured making the request"); - } - } - } - - request.open("GET", mesh.addr, true); - request.send(null); -}; +/* +Copyright (c) 2012, Motorola Mobility, Inc +All Rights Reserved. +BSD License. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + - Neither the name of Motorola Mobility nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + */ + +// RDGE namespaces +var RDGE = RDGE || {}; + +RDGE.Model = function (name, mesh) { + this.name = name; + this.mesh = mesh; + this.camera = null; +}; + +/* + * Maintains a list of meshes to allow instancing of data + */ +RDGE.MeshManager = function () { + this.contentUrl = "assets_web/mesh/"; + this.modelMap = {}; + this.readyList = []; // meshes that have data ready + this.meshesLoading = true; // indicates that no meshes have loaded or that they are still loading + this.postMeshLoadCallbackList = []; + this.tempSphere = null; + this.requestCounter = 0; +}; + +/* + * Pass the scene meshNode stump, loads temp object while real mesh is downloading + */ +RDGE.MeshManager.prototype.loadMesh = function (meshStump, tempMesh) { + // if it exists already, return the mesh requested + if ( this.modelMap[meshStump.name] !== undefined ) + return this.modelMap[meshStump.name]; + + meshStump.ready = false; + meshStump.addr = this.contentUrl + meshStump.name + "_mesh.json"; + meshStump.ctxID = RDGE.globals.engine.getContext().renderer.id; + + // sets a temp mesh up in place of the final mesh to load + if (!tempMesh) { + if (this.tempSphere == null) { + this.tempSphere = RDGE.renderUtils.makeSphere(RDGE.globals.engine.getContext().renderer.ctx, 25, 5, 5); + } + + tempMesh = this.tempSphere; + } + + // add the temp mesh to the map of loaded meshes + this.modelMap[meshStump.name] = tempMesh; + + // update the request counter - we now have one more mesh to load + this.requestCounter++; + + RDGE.requestMesh(meshStump); + + return null; +}; + +/* + * Deletes the passed mesh from the manager as well as all renderers + */ +RDGE.MeshManager.prototype.deleteMesh = function (name) { + var model = this.modelMap[name]; + + if (model) { + RDGE.globals.engine.ctxMan.forEach(function (context) { + context.renderer.deletePrimitive(model.primitive); + }); + + delete this.modelMap[name]; + } +}; + +RDGE.MeshManager.prototype.getModelByName = function (name) { + return this.modelMap[name]; +}; + +RDGE.MeshManager.prototype.getModelNames = function () { + var names = []; + for (var index in this.modelMap) { + names.push(this.modelList[index].name); + } + + return names; +}; + + +RDGE.MeshManager.prototype.processMeshData = function () { + var renderer = RDGE.globals.engine.getContext().renderer; + + // loop through meshes and load ready data + for (var index in this.readyList) { + // if item is ready load it + if (this.readyList[index] && this.readyList[index].ready && renderer.id === this.readyList[index].ctxID) { + + + // pop the item + var model = this.readyList[index]; + this.readyList.splice(index, 1); + + var primset = new RDGE.rdgePrimitiveDefinition(); + + primset.vertexDefinition = + { + // this shows two ways to map this data to an attribute + "vert": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_pos": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_norm": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_texcoords": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, + "a_uv": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC } + }; + + primset.bufferStreams = + [ + model.root.data.coords, + model.root.data.normals, + model.root.data.uvs + ]; + + primset.streamUsage = + [ + RDGE.rdgeConstants.BUFFER_STATIC, + RDGE.rdgeConstants.BUFFER_STATIC, + RDGE.rdgeConstants.BUFFER_STATIC + ]; + + primset.indexUsage = RDGE.rdgeConstants.BUFFER_STREAM; + + primset.indexBuffer = model.root.data.indices; + + renderer.createPrimitive( primset ); + + model.root.primitive = primset; + + // generate a bounding box for this mesh + model.root.bbox = new RDGE.box(); + + var numCoords = model.root.data.coords.length; var idx = 0; + while (idx < numCoords - 2) { + var thisCoord = [model.root.data.coords[idx+0], model.root.data.coords[idx+1], model.root.data.coords[idx+2]]; + model.root.bbox.addVec3(thisCoord); + idx += 3; + } + + this.modelMap[model.root.attribs.name] = model.root; + + // now that the model is load reduce the request count + this.requestCounter--; + + this.onLoaded(model.root.attribs.name); + //break; + } + + } +}; + +RDGE.MeshManager.prototype.isReady = function () { + return this.readyList.length == 0; +}; + +RDGE.MeshManager.prototype.addOnLoadedCallback = function (callback) { + this.postMeshLoadCallbackList.push(callback) +}; + +RDGE.MeshManager.prototype.onLoaded = function (meshName) { + for (var index = 0 in this.postMeshLoadCallbackList) { + // call the functions + this.postMeshLoadCallbackList[index].onMeshLoaded(meshName); + } +}; + +RDGE.MeshManager.prototype.exportJSON = function () { + for (var m in this.modelMap) { + this.modelMap[m].primitive.built = false; + } + + return JSON.stringify(this.modelMap); +}; + +RDGE.MeshManager.prototype.importJSON = function (jsonMeshExport) { + try { + var tempModelMap = JSON.parse(jsonMeshExport); + + for (var m in tempModelMap) { + if (!this.modelMap[m]) { + this.modelMap[m] = tempModelMap[m]; + } + } + window.console.log("meshes imported"); + } catch (e) { + window.console.error("error importing meshes: " + e.description ); + } +}; + +/* + * global function for the mesh manager to make mesh file requests + */ +RDGE.requestMesh = function (mesh) { + var request = new XMLHttpRequest(); + request.mesh = mesh; + request.onreadystatechange = function () { + if (request.readyState == 4) { + if (request.status == 200 || window.location.href.indexOf("http") == -1) { + var mesh = eval("(" + request.responseText + ")"); //retrieve result as an JavaScript object + mesh.ready = true; + mesh.ctxID = request.mesh.ctxID; + RDGE.globals.meshMan.readyList.push(mesh); + } + else { + alert("An error has occured making the request"); + } + } + } + + request.open("GET", mesh.addr, true); + request.send(null); +}; -- cgit v1.2.3