diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/MeshManager.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/MeshManager.js | 255 |
1 files changed, 118 insertions, 137 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/MeshManager.js b/js/helper-classes/RDGE/src/core/script/MeshManager.js index 43813078..2c31781e 100755 --- a/js/helper-classes/RDGE/src/core/script/MeshManager.js +++ b/js/helper-classes/RDGE/src/core/script/MeshManager.js | |||
@@ -4,86 +4,80 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | function Model(name, mesh) | 7 | // RDGE namespaces |
8 | { | 8 | var RDGE = RDGE || {}; |
9 | |||
10 | RDGE.Model = function (name, mesh) { | ||
9 | this.name = name; | 11 | this.name = name; |
10 | this.mesh = mesh; | 12 | this.mesh = mesh; |
11 | this.camera = null; | 13 | this.camera = null; |
12 | } | 14 | }; |
13 | 15 | ||
14 | /* | 16 | /* |
15 | * Maintains a list of meshes to allow instancing of data | 17 | * Maintains a list of meshes to allow instancing of data |
16 | */ | 18 | */ |
17 | function MeshManager() { | 19 | RDGE.MeshManager = function () { |
18 | this.contentUrl = "assets_web/mesh/"; | 20 | this.contentUrl = "assets_web/mesh/"; |
19 | this.modelMap = {}; | 21 | this.modelMap = {}; |
20 | this.readyList = []; // meshes that have data ready | 22 | this.readyList = []; // meshes that have data ready |
21 | this.meshesLoading = true; // indicates that no meshes have loaded or that they are still loading | 23 | this.meshesLoading = true; // indicates that no meshes have loaded or that they are still loading |
22 | this.postMeshLoadCallbackList = []; | 24 | this.postMeshLoadCallbackList = []; |
23 | this.tempSphere = null; | 25 | this.tempSphere = null; |
24 | this.requestCounter = 0; | 26 | this.requestCounter = 0; |
25 | } | 27 | }; |
26 | 28 | ||
27 | /* | 29 | /* |
28 | * Pass the scene meshNode stump, loads temp object while real mesh is downloading | 30 | * Pass the scene meshNode stump, loads temp object while real mesh is downloading |
29 | */ | 31 | */ |
30 | MeshManager.prototype.loadMesh = function (meshStump, tempMesh) | 32 | RDGE.MeshManager.prototype.loadMesh = function (meshStump, tempMesh) { |
31 | { | ||
32 | // if it exists already, return the mesh requested | 33 | // if it exists already, return the mesh requested |
33 | if ( this.modelMap[meshStump.name] !== undefined ) | 34 | if (this.modelMap[meshStump.name] !== undefined) |
34 | return this.modelMap[meshStump.name]; | 35 | return this.modelMap[meshStump.name]; |
35 | 36 | ||
36 | meshStump.ready = false; | 37 | meshStump.ready = false; |
37 | meshStump.addr = this.contentUrl + meshStump.name + "_mesh.json"; | 38 | meshStump.addr = this.contentUrl + meshStump.name + "_mesh.json"; |
38 | meshStump.ctxID = g_Engine.getContext().renderer.id; | 39 | meshStump.ctxID = RDGE.globals.engine.getContext().renderer.id; |
39 | 40 | ||
40 | // sets a temp mesh up in place of the final mesh to load | 41 | // sets a temp mesh up in place of the final mesh to load |
41 | if (!tempMesh) | 42 | if (!tempMesh) { |
42 | { | 43 | if (this.tempSphere == null) { |
43 | if (this.tempSphere == null) | 44 | this.tempSphere = RDGE.renderUtils.makeSphere(RDGE.globals.engine.getContext().renderer.ctx, 25, 5, 5); |
44 | { | ||
45 | this.tempSphere = makeSphere(g_Engine.getContext().renderer.ctx, 25, 5, 5); | ||
46 | } | 45 | } |
47 | 46 | ||
48 | tempMesh = this.tempSphere; | 47 | tempMesh = this.tempSphere; |
49 | } | 48 | } |
50 | 49 | ||
51 | // add the temp mesh to the map of loaded meshes | 50 | // add the temp mesh to the map of loaded meshes |
52 | this.modelMap[meshStump.name] = tempMesh; | 51 | this.modelMap[meshStump.name] = tempMesh; |
53 | 52 | ||
54 | // update the request counter - we now have one more mesh to load | 53 | // update the request counter - we now have one more mesh to load |
55 | this.requestCounter++; | 54 | this.requestCounter++; |
56 | 55 | ||
57 | requestMesh(meshStump); | 56 | RDGE.requestMesh(meshStump); |
58 | 57 | ||
59 | return null; | 58 | return null; |
60 | }; | 59 | }; |
61 | 60 | ||
62 | /* | 61 | /* |
63 | * Deletes the passed mesh from the manager as well as all renderers | 62 | * Deletes the passed mesh from the manager as well as all renderers |
64 | */ | 63 | */ |
65 | MeshManager.prototype.deleteMesh = function (name) | 64 | RDGE.MeshManager.prototype.deleteMesh = function (name) { |
66 | { | 65 | var model = this.modelMap[name]; |
67 | var model = this.modelMap[name]; | 66 | |
68 | 67 | if (model) { | |
69 | if (model) | 68 | RDGE.globals.engine.ctxMan.forEach(function (context) { |
70 | { | 69 | context.renderer.deletePrimitive(model.primitive); |
71 | g_Engine.ctxMan.forEach(function(context) | 70 | }); |
72 | { | 71 | |
73 | context.renderer.deletePrimitive(model.primitive); | 72 | delete this.modelMap[name]; |
74 | }); | 73 | } |
75 | |||
76 | delete this.modelMap[name]; | ||
77 | } | ||
78 | }; | 74 | }; |
79 | 75 | ||
80 | MeshManager.prototype.getModelByName = function (name) | 76 | RDGE.MeshManager.prototype.getModelByName = function (name) { |
81 | { | ||
82 | return this.modelMap[name]; | 77 | return this.modelMap[name]; |
83 | }; | 78 | }; |
84 | 79 | ||
85 | MeshManager.prototype.getModelNames = function () | 80 | RDGE.MeshManager.prototype.getModelNames = function () { |
86 | { | ||
87 | var names = []; | 81 | var names = []; |
88 | for (var index in this.modelMap) { | 82 | for (var index in this.modelMap) { |
89 | names.push(this.modelList[index].name); | 83 | names.push(this.modelList[index].name); |
@@ -93,134 +87,121 @@ MeshManager.prototype.getModelNames = function () | |||
93 | }; | 87 | }; |
94 | 88 | ||
95 | 89 | ||
96 | MeshManager.prototype.processMeshData = function () { | 90 | RDGE.MeshManager.prototype.processMeshData = function () { |
97 | var renderer = g_Engine.getContext().renderer; | 91 | var renderer = RDGE.globals.engine.getContext().renderer; |
98 | 92 | ||
99 | // loop through meshes and load ready data | 93 | // loop through meshes and load ready data |
100 | for (var index in this.readyList) { | 94 | for (var index in this.readyList) { |
101 | // if item is ready load it | 95 | // if item is ready load it |
102 | if (this.readyList[index] && this.readyList[index].ready && renderer.id === this.readyList[index].ctxID) { | 96 | if (this.readyList[index] && this.readyList[index].ready && renderer.id === this.readyList[index].ctxID) { |
103 | 97 | ||
104 | 98 | ||
105 | // pop the item | 99 | // pop the item |
106 | var model = this.readyList[index]; | 100 | var model = this.readyList[index]; |
107 | this.readyList.splice(index, 1); | 101 | this.readyList.splice(index, 1); |
108 | 102 | ||
109 | var primset = new rdgePrimitiveDefinition(); | 103 | var primset = new RDGE.rdgePrimitiveDefinition(); |
110 | 104 | ||
111 | primset.vertexDefinition = | 105 | primset.vertexDefinition = |
112 | { | 106 | { |
113 | // this shows two ways to map this data to an attribute | 107 | // this shows two ways to map this data to an attribute |
114 | "vert":{'type':rdgeConstants.VS_ELEMENT_POS, 'bufferIndex':0, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 108 | "vert": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
115 | "a_pos":{'type':rdgeConstants.VS_ELEMENT_POS, 'bufferIndex':0, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 109 | "a_pos": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
116 | "normal":{'type':rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 110 | "normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
117 | "a_norm":{'type':rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 111 | "a_norm": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
118 | "a_normal":{'type':rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 112 | "a_normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
119 | "texcoord":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 113 | "texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
120 | "a_texcoord":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 114 | "a_texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
121 | "a_texcoords":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 115 | "a_texcoords": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
122 | "a_uv":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC} | 116 | "a_uv": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC } |
123 | }; | 117 | }; |
124 | 118 | ||
125 | primset.bufferStreams = | 119 | primset.bufferStreams = |
126 | [ | 120 | [ |
127 | model.root.data.coords, | 121 | model.root.data.coords, |
128 | model.root.data.normals, | 122 | model.root.data.normals, |
129 | model.root.data.uvs | 123 | model.root.data.uvs |
130 | ]; | 124 | ]; |
131 | 125 | ||
132 | primset.streamUsage = | 126 | primset.streamUsage = |
133 | [ | 127 | [ |
134 | rdgeConstants.BUFFER_STATIC, | 128 | RDGE.rdgeConstants.BUFFER_STATIC, |
135 | rdgeConstants.BUFFER_STATIC, | 129 | RDGE.rdgeConstants.BUFFER_STATIC, |
136 | rdgeConstants.BUFFER_STATIC |