diff options
Diffstat (limited to 'js/document/helpers/webgl-helper.js')
-rwxr-xr-x | js/document/helpers/webgl-helper.js | 341 |
1 files changed, 171 insertions, 170 deletions
diff --git a/js/document/helpers/webgl-helper.js b/js/document/helpers/webgl-helper.js index 4d73758b..9bdf33e6 100755 --- a/js/document/helpers/webgl-helper.js +++ b/js/document/helpers/webgl-helper.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -30,72 +31,72 @@ POSSIBILITY OF SUCH DAMAGE. | |||
30 | 31 | ||
31 | //////////////////////////////////////////////////////////////////////// | 32 | //////////////////////////////////////////////////////////////////////// |
32 | // | 33 | // |
33 | var Montage = require("montage/core/core").Montage, | 34 | var Montage = require("montage/core/core").Montage, |
34 | Component = require("montage/ui/component").Component, | 35 | Component = require("montage/ui/component").Component, |
35 | MaterialsModel = require("js/models/materials-model").MaterialsModel, | 36 | MaterialsModel = require("js/models/materials-model").MaterialsModel, |
36 | NJUtils = require("js/lib/NJUtils").NJUtils, | 37 | NJUtils = require("js/lib/NJUtils").NJUtils, |
37 | GLWorld = require("js/lib/drawing/world").World; | 38 | GLWorld = require("js/lib/drawing/world").World; |
38 | //////////////////////////////////////////////////////////////////////// | 39 | //////////////////////////////////////////////////////////////////////// |
39 | // | 40 | // |
40 | exports.webGlDocumentHelper = Montage.create(Component, { | 41 | exports.webGlDocumentHelper = Montage.create(Component, { |
41 | //////////////////////////////////////////////////////////////////// | 42 | //////////////////////////////////////////////////////////////////// |
42 | // | 43 | // |
43 | hasTemplate: { | 44 | hasTemplate: { |
44 | value: false | 45 | value: false |
45 | }, | 46 | }, |
46 | //////////////////////////////////////////////////////////////////// | 47 | //////////////////////////////////////////////////////////////////// |
47 | //This is set when the design view is ready, for local reference | 48 | //This is set when the design view is ready, for local reference |
48 | iframe: { | 49 | iframe: { |
49 | value: null | 50 | value: null |
50 | }, | 51 | }, |
51 | //////////////////////////////////////////////////////////////////// | 52 | //////////////////////////////////////////////////////////////////// |
52 | // | 53 | // |
53 | _glData: { | 54 | _glData: { |
54 | value: null | 55 | value: null |
55 | }, | 56 | }, |
56 | //////////////////////////////////////////////////////////////////// | 57 | //////////////////////////////////////////////////////////////////// |
57 | // | 58 | // |
58 | glData: { | 59 | glData: { |
59 | // | 60 | // |
60 | get: function() { | 61 | get: function() { |
61 | // | 62 | // |
62 | var elt = this.iframe.contentWindow.document.body; | 63 | var elt = this.iframe.contentWindow.document.body; |
63 | // | 64 | // |
64 | if (elt) { | 65 | if (elt) { |
65 | var matLib = MaterialsModel.exportMaterials(); | 66 | var matLib = MaterialsModel.exportMaterials(); |
66 | this._glData = [matLib]; | 67 | this._glData = [matLib]; |
67 | this.collectGLData(this.iframe.contentWindow.document, this._glData ); | 68 | this.collectGLData(this.iframe.contentWindow.document, this._glData ); |
68 | } else { | 69 | } else { |
69 | this._glData = null | 70 | this._glData = null |
70 | } | 71 | } |
71 | // | 72 | // |
72 | return this._glData; | 73 | return this._glData; |
73 | }, | 74 | }, |
74 | // | 75 | // |
75 | set: function(value) { | 76 | set: function(value) { |
76 | // | 77 | // |
77 | var elt = this.iframe.contentWindow.document.body; | 78 | var elt = this.iframe.contentWindow.document.body; |
78 | // | 79 | // |
79 | if (elt) { | 80 | if (elt) { |
80 | /* | 81 | /* |
81 | // Use this code to test the runtime version of WebGL | 82 | // Use this code to test the runtime version of WebGL |
82 | var cdm = new NinjaCvsRt.CanvasDataManager(); | 83 | var cdm = new NinjaCvsRt.CanvasDataManager(); |
83 | cdm.loadGLData(elt, value, null ); | 84 | cdm.loadGLData(elt, value, null ); |
84 | */ | 85 | */ |
85 | 86 | ||
86 | // | 87 | // |
87 | var i, nWorlds= value.length; | 88 | var i, nWorlds= value.length; |
88 | // | 89 | // |
89 | for (i = 0; i < nWorlds; i++) { | 90 | for (i = 0; i < nWorlds; i++) { |
90 | // get the data for the next canvas | 91 | // get the data for the next canvas |
91 | var importStr = value[i], id, jObj, index = importStr.indexOf(';'), matLibStr, matLibObj, startIndex, endIndex, canvas, useWebGL, world; | 92 | 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 | 93 | // determine if it is the new (JSON) or old style format |
93 | if ((importStr[0] === 'v') && (index < 24)) { | 94 | if ((importStr[0] === 'v') && (index < 24)) { |
94 | // JSON format. pull off the | 95 | // JSON format. pull off the |
95 | importStr = importStr.substr(index+1); | 96 | importStr = importStr.substr(index+1); |
96 | jObj = JSON.parse(importStr); | 97 | jObj = JSON.parse(importStr); |
97 | id = jObj.id; | 98 | id = jObj.id; |
98 | } else { | 99 | } else { |
99 | // at this point the data could be either the materials library or | 100 | // 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 | 101 | // 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 | 102 | // to an object via JSON.parse. That operation will fail if the string |
@@ -107,113 +108,113 @@ exports.webGlDocumentHelper = Montage.create(Component, { | |||
107 | matLibObj = JSON.parse(importStr); | 108 | matLibObj = JSON.parse(importStr); |
108 | MaterialsModel.importMaterials(matLibObj); | 109 | MaterialsModel.importMaterials(matLibObj); |
109 | } else { | 110 | } else { |
110 | startIndex = importStr.indexOf("id: "); | 111 | startIndex = importStr.indexOf("id: "); |
111 | if (startIndex >= 0) { | 112 | if (startIndex >= 0) { |
112 | endIndex = importStr.indexOf("\n", startIndex); | 113 | endIndex = importStr.indexOf("\n", startIndex); |
113 | if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex); | 114 | if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex); |
114 | } | 115 | } |
116 | } | ||
117 | } | ||
118 | // | ||
119 | if (id != null) { | ||
120 | // | ||
121 | canvas = this.findCanvasWithID(id, elt); | ||
122 | // | ||
123 | if (canvas) { | ||
124 | // | ||
125 | if (canvas.elementModel) { | ||
126 | if (canvas.elementModel.shapeModel.GLWorld) { | ||
127 | canvas.elementModel.shapeModel.GLWorld.clearTree(); | ||
128 | } | ||
129 | // | ||
130 | if (jObj) { | ||
131 | useWebGL = jObj.webGL; | ||
132 | world = new GLWorld(canvas, useWebGL); | ||
133 | world.importJSON(jObj); | ||
134 | } | ||
135 | // | ||
136 | this.buildShapeModel(canvas.elementModel, world); | ||
137 | } | ||
115 | } | 138 | } |
116 | } | 139 | } |
117 | // | 140 | } |
118 | if (id != null) { | 141 | } |
119 | // | 142 | } |
120 | canvas = this.findCanvasWithID(id, elt); | ||
121 | // | ||
122 | if (canvas) { | ||
123 | // | ||
124 | if (canvas.elementModel) { | ||
125 | if (canvas.elementModel.shapeModel.GLWorld) { | ||
126 | canvas.elementModel.shapeModel.GLWorld.clearTree(); | ||
127 | } | ||
128 | // | ||
129 | if (jObj) { | ||
130 | useWebGL = jObj.webGL; | ||
131 | world = new GLWorld(canvas, useWebGL); | ||
132 | world.importJSON(jObj); | ||
133 | } | ||
134 | // | ||
135 | this.buildShapeModel(canvas.elementModel, world); | ||
136 | } |