Drawing to 3D render

Hi, I have a lot of .dxf’s files with drawings of sheets with holes, I want to generate rendered .jpg’s images file like this one below of with that sheet with holes, how can I do this? (many images like this one, but with different holes patterns)

I can try to convert the dxf files into a black/white images to be used as a mask if this is needed as a previous step, but ideally I want to be able to do it if it is possible importing directly the .dxf.

As far I know this scene was made by a freelancer using Keyshot, so I can get the needed files that he used as input to keyshot or the keyshot file itself.

Please beware that I don’t know much about 3D or filetypes involved neither, I’m a programmer and I need to automate this with python.

Thanks in advance!

Hi,
If I got it right, this is what I understand you want to do:
You have a .dxf file, which seems to be AutoCAD’s way of storing 2D and 3D drawings several years ago.
You want to render that with some images on the background.
I apologize if this is not what you wanted. You might want to explain in detail.

I do not know how someone might be able to automate this, because I assume each image is going to be different.

But doing this can be done easily in blender if you have only a few images:

  1. Install blender if you don’t have.
  2. Install the .dxf importer-exporter addon from within blender.
  3. Import the the .dxf you have.
  4. Import the image as a backdrop and click render.
    Simply googling these steps will let you know how to do it.

But the image you obtain might not be very realistic. That requires a bit more work.
See World Environment if you want.

Hi, @nerdishstuff Thanks for your kindly response, unfortunately I need to automate this stuff in order to process many, a lot of files, each file will have different holes pattern, some will round, some square, some with different or same sizes of holes, etc, and later new files will be added in the future… I can manage to convert the dxf into a jpg/image to act as a mask (black&white) to represent surface/holes.
But I need to get something similar to that image.

Maybe I could import a file (the sheet with that size, in that angle/perspective, etc, and later add the background as an image jpg external file, and it will be really useful to apply a colour or texture to the perforated sheet too.

I was reading messages here and I found that there is a screenshot function that allows to generate a jpg file… But I dont konw nothing about Panda3D and don’t know the previous steps to generate that.

May be someone can help me joining some snippets and get a sample code to be able to test it and modify it.

Thanks!

Screenshots are easy to make.

from direct.showbase.ShowBase import ShowBase

class Demo(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

        sample = loader.loadModel("panda")
        sample.reparentTo(render)
        sample.set_pos(0, 50, 0)
        
        base.graphicsEngine.renderFrame()
        base.win.saveScreenshot("1.png")
        
demo = Demo()
demo.run()
1 Like

thanks @serega-kkz !
Great! I will try that code asap.
There is also a way to run this headless on a server right?
in loadModel I assume that I could load other file with a figure in 3D right?
and there is some way to change the 3D figure texture and assign that mask to have the holes, right?

I have lying around sketchup, I can create a 3d figure using it and exporting to some filetype right ?
Thanks!

Hi @briaian87b

Yes, see here

You would have to add this line at the beginning of the script:

loadPrcFileData("", "load-file-type p3assimp")

By default panda3d can only load .egg and .bam files (AFAIK). This snippet enables all formats supported by assimp.

Yes, as stated above you can export it to any format supported by assimp and load it on panda3d.

So, summing up all these you would have something like:

from direct.showbase.ShowBase import ShowBase
from panda3d.core import loadPrcFileData
loadPrcFileData("", "window-type offscreen" ) # Spawn an offscreen buffer
loadPrcFileData("", "audio-library-name null" ) # Prevent ALSA errors
loadPrcFileData("", "load-file-type p3assimp") # Load using assimp
base = ShowBase()
for file in folder:
    sample = loader.loadModel(file)
    sample.reparentTo(render)
    sample.set_pos(0, 50, 0)
    base.graphicsEngine.renderFrame()
    base.screenshot(namePrefix='screenshot', defaultFilename=1, source=None, imageComment="")
    sample.destroy()

In fact, Assimp is used by default. The Confauto.prc file contains a string generated by the build system.

# If we built with Assimp support, we can enable the Assimp loader,
# which allows us to load many model formats natively.

load-file-type p3assimp