diff options
Diffstat (limited to 'js/document/helpers/webgl-helper.js')
-rwxr-xr-x | js/document/helpers/webgl-helper.js | 318 |
1 files changed, 159 insertions, 159 deletions
diff --git a/js/document/helpers/webgl-helper.js b/js/document/helpers/webgl-helper.js index 4d73758b..86e2cdc1 100755 --- a/js/document/helpers/webgl-helper.js +++ b/js/document/helpers/webgl-helper.js | |||
@@ -30,72 +30,72 @@ POSSIBILITY OF SUCH DAMAGE. | |||
30 | 30 | ||
31 | //////////////////////////////////////////////////////////////////////// | 31 | //////////////////////////////////////////////////////////////////////// |
32 | // | 32 | // |
33 | var Montage = require("montage/core/core").Montage, | 33 | var Montage = require("montage/core/core").Montage, |
34 | Component = require("montage/ui/component").Component, | 34 | Component = require("montage/ui/component").Component, |
35 | MaterialsModel = require("js/models/materials-model").MaterialsModel, | 35 | MaterialsModel = require("js/models/materials-model").MaterialsModel, |
36 | NJUtils = require("js/lib/NJUtils").NJUtils, | 36 | NJUtils = require("js/lib/NJUtils").NJUtils, |
37 | GLWorld = require("js/lib/drawing/world").World; | 37 | GLWorld = require("js/lib/drawing/world").World; |
38 | //////////////////////////////////////////////////////////////////////// | 38 | //////////////////////////////////////////////////////////////////////// |
39 | // | 39 | // |
40 | exports.webGlDocumentHelper = Montage.create(Component, { | 40 | exports.webGlDocumentHelper = Montage.create(Component, { |
41 | //////////////////////////////////////////////////////////////////// | 41 | //////////////////////////////////////////////////////////////////// |
42 | // | 42 | // |
43 | hasTemplate: { | 43 | hasTemplate: { |
44 | value: false | 44 | value: false |
45 | }, | 45 | }, |
46 | //////////////////////////////////////////////////////////////////// | 46 | //////////////////////////////////////////////////////////////////// |
47 | //This is set when the design view is ready, for local reference | 47 | //This is set when the design view is ready, for local reference |
48 | iframe: { | 48 | iframe: { |
49 | value: null | 49 | value: null |
50 | }, | 50 | }, |
51 | //////////////////////////////////////////////////////////////////// | 51 | //////////////////////////////////////////////////////////////////// |
52 | // | 52 | // |
53 | _glData: { | 53 | _glData: { |
54 | value: null | 54 | value: null |
55 | }, | 55 | }, |
56 | //////////////////////////////////////////////////////////////////// | 56 | //////////////////////////////////////////////////////////////////// |
57 | // | 57 | // |
58 | glData: { | 58 | glData: { |
59 | // | 59 | // |
60 | get: function() { | 60 | get: function() { |
61 | // | 61 | // |
62 | var elt = this.iframe.contentWindow.document.body; | 62 | var elt = this.iframe.contentWindow.document.body; |
63 | // | 63 | // |
64 | if (elt) { | 64 | if (elt) { |
65 | var matLib = MaterialsModel.exportMaterials(); | 65 | var matLib = MaterialsModel.exportMaterials(); |
66 | this._glData = [matLib]; | 66 | this._glData = [matLib]; |
67 | this.collectGLData(this.iframe.contentWindow.document, this._glData ); | 67 | this.collectGLData(this.iframe.contentWindow.document, this._glData ); |
68 | } else { | 68 | } else { |
69 | this._glData = null | 69 | this._glData = null |
70 | } | 70 | } |
71 | // | 71 | // |
72 | return this._glData; | 72 | return this._glData; |
73 | }, | 73 | }, |
74 | // | 74 | // |
75 | set: function(value) { | 75 | set: function(value) { |
76 | // | 76 | // |
77 | var elt = this.iframe.contentWindow.document.body; | 77 | var elt = this.iframe.contentWindow.document.body; |
78 | // | 78 | // |
79 | if (elt) { | 79 | if (elt) { |
80 | /* | 80 | /* |
81 | // Use this code to test the runtime version of WebGL | 81 | // Use this code to test the runtime version of WebGL |
82 | var cdm = new NinjaCvsRt.CanvasDataManager(); | 82 | var cdm = new NinjaCvsRt.CanvasDataManager(); |
83 | cdm.loadGLData(elt, value, null ); | 83 | cdm.loadGLData(elt, value, null ); |
84 | */ | 84 | */ |
85 | 85 | ||
86 | // | 86 | // |
87 | var i, nWorlds= value.length; | 87 | var i, nWorlds= value.length; |
88 | // | 88 | // |
89 | for (i = 0; i < nWorlds; i++) { | 89 | for (i = 0; i < nWorlds; i++) { |
90 | // get the data for the next canvas | 90 | // get the data for the next canvas |
91 | var importStr = value[i], id, jObj, index = importStr.indexOf(';'), matLibStr, matLibObj, startIndex, endIndex, canvas, useWebGL, world; | 91 | var importStr = value[i], id, jObj, index = importStr.indexOf(';'), matLibStr, matLibObj, startIndex, endIndex, canvas, useWebGL, world; |
92 | // determine if it is the new (JSON) or old style format | 92 | // determine if it is the new (JSON) or old style format |
93 | if ((importStr[0] === 'v') && (index < 24)) { | 93 | if ((importStr[0] === 'v') && (index < 24)) { |
94 | // JSON format. pull off the | 94 | // JSON format. pull off the |
95 | importStr = importStr.substr(index+1); | 95 | importStr = importStr.substr(index+1); |
96 | jObj = JSON.parse(importStr); | 96 | jObj = JSON.parse(importStr); |
97 | id = jObj.id; | 97 | id = jObj.id; |
98 | } else { | 98 | } else { |
99 | // at this point the data could be either the materials library or | 99 | // at this point the data could be either the materials library or |
100 | // an old style world. We can determine which by converting the string | 100 | // an old style world. We can determine which by converting the string |
101 | // to an object via JSON.parse. That operation will fail if the string | 101 | // to an object via JSON.parse. That operation will fail if the string |
@@ -107,113 +107,113 @@ exports.webGlDocumentHelper = Montage.create(Component, { | |||
107 | matLibObj = JSON.parse(importStr); | 107 | matLibObj = JSON.parse(importStr); |
108 | MaterialsModel.importMaterials(matLibObj); | 108 | MaterialsModel.importMaterials(matLibObj); |
109 | } else { | 109 | } else { |
110 | startIndex = importStr.indexOf("id: "); | 110 | startIndex = importStr.indexOf("id: "); |
111 | if (startIndex >= 0) { | 111 | if (startIndex >= 0) { |
112 | endIndex = importStr.indexOf("\n", startIndex); | 112 | endIndex = importStr.indexOf("\n", startIndex); |
113 | if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex); | 113 | if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | } | 116 | } |
117 | // | 117 | // |
118 | if (id != null) { | 118 | if (id != null) { |
119 | // | 119 | // |
120 | canvas = this.findCanvasWithID(id, elt); | 120 | canvas = this.findCanvasWithID(id, elt); |
121 | // | 121 | // |
122 | if (canvas) { | 122 | if (canvas) { |
123 | // | 123 | // |
124 | if (canvas.elementModel) { | 124 | if (canvas.elementModel) { |
125 | if (canvas.elementModel.shapeModel.GLWorld) { | 125 | if (canvas.elementModel.shapeModel.GLWorld) { |
126 | canvas.elementModel.shapeModel.GLWorld.clearTree(); | 126 | canvas.elementModel.shapeModel.GLWorld.clearTree(); |
127 | } | 127 | } |
128 | // | 128 | // |
129 | if (jObj) { | 129 | if (jObj) { |
130 | useWebGL = jObj.webGL; | 130 | useWebGL = jObj.webGL; |
131 | world = new GLWorld(canvas, useWebGL); | 131 | world = new GLWorld(canvas, useWebGL); |
132 | world.importJSON(jObj); | 132 | world.importJSON(jObj); |
133 | } | 133 | } |
134 | // | 134 | // |
135 | this.buildShapeModel(canvas.elementModel, world); | 135 | this.buildShapeModel(canvas.elementModel, world); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } | 138 | } |
139 | } | 139 | } |
140 | } | 140 | } |
141 | } | 141 | } |
142 | }, | 142 | }, |
143 | //////////////////////////////////////////////////////////////////// | 143 | //////////////////////////////////////////////////////////////////// |
144 | // | 144 | // |
145 | findCanvasWithID: { | 145 | findCanvasWithID: { |
146 | value: function(id, elt) { | 146 | value: function(id, elt) { |
147 | // | 147 | // |
148 | var i, child, nKids, foundElt, cid = elt.getAttribute("data-RDGE-id"); | 148 | var i, child, nKids, foundElt, cid = elt.getAttribute("data-RDGE-id"); |
149 | // | 149 | // |
150 | if (cid == id) return elt; | 150 | if (cid == id) return elt; |
151 | // | 151 | // |
152 | if (elt.children) { | 152 | if (elt.children) { |
153 | nKids = elt.children.length; | 153 | nKids = elt.children.length; |
154 | for (i=0; i<nKids; i++) { | 154 | for (i=0; i<nKids; i++) { |
155 | child = elt.children[i]; | 155 | child = elt.children[i]; |
156 | foundElt = this.findCanvasWithID( id, child ); | 156 | foundElt = this.findCanvasWithID( id, child ); |
157 | if (foundElt) return foundElt; | 157 | if (foundElt) return foundElt; |
158 | } | 158 | } |
159 | } | 159 | } |
160 | } | 160 | } |
161 | }, | 161 | }, |
162 | //////////////////////////////////////////////////////////////////// | 162 | //////////////////////////////////////////////////////////////////// |
163 | // | 163 | // |
164 | buildShapeModel: { | 164 | buildShapeModel: { |
165 | value: function(elementModel, world) { | 165 | value: function(elementModel, world) { |
166 | // | 166 | // |
167 | var shapeModel = elementModel.shapeModel, root; | 167 | var shapeModel = elementModel.shapeModel, root; |
168 | shapeModel.shap |