Dissecting R3D:
A. import .obj file
r3d_load_OBJ loads an .obj file and stores it's vertices in an array: world[1]["model"]
world[1] is just one of near infinite number of models that could be stored...
after we change things because:
set the curmodel of this stack to world[1]["model"]
Only holds one model in the stack properties, the rest would be floating around in memory in the world array and vanish when you restart the application or stack.
Let's look at a cube.obj file that R3D can read:
# Blender 3.4.1
# www.blender.org
mtllib cube.mtl
o Cube
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 1.000000 -1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 -1.000000 -1.000000
vn -0.0000 -0.0000 1.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vn -0.0000 1.0000 -0.0000
vn -1.0000 -0.0000 -0.0000
vt 0.625000 0.500000
vt 0.375000 0.500000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.875000 0.500000
vt 0.625000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.250000
vt 0.875000 0.750000
vt 0.625000 1.000000
vt 0.625000 0.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.125000 0.750000
s 0
usemtl Material
f 1/1/1 5/5/1 7/9/1 3/3/1
f 4/4/2 3/3/2 7/10/2 8/12/2
f 8/13/3 7/11/3 5/6/3 6/8/3
f 6/7/4 2/2/4 4/4/4 8/14/4
f 2/2/5 1/1/5 3/3/5 4/4/5
f 6/8/6 5/6/6 1/1/6 2/2/6
Parts of the .obj file:
Vertices (
v): These are like the corners of a 3D shape. Each vertex has three numbers (X, Y, Z) representing its position in 3D space.
Normals (
vn): Normals help define the direction a surface is facing.
Texture Coordinates (
vt): These tell us how to map a 2D image (like a texture) onto the 3D shape.
Faces (
f): Faces connect vertices to create surfaces. They define which vertices form a triangle or polygon.
Materials (
mtllib and
usemtl): Materials describe how the surface looks (like color, shininess, or texture). They’re linked to specific parts of the object.
Note the end of the .Obj file with the lines that begin with f and are loaded with slashes:
Let’s break down the first face line:
f 1/1/1 5/5/1 7/9/1 3/3/1.
Vertices (v):
Each number before the slash represents a vertex index.
In this line, we have four vertex indices: 1, 5, 7, and 3.
f 1/1/1 5/5/1 7/9/1 3/3/1.
--- The face connects the vertices (1, 5, 7, and 3) to form a polygon.
R3D isn't using the other properties but maybe some modifications could be applied based on the values if read.
Texture Coordinates (vt):
The number after the first slash (e.g., /1) represents the texture coordinate index.
Normals (vn):
The number after the second slash (e.g., /1/1) represents the normal index.
--- Everything in R3D faces away from the center of the object, toward the camera
My 'ship' design in the image above has Material properties like this:
usemtl Wing
f 26/40/2 25/39/2 27/41/2 28/42/2
f 30/46/8 31/48/8 32/50/8 29/44/8
Theoretically with some additional scripting we should be able to isolate those and make the materials allow us to modify the vertices in the IDE. For instance grab the 'Wing' vertices and apply scale or position adjustments to just those vertices to reshape the wing.
Each hideous line is just a rectangle polygon, however with how R3D draws things as a big pile of graphics, I'm not sure it will update everything under that modified polygon...we'll have to see.