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