diff options
Diffstat (limited to 'assets')
-rw-r--r-- | assets/canvas-runtime.js | 3305 |
1 files changed, 1690 insertions, 1615 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index 67d53963..f4bfa0ae 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -28,60 +28,60 @@ NinjaCvsRt.initWebGl = function (rootElement, directory) { | |||
28 | /////////////////////////////////////////////////////////////////////// | 28 | /////////////////////////////////////////////////////////////////////// |
29 | NinjaCvsRt.CanvasDataManager = Object.create(Object.prototype, { | 29 | NinjaCvsRt.CanvasDataManager = Object.create(Object.prototype, { |
30 | 30 | ||
31 | loadGLData: { | 31 | loadGLData: { |
32 | value: function(root, valueArray, assetPath) { | 32 | value: function(root, valueArray, assetPath) { |
33 | if (assetPath) | 33 | if (assetPath) |
34 | this._assetPath = assetPath.slice(); | 34 | this._assetPath = assetPath.slice(); |
35 | 35 | ||
36 | var value = valueArray; | 36 | var value = valueArray; |
37 | var nWorlds = value.length; | 37 | var nWorlds = value.length; |
38 | for (var i=0; i<nWorlds; i++) | 38 | for (var i=0; i<nWorlds; i++) |
39 | { | 39 | { |
40 | var importStr = value[i]; | 40 | var importStr = value[i]; |
41 | 41 | ||
42 | // there should be some version information in | 42 | // there should be some version information in |
43 | // the form of 'v0.0;' Pull that off. (the trailing ';' should | 43 | // the form of 'v0.0;' Pull that off. (the trailing ';' should |
44 | // be in the first 24 characters). | 44 | // be in the first 24 characters). |
45 | var index = importStr.indexOf( ';' ); | 45 | var index = importStr.indexOf( ';' ); |
46 | if ((importStr[0] === 'v') && (index < 24)) | 46 | if ((importStr[0] === 'v') && (index < 24)) |
47 | { | 47 | { |
48 | // JSON format. pull off the version info | 48 | // JSON format. pull off the version info |
49 | importStr = importStr.substr( index+1 ); | 49 | importStr = importStr.substr( index+1 ); |
50 | 50 | ||
51 | var jObj = JSON.parse( importStr ); | 51 | var jObj = JSON.parse( importStr ); |
52 | var id = jObj.id; | 52 | var id = jObj.id; |
53 | if (id) | 53 | if (id) |
54 | { | 54 | { |
55 | var canvas = this.findCanvasWithID( id, root ); | 55 | var canvas = this.findCanvasWithID( id, root ); |
56 | if (canvas) | 56 | if (canvas) |
57 | { | 57 | { |
58 | // new NinjaCvsRt.GLRuntime( canvas, jObj, assetPath ); | 58 | // new NinjaCvsRt.GLRuntime( canvas, jObj, assetPath ); |
59 | var glRt = Object.create(NinjaCvsRt.GLRuntime, {}); | 59 | var glRt = Object.create(NinjaCvsRt.GLRuntime, {}); |
60 | glRt.renderWorld(canvas, jObj, this._assetPath); | 60 | glRt.renderWorld(canvas, jObj, this._assetPath); |
61 | } | 61 | } |
62 | } | 62 | } |
63 | } | 63 | } |
64 | } | 64 | } |
65 | } | 65 | } |
66 | }, | 66 | }, |
67 | 67 | ||
68 | findCanvasWithID: { | 68 | findCanvasWithID: { |
69 | value: function(id, elt) { | 69 | value: function(id, elt) { |
70 | var cid = elt.getAttribute( "data-RDGE-id" ); | 70 | var cid = elt.getAttribute( "data-RDGE-id" ); |
71 | if (cid == id) return elt; | 71 | if (cid == id) return elt; |
72 | 72 | ||
73 | if (elt.children) | 73 | if (elt.children) |
74 | { | 74 | { |
75 | var nKids = elt.children.length; | 75 | var nKids = elt.children.length; |
76 | for (var i=0; i<nKids; i++) | 76 | for (var i=0; i<nKids; i++) |
77 | { | 77 | { |
78 | var child = elt.children[i]; | 78 | var child = elt.children[i]; |
79 | var foundElt = this.findCanvasWithID( id, child ); | 79 | var foundElt = this.findCanvasWithID( id, child ); |
80 | if (foundElt) return foundElt; | 80 | if (foundElt) return foundElt; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | } | 83 | } |
84 | } | 84 | } |
85 | }); | 85 | }); |
86 | 86 | ||
87 | /////////////////////////////////////////////////////////////////////// | 87 | /////////////////////////////////////////////////////////////////////// |
@@ -89,394 +89,394 @@ NinjaCvsRt.CanvasDataManager = Object.create(Object.prototype, { | |||
89 | // Manages runtime fora WebGL canvas | 89 | // Manages runtime fora WebGL canvas |
90 | /////////////////////////////////////////////////////////////////////// | 90 | /////////////////////////////////////////////////////////////////////// |
91 | NinjaCvsRt.GLRuntime = Object.create(Object.prototype, { | 91 | NinjaCvsRt.GLRuntime = Object.create(Object.prototype, { |
92 | /////////////////////////////////////////////////////////////////////// | 92 | /////////////////////////////////////////////////////////////////////// |
93 | // Instance variables | 93 | // Instance variables |
94 | /////////////////////////////////////////////////////////////////////// | 94 | /////////////////////////////////////////////////////////////////////// |
95 | _canvas: { value: null, writable: true }, | 95 | _canvas: { value: null, writable: true }, |
96 | _context : { value: null, writable: true }, | 96 | _context : { value: null, writable: true }, |
97 | //this._importStr = importStr; | 97 | //this._importStr = importStr; |
98 | _jObj: { value: null, writable: true }, | 98 | _jObj: { value: null, writable: true }, |
99 | 99 | ||
100 | _renderer: { value: null, writable: true }, | 100 | _renderer: { value: null, writable: true }, |
101 | myScene: { value: null, writable: true }, | 101 | myScene: { value: null, writable: true }, |
102 | light: { value: null, writable: true }, | 102 | light: { value: null, writable: true }, |
103 | light2: { value: null, writable: true }, | 103 | light2: { value: null, writable: true }, |
104 | _rootNode: { value: null, writable: true }, | 104 | _rootNode: { value: null, writable: true }, |
105 | 105 | ||
106 | _firstRender: { value: true, writable: true }, | 106 | _firstRender: { value: true, writable: true }, |
107 | _renderCount: { value: -1, writable: true }, | 107 | _renderCount: { value: -1, writable: true }, |
108 | _initialized: { value: false, writable: true }, | 108 | _initialized: { value: false, writable: true }, |
109 | 109 | ||
110 | _useWebGL: { value: false, writable: true }, | 110 | _useWebGL: { value: false, writable: true }, |
111 | _assetPath: { value: undefined, writable: true }, | 111 | _assetPath: { value: undefined, writable: true }, |
112 | 112 | ||
113 | // view parameters | 113 | // view parameters |
114 | _fov: { value: 45.0, writable: true }, | 114 | _fov: { value: 45.0, writable: true }, |
115 | _zNear: { value: 0.1, writable: true }, | 115 | _zNear: { value: 0.1, writable: true }, |
116 | _zFar: { value: 100.0, writable: true }, | 116 | _zFar: { value: 100.0, writable: true }, |
117 | _viewDist: { value: 5.0, writable: true }, | 117 | _viewDist: { value: 5.0, writable: true }, |
118 | 118 | ||
119 | elapsed: { value: 0, writable: true }, | 119 | elapsed: { value: 0, writable: true }, |
120 | 120 | ||
121 | _aspect: { value: 1, writable: true }, | 121 | _aspect: { value: 1, writable: true }, |
122 | 122 | ||
123 | //this._geomRoot = null; | 123 | //this._geomRoot = null; |
124 | _rootChildren: { value: [], writable: true }, | 124 | _rootChildren: { value: [], writable: true }, |
125 | 125 | ||
126 | // all "live" materials | 126 | // all "live" materials |
127 | _materials: { value: [], writable: true }, | 127 | _materials: { value: [], writable: true }, |
128 | 128 | ||
129 | renderWorld: { | 129 | renderWorld: { |
130 | value: function(canvas, jObj, assetPath) { | 130 | value: function(canvas, jObj, assetPath) { |
131 | this._materials = []; | 131 | this._materials = []; |
132 | this._rootChildren = []; | 132 | this._rootChildren = []; |
133 | this._canvas = canvas; | 133 | this._canvas = canvas; |
134 | this._aspect = this._canvas.width/this._canvas.height; | 134 | this._aspect = this._canvas.width/this._canvas.height; |
135 | 135 | ||
136 | this._jObj= jObj; | 136 | this._jObj= jObj; |
137 | 137 | ||
138 | // provide the mapping for the asset directory | 138 | // provide the mapping for the asset directory |
139 | if (assetPath) { | 139 | if (assetPath) { |
140 | this._assetPath = assetPath.slice(); | 140 | this._assetPath = assetPath.slice(); |
141 | if (this._assetPath[this._assetPath.length - 1] != '/') | 141 | if (this._assetPath[this._assetPath.length - 1] != '/') |
142 | this._assetPath += '/'; | 142 | this._assetPath += '/'; |
143 | } | 143 | } |
144 | 144 | ||
145 | if(this._assetPath !== undefined) { | 145 | if(this._assetPath !== undefined) { |
146 | RDGE.globals.engine.setAssetPath(this._assetPath); | 146 | RDGE.globals.engine.setAssetPath(this._assetPath); |
147 | } | 147 | } |
148 | 148 | ||
149 | // start RDGE or load Canvas 2D objects | 149 | // start RDGE or load Canvas 2D objects |
150 | if (jObj.scenedata) this._useWebGL = true; | 150 | if (jObj.scenedata) this._useWebGL = true; |
151 | if (this._useWebGL) | 151 | if (this._useWebGL) |
152 | { | 152 | { |
153 | var id = this._canvas.getAttribute( "data-RDGE-id" ); | 153 | var id = this._canvas.getAttribute( "data-RDGE-id" ); |
154 | this._canvas.rdgeid = id; | 154 | this._canvas.rdgeid = id; |
155 | RDGE.globals.engine.registerCanvas(this._canvas, this); | 155 | RDGE.globals.engine.registerCanvas(this._canvas, this); |
156 | RDGE.RDGEStart( this._canvas ); | 156 | RDGE.RDGEStart( this._canvas ); |
157 | } | 157 | } |
158 | else | 158 | else |
159 | { | 159 | { |
160 | this.loadScene(); | 160 | this.loadScene(); |
161 | } | 161 | } |
162 | } | 162 | } |
163 | }, | 163 | }, |
164 | 164 | ||
165 | /////////////////////////////////////////////////////////////////////// | 165 | /////////////////////////////////////////////////////////////////////// |
166 | // accessors | 166 | // accessors |
167 | /////////////////////////////////////////////////////////////////////// | 167 | /////////////////////////////////////////////////////////////////////// |
168 | getZNear: { value: function() { return this._zNear; }}, | 168 | getZNear: { value: function() { return this._zNear; }}, |
169 | getZFar: { value: function() { return this._zFar; }}, | 169 | getZFar: { value: function() { return this._zFar; }}, |
170 | getFOV: { value: function() { return this._fov; }}, | 170 | getFOV: { value: function() { return this._fov; }}, |
171 | getAspect: { value: function() { return this._aspect; }}, | 171 | getAspect: { value: function() { return this._aspect; }}, |
172 | getViewDistance: { value: function() { return this._viewDist; }}, | 172 | getViewDistance: { value: function() { return this._viewDist; }}, |
173 | 173 | ||
174 | get2DContext: { value: function() { return this._context; }}, | 174 | get2DContext: { value: function() { return this._context; }}, |