@tt_su
So far I’ve been copying the example provided in the xml_to_skp importer, so using:
SUGeometryInputCreate
SUGeometryInputAddVertex
SULoopInputCreate
SULoopInputAddVertexIndex
SULoopInputEdgeSetHidden
SULoopInputEdgeSetSmooth
SULoopInputEdgeSetSoft
SUGeometryInputAddFace
SUGeometryInputFaceSetFrontMaterial
SUEntitiesFill
SUGeometryInputRelease
in that order.
I’m really pleased with performance so far, and I’ve got texture mapping, basic colours, vertex colours (applying average colour to the face), and the matrix transforms all implemented since yesterday! Next stage is to implement component definitions for those nodes that repeat themselves, and afterwards I will try to find a way to distribute the DLL.
For the ruby code, I can’t use PolygonMesh, as I need to be able to track each face added to apply the UV coordinates, and even if it is a basic colour mesh, I still need to track each face for determining which edges need to be smooth. So that means using add_face.
This is the ruby code that I wrote for the importer, I’m sure a professional developer will be horrified but it works. As you note, add_face triggers the remerge, so for massive amounts of geometry it is the reason the import gets progressively slower - some imports taking days to complete. Better add to the 2018 wish-list for a begin-import end-import pair of ruby API functions for turning this off.
i = 0
while i < indices.length
points = []
normals = []
pt_array = []
indice_array = []
n = nil
j = 0
while j < 3
index = indices[i+j]
indice_array.push(index)
pt = t_positions[index]
if normal != nil
n = normal[index]
normals.push(n)
end
points.push(pt)
if(texcoord != nil)
t = texcoord[index]
pt_array.push(pt)
pt_array.push(Geom::Point3d.new(t[0],1.0-t[1],0.0))
end
j = j + 1
end
if colors != nil
material = add_material(nil, colors[i][0], colors[i][1], colors[i][2], colors[i][3], nil)
end
begin
face = entities.add_face points
# store the indice array for this face
face_indices[face] = indice_array
if n != nil
# flip the new face is it is not facing the correct direction according to the provided normals
dot = face.normal.dot n
if dot < 0.0
face.reverse!
end
end
if material != nil
face.material = material
if is_double_sided
face.back_material = material
end
if(texcoord != nil)
begin
face.position_material face.material, pt_array, true
if is_double_sided
face.position_material face.back_material, pt_array, false
end
rescue
end
end
end
rescue #=> e
#puts 'Error - face could not be created'
# todo: count the number of faces that could not be created
end
i = i + 3
end