Thank you!
ok, I can save the points as csv.
saving this
But when I load it, it’s totally distorted.
loading this
(looks like correct vertices in the triangles but wrong stitches)
Explanation
(only code snippets, code is too long)
The initial saved PShape has no vertexes, but 1200 children, each 3 vertexes.
Saving, the generated csv, in the csv, each line holds 3 PVectors (3D).
How do I save?
void makeMarbleTrack() {
// JCSG code:
PShape csgResult;
// red marble track
CSG cubeMinusSphere = defineRedCSG();
// staple red
csgResult = CSGToPShape(cubeMinusSphere, 45, color(255, 0, 0)); // red marble track
list.add(csgResult);
// ----------------------------------------------------------------------------------
// get data and SAVE
PShape psTest=list.get(0);
int count = psTest.getChildCount();
println("children "
+ count);
int count2 = psTest.getVertexCount();
println("vertex count "
+ count2
+"\n--------------------------------");
String[] listString = new String[count];
for (int i=0; i<count; i++) {
PShape child = psTest.getChild(i);
int count3 = child.getChildCount();
// println("children " + count3);
int count4 = child.getVertexCount();
// println("child vertex count " + count4);
// for each triangle we want to have three PVectors in ONE line for csv
String temp="";
for (int i2 = 0; i2 < child.getVertexCount(); i2++) {
PVector pv = child.getVertex(i2);
temp += getStringPV(pv)+","; // !!!!!!!!!!!!!
}//for
listString[i] = temp;
}//for
println("\n--------------------------------");
saveStrings("list1.csv", listString);
for (String s1 : listString) {
print (s1, ";");
}
println("\n--------------------------------");
....
}
....
String getStringPV(PVector pv) {
return
pv.x +","+
pv.y +","+
pv.z ;
}
When loading BOOM! all goes wrong
=====================================================
Loading 1 :
So 1st I tried load and GROUP and then add 1200 children using addChild
void makeMarbleTrack() {
// JCSG code:
PShape csgResult;
csgResult = createShape(GROUP);
String[] loadedFile = loadStrings("list1.csv"); // !!!!
for (String s1 : loadedFile) {
println (s1, ";");
PShape temp=getShapeFromString(s1); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
csgResult.addChild(temp);
}//for
list.add(csgResult);
// ----------------------------------------------------------------------------------
PShape getShapeFromString(String s_) {
// make one line (String) with 3 3D PVectors to a PShape (triangle)
PShape temp = createShape();
String[] items = split(s_, ",");
// error?
if (items.length<9) {
exit();
return null;
}
temp.beginShape(TRIANGLE);
temp.noStroke();
temp.fill(255, 0, 0);
temp.vertex(float(items[0]), float(items[1]), float(items[2]));
temp.vertex(float(items[3]), float(items[4]), float(items[5]));
temp.vertex(float(items[6]), float(items[7]), float(items[8]));
temp.endShape(); // CLOSE ???
return
temp;
}
Loading 2 :
Next TRY TRIANGLE_STRIP
Triangle-strip
void makeMarbleTrack() {
// JCSG code:
PShape csgResult;
csgResult = createShape();
csgResult.noStroke();
csgResult.fill(255, 0, 0);
// NEW
csgResult.beginShape(TRIANGLE_STRIP); // TRIANGLE_STRIP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
csgResult.noStroke();
csgResult.fill(255, 0, 0);
String[] loadedFile = loadStrings("list1.csv");
for (String s1 : loadedFile) {
String[] items = split(s1, ",");
csgResult.vertex(float(items[0]), float(items[1]), float(items[2]));
csgResult.vertex(float(items[3]), float(items[4]), float(items[5]));
csgResult.vertex(float(items[6]), float(items[7]), float(items[8]));
}//for
csgResult.endShape();
list.add(csgResult);
// ----------------------------------------------------------------------------------
}
Also very bad.
Please help.