Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
If, like me, your iDevice is too old for ARKit...
-
In this part of the code:
indexes = [3,3,3,3,3,3,3,3, 0, 1, 2, 2, 3, 0, 3, 4, 0, 4, 1, 0, 1, 5, 2, 2, 5, 3, 3, 5, 4, 4, 5, 1]
what does this part do:
[3,3,3,3,3,3,3,3,
I am trying to make a cube and I have four sides completed, but I can't cover the top and bottom because of these 3's I think.
-
See
@cvps code used polygon primatives -- so the data first has list of polygon lengths, then list of vertices making each face.
If you want to make your cube out of squares, you would need 8 vertices (cvp has 6), then if you ordered the vertices going clockwise in the first plane, then clockwise in the second plane, then you would have
[4,4,4,4,4,4, # six faces, each has 4 sides
0,3,2,1# bottom face
1,2,6,5,# right face
2,3,7,6# back face
3,0, 4,7# left face
0,1,5,4 # front face
4,5,6,7]Depending on how your order your vertices, it might be a little different for you.
You'll want to make sure you provide indexes in a clockwise order for each face as viewed from outside, otherwise some of the faces will be considered inside faces, which might screw with lighting/shading or applying textures.
-
@JonB said:
[4,4,4,4,4,4, # six faces, each has 4 sides
0,3,2,1# bottom face
1,2,6,5,# right face
2,3,7,6# back face
3,0, 4,7# left face
0,1,5,4 # front face
4,5,6,7]So I used the new index array you provided on the cube defined by these vertices:
verts = [ SCNVector3(0, 0, 0), SCNVector3(0.05, 0, 0), SCNVector3(0.05, 0, 0.05), SCNVector3(0, 0, 0.05), SCNVector3(0, 0.05, 0), SCNVector3(0.05, 0.05, 0), SCNVector3(0.05, 0.05, 0.05), SCNVector3(0, 0.05, 0.05)]
and the result for me is triangles (covering half the face) instead of full square faces on the cube. Is there anything else I should change in cvp's original code to allow the new index array to work?
-
@vignesh said:
0,3,2,1# bottom face
It seems that some lines have a comma missing
0,3,2,1, # bottom face
-
@vignesh and
#for i in range(0,8): # j = 8 + i*3 for i in range(0,6): j = 6 + i*4 #indexes2 = [indexes[j],indexes[j+1],indexes[j+2]] indexes2 = [indexes[j],indexes[j+1],indexes[j+2],indexes[j+3]]
-
@vignesh and
#e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,4,8,sizeof(c_int)) e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,4,6,sizeof(c_int))
-
@vignesh but geometry2 is still composed of triangles due to
e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,4,8,sizeof(c_int))
-
@vignesh it seems that if you want different colors per face, you have to play with triangles.
Then you could generate two triangles per square face, both with same color, likefor i in range(0,6): j = 6 + i*4 # first triangle of square face indexes2 = [indexes[j],indexes[j+1],indexes[j+2]] indexes_array2 = (c_int*len(indexes2))(*indexes2) datIndexes2 = ObjCClass('NSData').dataWithBytes_length_(indexes_array2,sizeof(indexes_array2)) e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes2,0,1,sizeof(c_int)) e2.append(e) rgb = getrgb(colors[i]) r,g,b = tuple(c/255.0 for c in rgb) Material = SCNMaterial.material() Material.contents = ObjCClass('UIColor').colorWithRed_green_blue_alpha_(r,g,b,1.0) Materials.append(Material) # 2nd triangle to create a square face indexes2 = [indexes[j+2],indexes[j+3],indexes[j]] indexes_array2 = (c_int*len(indexes2))(*indexes2) datIndexes2 = ObjCClass('NSData').dataWithBytes_length_(indexes_array2,sizeof(indexes_array2)) e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes2,0,1,sizeof(c_int)) e2.append(e) # with same color Materials.append(Material) geometry2 = ObjCClass('SCNGeometry').geometryWithSources_elements_([s],e2) geometry2.setMaterials_(Materials) geometry2_node = SCNNode.nodeWithGeometry_(geometry2)
-
Thanks so much, @cvp this makes sense and I just tested it myself and it works
-
-
@pulbrich awesome, thank you I'll check it out!