SolidWorks to OBJ export
Asked Answered
E

1

25

At the moment I am engaged in creation SolidWorks add-in for exporting 3D models in OBJ format .

OBJ is opened and very simple format

I've googled and found out the following information about existing solutions: there are several paid plugins and 1 free, which is called "Free OBJ Exporter"

It was taken as a basis. But it does not export the decals.

Decals are images you draw on top of the main texture ( if you move away from the context of SolidWorks, in 3D programming it's like a marks of bullets , blood drops , etc.)

Export decals are an important part of the project.

I rewrote all the VBA code into C #.

And now I come to grips with the issue of export decals . Documentation Solidworks API rather poor.

After a week of reading the documentation and a couple of questions on LinkedIn I found the following :

IDecal is inherided class from IRendererMaterial. Therefore I can get a list of all the decals and get the following information:

  • Yposition
  • Xposition
  • Width
  • Height

I also can get a list of IFace2 objects and get FaceDecalProperties. IFaceDecalProperties provides next information:

  • TextureTranslationU
  • TextureTranslationV
  • TextureTranslationX
  • TextureTranslationY
  • TextureUScale
  • TextureVScale

What it is, what it stands for and how to use it I do not know .

OBJ format does not support directly decals.

How can I use this parameters for concatenation texture and decal in one file? I want to do it for rendering decal on face and solve the problem of Z-fighting, because I don't have source code of renderer.

Erastus answered 23/5, 2014 at 8:5 Comment(2)
I think this textbook page gives you the idea of what u, v, x, and y conventionally represent in this procedure. I am not familiar with it although I'm somewhat interested to learn. encrypted.google.com/…Equidistant
Have you think about publishing your code on GitHub? I'd like to contribute on developing a C# macro or plugin to do the same job.Conjunctive
D
6

I'm not sure what TextureTranslationX and TextureTranslationY mean in this context, but TextureTranslationU and TextureTranslationV almost certainly refer to the texture coordinates of the model.

Typically the (U,V) texture coordinates are specified between [0,1] and determine how an image is mapped onto a surface. (U,V) = (0,0) will typically be the top leftmost pixel of the texture image.

So if you have a set of vertices like:

v 0 0 0
v 1 0 0
v 0 1 0
v 1 1 0

Which defines a square in (X,Y,Z) space, and these vertices have the following (U,V) texture coordinates:

vt 0 0
vt 1 0
vt 0 1
vt 1 1

Then a "texture", by which we really mean image, will be applied to the square such that its top leftmost pixel will be applied to the (0, 0, 0) vertex of the square.

TectureUScale and TextureVScale likely refer to scaling parameters that allow for non-rectangular texture images.

In terms of translating this to OBJ, consult http://en.wikipedia.org/wiki/Wavefront_.obj_file. The format I used above is consistent with the file format specification.

You will also need to save the texture image to a .tga file according the documentation and then create a .mtl file that looks like:

newmtl texture1
Ka 1.000 1.000 1.000  # Only ambient to keep things simple
Kd 0.000 0.000 0.000  # Disable diffuse component
Ks 0.000 0.000 0.000  # Disable specular component
illum 1               # Only color and ambient are enabled
map_Ka texture.tga    # Ambient texture map

The final piece is to put:

usemtl [texture1]

Before the vertex and texture coordinate definitions in your .obj file.

I would start out with something very simple like a square textured with a checkerboard pattern that has the same width and height.

Decoct answered 25/10, 2014 at 21:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.