#javascript #three.js
#javascript #three.js
Вопрос:
я пытаюсь прочитать файл и сохранить значения, разделенные запятыми, в объекты в javascript. я пытался вот так … ?
здесь я считываю текстовый файл в переменную out, разделяю его и сохраняю как объекты.. является ли это правильным способом присвоения значения объектам
<script type="text/javascript">
var patternDetails = [
{
patternIndex :0,
patternLineCount : 0,
patternPointCount : 0,
firstPtIndx:[
{
i:0
}
],
patternPointName:[
{
i=0
}
],
patternPoint: [
{
X:0,
Y:0,
Z:0
}
],
secondPtIndx:[
{
i:0
}
],
}
]
patternDetails=new Array();// Is this object creation correct ?
function checkFileAPI() {
if (window.File amp;amp; window.FileReader amp;amp; window.FileList amp;amp; window.Blob) {
reader = new FileReader();
return true;
} else {
alert('The File APIs are not fully supported by your browser. Fallback required.');
return false;
}
}
/**
* read text input
*/
function readText(filePath) {
var output = ""; //placeholder for text output
if(filePath.files amp;amp; filePath.files[0]) {
reader.onload = function (e) {
output = e.target.result;
displayContents(output.split("n"));
};//end onload()
reader.readAsText(filePath.files[0]);
}//end if html5 filelist support
/*else if(ActiveXObject amp;amp; filePath) { //fallback to IE 6-8 support via ActiveX
try {
reader = new ActiveXObject("Scripting.FileSystemObject");
var file = reader.OpenTextFile(filePath, 1); //ActiveX File Object
//output = file.ReadAll(); //text contents of file
file.Close(); //close file "input stream"
displayContents(output);
} catch (e) {
if (e.number == -2146827859) {
alert('Unable to access local files due to browser security settings. '
'To overcome this, go to Tools->Internet Options->Security->Custom Level. '
'Find the setting for "Initialize and script ActiveX controls not marked as safe" and change it to "Enable" or "Prompt"');
}
}
}
else { //this is where you could fallback to Java Applet, Flash or similar
return false;
}*/
return true;
}
/**
* display content using a basic HTML replacement
*/
function displayContents(txt)
{
var ver =txt[4].split(",");
var i=0;
var z=0;
patternDetails[i].patternIndex=new patternIndex(ver[ z]);// can i do this . is this is correct wary?
patternDetails[i].patternLineCount=new patternLineCount(ver[ z]);
patternDetails[i].patternPointCount=new patternPointCount(ver[ z]);
for(var b=0;b<patternDetails[i].patternLineCount;b )
{
patternDetails[i].firstPtIndx[b]=new firstPtIndx[b](ver[ z]);
patternDetails[i].patternPointName[patternDetails[i].firstPtIndx[b]]= new patternPointName(ver[ z]);
patternDetails[i].patternPoint[patternDetails[i].firstPtIndx[b]].X= new patternPoint(ver[ z]);
patternDetails[i].patternPoint[patternDetails[i].firstPtIndx[b]].Y= new patternPoint(ver[ z]);
patternDetails[i].patternPoint[patternDetails[i].firstPtIndx[b]].Z= new patternPoint(ver[ z]);
patternDetails[i].secondPtIndx[b]=new firstPtIndx[b](ver[ z]);
patternDetails[i].patternPointName[patternDetails[i].secondPtIndx[b]]= new patternPointName(ver[ z]);
patternDetails[i].patternPoint[patternDetails[i].secondPtIndx[b]].X= new patternPoint(ver[ z]);
patternDetails[i].patternPoint[patternDetails[i].secondPtIndx[b]].Y= new patternPoint(ver[ z]);
patternDetails[i].patternPoint[patternDetails[i].secondPtIndx[b]].Z= new patternPoint(ver[ z]);
}
var p= patternDetails[0].patternPoint[patternDetails[0].firstPtIndx[0]].X;
var q= patternDetails[0].patternPoint[patternDetails[0].firstPtIndx[0]].Y;
var r= patternDetails[0].patternPoint[patternDetails[0].firstPtIndx[0]].Z;
DRAW_SP(p,q,r);
var el = document.getElementById('info');
el.innerHTML = ver; //display output in DOM
}
файл tlr, который я читаю, является
//TLR:Format:Vishama Creations:v1.0
//Pattern_no,Pattern_NumLines,FrstPointIndx,PointName,aX,aY,aZ,bX,bY,bZ,SecondPointIndex,PointName,aX,aY,aZ,bX,bY,bZ
2
L
,0,23,24,0,f:p0,0.008,0.235,0.051,1,f:p1,0.008,0.147,0.085,10,f:p10,0.060,0.053,0.109,11,f:p11,0.108,0.050,0.094,12,f:p12,-0.045,0.053,0.111,13,f:p13,-0.091,0.049,0.090,14,f:p14,0.063,-0.049,0.095,15,f:p15,0.081,-0.050,0.082,15,f:p15,0.081,-0.050,0.082,16,f:p16,0.081,-0.050,0.082,17,f:p17,-0.048,-0.049,0.096,18,f:p18,-0.063,-0.050,0.084,18,f:p18,-0.063,-0.050,0.084,19,f:p19,-0.063,-0.050,0.084,1,f:p1,0.008,0.147,0.085,2,f:p2,0.008,0.051,0.102,1,f:p1,0.008,0.147,0.085,4,f:p4,-0.049,0.156,0.108,1,f:p1,0.008,0.147,0.085,7,f:p7,0.065,0.156,0.107,2,f:p2,0.008,0.051,0.102,10,f:p10,0.060,0.053,0.109,2,f:p2,0.008,0.051,0.102,12,f:p12,-0.045,0.053,0.111,2,f:p2,0.008,0.051,0.102,3,f:p3,0.008,-0.049,0.106,3,f:p3,0.008,-0.049,0.106,14,f:p14,0.063,-0.049,0.095,3,f:p3,0.008,-0.049,0.106,17,f:p17,-0.048,-0.049,0.096,4,f:p4,-0.049,0.156,0.108,21,f:p21,-0.055,0.181,0.084,4,f:p4,-0.049,0.156,0.108,5,f:p5,-0.105,0.151,0.095,5,f:p5,-0.105,0.151,0.095,20,f:p20,-0.103,0.165,0.082,5,f:p5,-0.105,0.151,0.095,6,f:p6,-0.118,0.146,0.082,7,f:p7,0.065,0.156,0.107,22,f:p22,0.071,0.179,0.083,7,f:p7,0.065,0.156,0.107,8,f:p8,0.120,0.151,0.094,8,f:p8,0.120,0.151,0.094,23,f:p23,0.119,0.163,0.083,8,f:p8,0.120,0.151,0.094,9,f:p9,0.133,0.147,0.084
Комментарии:
1. 1) будьте конкретны. Что не работает? 2) создайте jsfiddle. net и включить примеры из текстового файла
2. Итак, в чем конкретно заключаются проблемы? У вас есть все, что вам нужно
3. мне нужно прочитать эти значения из файла и построить строку с учетом значений x, y, z
4. Да, и что вас останавливает?
5. добавление значений в объектные литералы останавливает меня..