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:
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.
You can set the export options when you export SOLIDWORKS documents as TIFF, Adobe® Photoshop®, or JPEG files.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With