annotate webGL/dandy/resources/makePanel.js~ @ 25:e8c591a01a8e

update makePanel
author NOBUYASU Oshiro
date Fri, 05 Nov 2010 08:40:26 +0900
parents 61febc94fa62
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
1 function parsePanel( url ) {
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
2 var http = new JKL.ParseXML( url );
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
3 var data = http.parse()["OBJECT-3D"];
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
4 var xmlObj = new Object();
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
5
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
6 if (data["surface"][0]) {
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
7 for (var i in data["surface"]) {
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
8 var obj = xmlObj[data["surface"][i]["name"]] = new Object();
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
9 obj.vertex = splitVector(data["surface"][i]["coordinate"]);
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
10 obj.normal = splitVector(data["surface"][i]["normal"]);
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
11 obj.texCoords = splitVector(data["surface"][i]["texture"]);
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
12 obj.model = splitVector(data["surface"][i]["model"]);
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
13 var xmlObjImage = data["surface"][i]["image"];
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
14 obj.image = 'data:image/png;base64,'+xmlObjImage["#text"];
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
15 }
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
16 } else {
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
17 var obj = xmlObj[data["surface"]["name"]] = new Object();
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
18 obj.vertex = splitVector(data["surface"]["coordinate"]);
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
19 obj.normal = splitVector(data["surface"]["normal"]);
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
20 obj.texCoords = splitVector(data["surface"]["texture"]);
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
21 obj.model = splitVector(data["surface"]["model"]);
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
22 var xmlObjImage = data["surface"]["image"];
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
23 obj.image = 'data:image/png;base64,'+xmlObjImage["#text"];
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
24 }
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
25
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
26 return xmlObj;
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
27 }
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
28
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
29 function splitVector(str) {
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
30 // return str.replace(/^\s+/g, "").replace(/\s+/g, " ").split(" ");
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
31 return str.replace(/^\s+/g, "").replace(/\s+/g, " ").replace(/\s$/g, "").split(" ");
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
32 }
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
33
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
34 function makeXmlObj(ctx, xmlObj)
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
35 {
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
36
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
37 var model = new Object();
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
38 model.x = parseFloat(xmlObj.model[0]);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
39 model.y = parseFloat(xmlObj.model[1]);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
40 model.z = parseFloat(xmlObj.model[2]);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
41
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
42 var geometryData = [ ];
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
43 var normalData = [ ];
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
44 var texCoordData = [ ];
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
45 var indexData = [ ];
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
46 var index = 0;
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
47 var xmax = 0;
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
48 var xmin = 0;
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
49 var ymax = 0;
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
50 var ymin = 0;
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
51
25
e8c591a01a8e update makePanel
NOBUYASU Oshiro
parents: 12
diff changeset
52
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
53 for(var i=0; xmlObj.vertex[i]; i+=3){
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
54 geometryData.push(parseFloat(xmlObj.vertex[i]) - model.x);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
55 geometryData.push(parseFloat(xmlObj.vertex[i+1]) - model.y);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
56 geometryData.push(parseFloat(xmlObj.vertex[i+2]) - model.z);
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
57 if ( (i % 3) == 0) {
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
58 indexData.push(index);
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
59 index++;
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
60 }
12
61febc94fa62 upload dandy4.html,new xmlFile
NOBUYASU Oshiro
parents: 7
diff changeset
61 //オブジェクトの最大・最小のx,y座標を求める
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
62 if ( i == 0) {
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
63 xmax = geometryData[0];
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
64 xmin = geometryData[0];
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
65 ymax = geometryData[1];
12
61febc94fa62 upload dandy4.html,new xmlFile
NOBUYASU Oshiro
parents: 7
diff changeset
66 ymin = geometryData[1];
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
67 }
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
68 if ( i > 0 ){
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
69 xmax = Math.max( xmax, geometryData[i]);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
70 xmin = Math.min( xmin, geometryData[i]);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
71 ymax = Math.max( ymax, geometryData[i+1]);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
72 ymin = Math.min( ymin, geometryData[i+1]);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
73 }
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
74 }
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
75 for(i=0; xmlObj.texCoords[i]; i++){
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
76 texCoordData.push(parseFloat(xmlObj.texCoords[i]));
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
77
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
78 }
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
79 for(i=0; xmlObj.normal[i]; i+=3){
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
80 normalData.push(parseFloat(xmlObj.normal[i]) - model.x);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
81 normalData.push(parseFloat(xmlObj.normal[i+1]) - model.y);
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
82 normalData.push(parseFloat(xmlObj.normal[i+2]) - model.z);
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
83 }
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
84
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
85 var retval = { };
12
61febc94fa62 upload dandy4.html,new xmlFile
NOBUYASU Oshiro
parents: 7
diff changeset
86 //オブジェクトの横幅,縦幅を求める
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
87 retval.w = xmax - xmin;
12
61febc94fa62 upload dandy4.html,new xmlFile
NOBUYASU Oshiro
parents: 7
diff changeset
88 retval.h = ymax - ymin;
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
89
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
90 retval.normalObject = ctx.createBuffer();
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
91 ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.normalObject);
25
e8c591a01a8e update makePanel
NOBUYASU Oshiro
parents: 12
diff changeset
92 ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(normalData), ctx.STATIC_DRAW);
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
93
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
94 retval.texCoordObject = ctx.createBuffer();
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
95 ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.texCoordObject);
25
e8c591a01a8e update makePanel
NOBUYASU Oshiro
parents: 12
diff changeset
96 ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(texCoordData), ctx.STATIC_DRAW);
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
97
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
98 retval.vertexObject = ctx.createBuffer();
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
99 ctx.bindBuffer(ctx.ARRAY_BUFFER, retval.vertexObject);
25
e8c591a01a8e update makePanel
NOBUYASU Oshiro
parents: 12
diff changeset
100 ctx.bufferData(ctx.ARRAY_BUFFER, new Float32Array(geometryData), ctx.STATIC_DRAW);
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
101
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
102 retval.numIndices = indexData.length;
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
103 retval.indexObject = ctx.createBuffer();
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
104 ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, retval.indexObject);
25
e8c591a01a8e update makePanel
NOBUYASU Oshiro
parents: 12
diff changeset
105 ctx.bufferData(ctx.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData), ctx.STREAM_DRAW);
3
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
106
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
107 return retval;
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
108 }
10344afb38a6 upload dandy
NOBUYASU Oshiro
parents:
diff changeset
109
7
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
110 function makeOrthoPara(left, right, bottom, top)
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
111 {
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
112 this.left = left;
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
113 this.right = right;
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
114 this.bottom = bottom;
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
115 this.top = top;
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
116 return this;
4343c1feedb5 upload boss.js xmlAlpha file
NOBUYASU Oshiro
parents: 3
diff changeset
117 }