Mercurial > hg > Members > e085711
changeset 2:be36da713ffd
update makeXmlObj.js
author | NOBUYASU Oshiro |
---|---|
date | Mon, 31 May 2010 03:25:15 +0900 |
parents | 94c790cbd930 |
children | 10344afb38a6 |
files | webGL/test/resources/makeXmlObj.js |
diffstat | 1 files changed, 19 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/webGL/test/resources/makeXmlObj.js Mon May 31 03:24:30 2010 +0900 +++ b/webGL/test/resources/makeXmlObj.js Mon May 31 03:25:15 2010 +0900 @@ -2,24 +2,30 @@ var http = new JKL.ParseXML( url ); var data = http.parse()["OBJECT-3D"]; var xmlObj = new Object(); + if (data["surface"][0]) { for (var i in data["surface"]) { var obj = xmlObj[data["surface"][i]["name"]] = new Object(); obj.vertex = splitVector(data["surface"][i]["coordinate"]); obj.normal = splitVector(data["surface"][i]["normal"]); obj.texCoords = splitVector(data["surface"][i]["texture"]); + var xmlObjImage = data["surface"][i]["image"]; + obj.image = 'data:image/png;base64,'+xmlObjImage["#text"]; } } else { var obj = xmlObj[data["surface"]["name"]] = new Object(); - obj.vertex = splitVector(data["surface"]["coordinate"]); - obj.normal = splitVector(data["surface"]["normal"]); - obj.texCoords = splitVector(data["surface"]["texture"]); + obj.vertex = splitVector(data["surface"]["coordinate"]); + obj.normal = splitVector(data["surface"]["normal"]); + obj.texCoords = splitVector(data["surface"]["texture"]); + var xmlObjImage = data["surface"]["image"]; + obj.image = 'data:image/png;base64,'+xmlObjImage["#text"]; } return xmlObj; } function splitVector(str) { - return str.replace(/^\s+/g, "").replace(/\s+/g, " ").split(" "); + // return str.replace(/^\s+/g, "").replace(/\s+/g, " ").split(" "); + return str.replace(/^\s+/g, "").replace(/\s+/g, " ").replace(/\s$/g, "").split(" "); } function makeXmlObj(ctx, xmlObj) @@ -28,27 +34,21 @@ var normalData = [ ]; var texCoordData = [ ]; var indexData = [ ]; - var i = 0; - var j = 0; - var k = 0; - while (xmlObj.vertex[i]) { + var index = 0; + for(var i=0; xmlObj.vertex[i]; i++){ geometryData.push(parseFloat(xmlObj.vertex[i])); if ( (i % 3) == 0) { - indexData.push(k); - k++; + indexData.push(index); + index++; } - i++; } - k = 0; - while (xmlObj.texCoords[k]) { - texCoordData.push(parseFloat(xmlObj.texCoords[k])); - k++; + for(i=0; xmlObj.texCoords[i]; i++){ + texCoordData.push(parseFloat(xmlObj.texCoords[i])); } - while (xmlObj.normal[j]) { - normalData.push(parseFloat(xmlObj.normal[j])); - j++; + for(i=0; xmlObj.normal[i]; i++){ + normalData.push(parseFloat(xmlObj.normal[i])); } - + var retval = { }; retval.normalObject = ctx.createBuffer();