Question

Before I get too deep into a rabbit hole full of quicksand, here's a subset of the text in an OBJ file (737 aircraft in this case)

v -1.684813 -4.962262 2.184269
v -1.684813 -4.672744 2.090231
v -1.684813 -4.469102 1.864027
v -1.684813 -4.405789 1.566230
v -1.684813 -4.499885 1.276771
v -1.684813 -4.726089 1.073071
g engines
f 13 2 1
f 13 14 2
f 14 3 2
f 14 15 3
f 15 4 3
f 15 16 4
f 16 5 4
f 16 17 5
f 17 6 5
g main_body
f 1362 1380 1378
f 1362 1364 1380
f 1360 1362 1378
f 1320 1364 1362

And so on for several other components.
Edit - now that (stupid me) I found the OBJ file definition at Wikipedia and other places, at least I know that v x y z are vertex coordinates and f a b c identify the vertices which go into building that part. So I guess my question is reduced to: has anyone written an OBJ - specific translator compatible with rgl or other 3D libraries?

Was it helpful?

Solution

mdsumner is correct. For those who might care, here are the basic steps.

1) break each element (e.g., "engine") into a separate array. 2) build a matrix of x,y,z vertices compatible with coords.3d (see rgl documentation) by reading the referenced vertex numbers in each 'engine' row and retrieving the coordinate sets from the "v" set of vertex coordinates. 3) plot it.

For an element with 896 rows (i.e. 896 triangles making up the item),

trieng<-matrix(nrow=896*3,ncol=3)
for (j in 1:896) {
    trieng[(1+3*(j-1)):(3+3*(j-1)),1:3] <- v737[engine737[j,1:3],1:3]
    }

Where I've removed the first column (containing "v", "f") from my data matrices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top