0
$\begingroup$

i created a mesh monkey object from blender option. On the screen, you see the spreadsheet which only give xyz values and i trying to figure where are the ijk. The reason i want these values is to make a 3d mesh in plotly .enter image description here

On the second screenshot, I've exported the spreadsheet to be use in plotly studio and you see how the monkey look like with just the XYZ values which does not look right in plotly studio because it's missing the ijk values.enter image description here

I was wondering if blenders have the option to view/export ijk data so that the model would look like the same as in plotly studio?https://computergraphics.stackexchange.com/questions/8960/what-are-the-i-j-k-components-of-a-3d-mesh-on-plot-ly-online

$\endgroup$

1 Answer 1

2
$\begingroup$

Get indices of mesh

  1. Go to Edit mode, select All and make Triangulate Faces

enter image description here

  1. Exit Edit mode >To Object mode

  2. Run script

enter image description here

import bpy

obj = bpy.context.object
mesh = obj.data

print("coor: ")
for vert in mesh.vertices:
    xyz = vert.co.xyz
    print(f"{xyz[0]}, {xyz[1]}, {xyz[2]}")
print("")

print("indices: ")
for face in mesh.polygons:
    print(f"{face.vertices[0]}, {face.vertices[1]}, {face.vertices[2]}")
print("")
  1. Open console

enter image description here

enter image description here

Export to csv

import bpy

outputFile = 'C:/yourlocation/list.csv'

obj = bpy.context.object
mesh = obj.data

coor = []
for vert in mesh.vertices:
    xyz = vert.co.xyz
    coor.append(f"{xyz[0]},{xyz[1]},{xyz[2]}")

indices = []
for face in mesh.polygons:
    indices.append(f"{face.vertices[0]},{face.vertices[1]},{face.vertices[2]}")

line = ["X,Y,Z,I,J,K\n"]
if len(indices) >= len(coor):
    for i, s in enumerate(coor):
        line.append(f"{s},{indices[i]}\n")
    for i in range(len(coor), len(indices)):
        line.append(f",,,{indices[i]}\n")
else:
    for i, s in enumerate(indices):
        line.append(f"{coor[i]},{s}\n")
    for i in range(len(indices), len(coor)):
        line.append(f"{coor[i]}\n")

f = open(outputFile, 'w')
f.writelines(line)
f.close()

enter image description here

$\endgroup$
2
  • $\begingroup$ Really impressive stuff. Do you if there is a possible way to export the indices values to a csv file? The only way i manage to do it is to copy and paste the command prompt onto spreadsheet and use data - text to columns, delimiter command - finish. This will separate each value into a separate column. $\endgroup$
    – user146660
    Commented Apr 18, 2022 at 3:41
  • $\begingroup$ Yes, it can. A write a new script for you. $\endgroup$
    – X Y
    Commented Apr 18, 2022 at 4:39

You must log in to answer this question.