4
$\begingroup$

Here's the output of a 3D scan of a bike, I need to render it in color with the texture file provided. Here are the files:

texture = CloudGet["https://www.wolframcloud.com/obj/320b51fd-8cc3-4dc9-9610-591e25096e3b"] (*Import["textured_ 0_v2.jpg"]*)
objTable = CloudGet["https://www.wolframcloud.com/obj/71483c49-eca5-425b-a251-29e112f2adde"] (*Import["~/3Ddata.obj", "Table"]*)

I can import the obj, but I need to import the texture too:

Import["3Ddata.obj"]

enter image description here

$\endgroup$
0

1 Answer 1

8
$\begingroup$

You could manually import it and construct Graphics3D:

rawobj = 
  Association[
   Reap[Cases[
      objTable, {t : "v" | "vt" | "f" | "vn", rest__} :> 
       If[t === "f", 
        Sow[Transpose[(ToExpression@StringSplit[#, "/"] & /@ {rest})],
          t], Sow[{rest}, t]]], {"v", "vt", "vn", "f"}, Rule][[2]]];

(*texture = Import["textured_0_v2.jpg"];*)

Graphics3D[
 GraphicsComplex[
  rawobj["v"], {Texture[texture], EdgeForm[], 
   Polygon[rawobj["f"][[All, 1]], 
    VertexTextureCoordinates -> (rawobj["vt"][[#]] & /@ 
       rawobj["f"][[All, 2]]), 
    VertexNormals -> rawobj["vn"][[#]] & /@ rawobj["f"][[All, 3]]]}]]

enter image description here If you want to use VertexColors, then

rules = AssociationThread[
   Flatten[rawobj["f"][[All, 1]]] -> Flatten[rawobj["f"][[All, 2]]]];
vcolors = 
  ImageValue[texture, 
   rawobj["vt"][[Range[Length[rawobj["v"]]] /. rules, ;; 2]], 
   DataRange -> {{0, 1}, {0, 1}}];

Graphics3D[
 GraphicsComplex[
  rawobj["v"], {EdgeForm[], 
   Polygon[rawobj["f"][[All, 1]], 
    VertexNormals -> rawobj["vn"][[#]] & /@ rawobj["f"][[All, 3]]]}, 
  VertexColors -> vcolors]]
$\endgroup$
1
  • $\begingroup$ The first example has much more detail than the second it look like... $\endgroup$
    – user5601
    Aug 8 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.