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