diff options
author | Pushkar Joshi | 2012-05-22 13:22:26 -0700 |
---|---|---|
committer | Pushkar Joshi | 2012-05-22 13:22:26 -0700 |
commit | 01dbc1f329a95bc7e3b93224543d88ad5bdbd315 (patch) | |
tree | ceb527713554f506c537168e36a10452cd09ad10 /assets/canvas-runtime.js | |
parent | b9262c831952e77135b79c2de7c455d5e7ff0589 (diff) | |
parent | c37a876b373ddc7cb19277aaeaa6bb2d2d5a50ac (diff) | |
download | ninja-01dbc1f329a95bc7e3b93224543d88ad5bdbd315.tar.gz |
Merge branch 'master' into brushtool
Diffstat (limited to 'assets/canvas-runtime.js')
-rw-r--r-- | assets/canvas-runtime.js | 2998 |
1 files changed, 1536 insertions, 1462 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index ce2a15de..eeafaab6 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -17,7 +17,7 @@ NinjaCvsRt.initWebGl = function (rootElement, directory) { | |||
17 | } | 17 | } |
18 | } | 18 | } |
19 | //Creating data manager | 19 | //Creating data manager |
20 | cvsDataMngr = new NinjaCvsRt.CanvasDataManager(); | 20 | cvsDataMngr = Object.create(NinjaCvsRt.CanvasDataManager, {}); |
21 | //Loading data to canvas(es) | 21 | //Loading data to canvas(es) |
22 | cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory); | 22 | cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory); |
23 | }; | 23 | }; |
@@ -26,1024 +26,870 @@ NinjaCvsRt.initWebGl = function (rootElement, directory) { | |||
26 | // Class ShapeRuntime | 26 | // Class ShapeRuntime |
27 | // Manages runtime shape display | 27 | // Manages runtime shape display |
28 | /////////////////////////////////////////////////////////////////////// | 28 | /////////////////////////////////////////////////////////////////////// |
29 | NinjaCvsRt.CanvasDataManager = function () | 29 | NinjaCvsRt.CanvasDataManager = Object.create(Object.prototype, { |
30 | { | 30 | |
31 | this.loadGLData = function(root, valueArray, assetPath ) | 31 | loadGLData: { |
32 | { | 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 | } | 59 | var glRt = Object.create(NinjaCvsRt.GLRuntime, {}); |
60 | } | 60 | glRt.renderWorld(canvas, jObj, this._assetPath); |
61 | } | 61 | } |
62 | } | 62 | } |
63 | }; | 63 | } |
64 | 64 | } | |
65 | this.findCanvasWithID = function( id, elt ) | 65 | } |
66 | { | 66 | }, |
67 | var cid = elt.getAttribute( "data-RDGE-id" ); | 67 | |
68 | if (cid == id) return elt; | 68 | findCanvasWithID: { |
69 | 69 | value: function(id, elt) { | |
70 | if (elt.children) | 70 | var cid = elt.getAttribute( "data-RDGE-id" ); |
71 | { | 71 | if (cid == id) return elt; |
72 | var nKids = elt.children.length; | 72 | |
73 | for (var i=0; i<nKids; i++) | 73 | if (elt.children) |
74 | { | 74 | { |
75 | var child = elt.children[i]; | 75 | var nKids = elt.children.length; |
76 | var foundElt = this.findCanvasWithID( id, child ); | 76 | for (var i=0; i<nKids; i++) |
77 | if (foundElt) return foundElt; | 77 | { |
78 | } | 78 | var child = elt.children[i]; |
79 | } | 79 | var foundElt = this.findCanvasWithID( id, child ); |
80 | }; | 80 | if (foundElt) return foundElt; |
81 | }; | 81 | } |
82 | } | ||
83 | } | ||
84 | } | ||
85 | }); | ||
82 | 86 | ||
83 | /////////////////////////////////////////////////////////////////////// | 87 | /////////////////////////////////////////////////////////////////////// |
84 | // Class GLRuntime | 88 | // Class GLRuntime |
85 | // Manages runtime fora WebGL canvas | 89 | // Manages runtime fora WebGL canvas |
86 | /////////////////////////////////////////////////////////////////////// | 90 | /////////////////////////////////////////////////////////////////////// |
87 | NinjaCvsRt.GLRuntime = function ( canvas, jObj, assetPath ) | 91 | NinjaCvsRt.GLRuntime = Object.create(Object.prototype, { |
88 | { | ||
89 | /////////////////////////////////////////////////////////////////////// | 92 | /////////////////////////////////////////////////////////////////////// |
90 | // Instance variables | 93 | // Instance variables |
91 | /////////////////////////////////////////////////////////////////////// | 94 | /////////////////////////////////////////////////////////////////////// |
92 | this._canvas = canvas; | 95 | _canvas: { value: null, writable: true }, |
93 | this._context = null; | 96 | _context : { value: null, writable: true }, |
94 | //this._importStr = importStr; | 97 | //this._importStr = importStr; |
95 | this._jObj = jObj; | 98 | _jObj: { value: null, writable: true }, |
96 | 99 | ||
97 | this.renderer = null; | 100 | _renderer: { value: null, writable: true }, |
98 | this.myScene = null; | 101 | myScene: { value: null, writable: true }, |
99 | this.light = null; | 102 | light: { value: null, writable: true }, |
100 | this.light2 = null; | 103 | light2: { value: null, writable: true }, |
101 | this._rootNode = null; | 104 | _rootNode: { value: null, writable: true }, |
102 | 105 | ||
103 | this._firstRender = true; | 106 | _firstRender: { value: true, writable: true }, |
104 | this._initialized = false; | 107 | _renderCount: { value: -1, writable: true }, |
108 | _initialized: { value: false, writable: true }, | ||
105 | 109 | ||
106 | this._useWebGL = false; | 110 | _useWebGL: { value: false, writable: true }, |
107 | this._assetPath = undefined; | 111 | _assetPath: { value: undefined, writable: true }, |
108 | 112 | ||
109 | // view parameters | 113 | // view parameters |
110 | this._fov = 45.0; | 114 | _fov: { value: 45.0, writable: true }, |
111 | this._zNear = 0.1; | 115 | _zNear: { value: 0.1, writable: true }, |
112 | this._zFar = 100.0; | 116 | _zFar: { value: 100.0, writable: true }, |
113 | this._viewDist = 5.0; | 117 | _viewDist: { value: 5.0, writable: true }, |
114 | 118 | ||
115 | this.elapsed = 0; | 119 | elapsed: { value: 0, writable: true }, |
116 | 120 | ||
117 | this._aspect = canvas.width/canvas.height; | 121 | _aspect: { value: 1, writable: true }, |
118 | 122 | ||
119 | this._geomRoot = null; | 123 | //this._geomRoot = null; |
124 | _rootChildren: { value: [], writable: true }, | ||
120 | 125 | ||
121 | // all "live" materials | 126 | // all "live" materials |
122 | this._materials = []; | 127 | _materials: { value: [], writable: true }, |
128 | |||
129 | renderWorld: { | ||
130 | value: function(canvas, jObj, assetPath) { | ||
131 | this._materials = []; | ||
132 | this._rootChildren = []; | ||
133 | this._canvas = canvas; | ||
134 | this._aspect = this._canvas.width/this._canvas.height; | ||
135 | |||
136 | this._jObj= jObj; | ||
137 | |||
138 | // provide the mapping for the asset directory | ||
139 | if (assetPath) { | ||
140 | this._assetPath = assetPath.slice(); | ||
141 | if (this._assetPath[this._assetPath.length - 1] != '/') | ||
142 | this._assetPath += '/'; | ||
143 | } | ||
123 | 144 | ||
124 | // provide the mapping for the asset directory | 145 | if(this._assetPath !== undefined) { |
125 | if (assetPath) { | 146 | RDGE.globals.engine.setAssetPath(this._assetPath); |
126 | this._assetPath = assetPath.slice(); | 147 | } |
127 | if (this._assetPath[this._assetPath.length - 1] != '/') | ||
128 | this._assetPath += '/'; | ||
129 | } | ||
130 | 148 | ||
131 | if(this._assetPath !== undefined) { | 149 | // start RDGE or load Canvas 2D objects |
132 | RDGE.globals.engine.setAssetPath(this._assetPath); | 150 | if (jObj.scenedata) this._useWebGL = true; |
133 | } | 151 | if (this._useWebGL) |
152 | { | ||
153 | var id = this._canvas.getAttribute( "data-RDGE-id" ); | ||
154 | this._canvas.rdgeid = id; | ||
155 | RDGE.globals.engine.registerCanvas(this._canvas, this); | ||
156 | RDGE.RDGEStart( this._canvas ); | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | this.loadScene(); | ||
161 | } | ||
162 | } | ||
163 | }, | ||
134 | 164 | ||
135 | /////////////////////////////////////////////////////////////////////// | 165 | /////////////////////////////////////////////////////////////////////// |
136 | // accessors | 166 | // accessors |
137 | /////////////////////////////////////////////////////////////////////// | 167 | /////////////////////////////////////////////////////////////////////// |
138 | this.getZNear = function() { return this._zNear; }; | 168 | getZNear: { value: function() { return this._zNear; }}, |
139 | this.getZFar = function() { return this._zFar; }; | 169 | getZFar: { value: function() { return this._zFar; }}, |
140 | this.getFOV = function() { return this._fov; }; | 170 | getFOV: { value: functio |