Start a new topic

Setting graphics draw functions via python?

Original Post by: chrisell Thu Nov 12 23:05:23 2015


Is it possible to set graphics functions using python scripts?

For example how do I set the draw mode to lit, textured, solid with no grid being displayed?


I tried simple stuff like:


ok=mggraphicdrawmode(MGDM_WIREFRAME)


But that didn't work - likely because I don't understand exactly how that is supposed to work and the API documentation isn't helping me.

I searched through the examples but couldn't find anything and searching the forum for 'mggraphicdrawmode ' shows no results.


A code snippit would be appreciated - then I can work the rest out from there.


For reference : I'm trying to write a script that will take 360 degree views of a model and output them to a series of JPGS that can then be stitched together to form a movie. I've got the orbiting camera and other functions working, but setting the draw mode is an issue.


Also - any tips on how to get the inbuilt snapshot function to run would be appreciated. I'm guessing I can probably do it with mgExecute()


Original Post by: chrisell Mon Aug 1 16:55:01 2016


Creator v14, Window 7x64 running an Nvidia Quadro K4000 with the latest graphics driver.

Original Post by: SteveThompson Mon Aug 1 16:47:35 2016


Thanks we can give it a whirl. BTW what version of Creator are you using? and what OS? Thanks.

Original Post by: chrisell Mon Aug 1 15:05:50 2016


The steps to make it happen are pretty simple - just invoke the IBR tool with any settings. Like I said - it's frustrating because I can't get it to do it consistently which makes it difficult for me to give you a reproducable test case :(

Original Post by: SteveThompson Mon Aug 1 14:59:17 2016


n light of that not being a possibility then - any ideas what causes the problem that made me go looking down this path in the first place? When IBR adds transparent edges to all the polygons before it takes the images?

This is the first I've heard of this problem. Perhaps you could send a test case to our support team and we could investigate. Or give us a set of steps that show this problem?

Thanks!

Original Post by: chrisell Mon Aug 1 12:57:01 2016


Darn

Yeah - I had a bunch of Python calls lined up to do the auto-renaming of the file each time it was written to give me a number sequence.

In light of that not being a possibility then - any ideas what causes the problem that made me go looking down this path in the first place? When IBR adds transparent edges to all the polygons before it takes the images?

It doesn't happen to every model and on those it does happen on, I've not found any consistency. Sometimes it does it on models that have transparent polys, sometimes not. Sometimes it does it on models with 4k maps, sometimes not.

Tres frustrating :)

Original Post by: SteveThompson Fri Jul 29 17:28:57 2016


Ahh... I see what you are trying to do.

Unfortunately there is no existing code from the OpenFlight API you could put here


# TAKE SCREENSHOT HERE


that would help you. Side note: even if Snapshot was scriptable and saved the correct image file from your current eye point, you'd need to "rename" it before advancing to the next loop iteration. As you know Snapshot would save the file as db.[icn|jpg] and you'd just overwrite the last one on each subsequent iteration through the loop.


In any event, I don't believe there is anything in Creator or OpenFlight Script that will help you here. Sorry.

Original Post by: chrisell Thu Jul 28 21:08:13 2016


What I'm trying to do is encapuslated by this bit of code. I'm trying to orbit the model in front of the camera and grab a series of stills that can be used either in a report or to create an animated GIF and I'm just banging my head against a wall right now trying to figure out how to do that. I was relying on programmatically calling IBR Billboard for a while but then I started to see more and more models where that tool would fail so I'm looking for an alternative solution.

This is the code I have to position the model and orbit the eyepoint. At each "step" of the orbit I want to grab a screenshot and dump it to disk:


def getExtents (db, parent, rec, i):

global maxX,maxY,maxZ,minX,minY,minZ

item = mgGetCode(rec)

if (item == fltVertex):

ok,x,y,z=mgGetVtxCoord(rec)

if x>maxX:

maxX=x

if y>maxY:

maxY=y

if z>maxZ:

maxZ=z

if x<minX:

minX=x

if y<minY:

minY=y

if z<minZ:

minZ=z

return MG_TRUE


maxX=maxY=maxZ=minX=minY=minZ=0

mgWalk (db, getExtents, None, 0, MWALK_VERTEX) # get the extents of the model

extent1=mgcoord3d() # coord3D to contain minimum extent

extent2=mgcoord3d() # coord3D to contain maximum extent

extent1.x=minX

extent1.y=minY

extent1.z=minZ

extent2.x=maxX

extent2.y=maxY

extent2.z=maxZ

sizeOfObject = mgCoord3dDistance(extent1,extent2) # distance between both coordinates

viewRadius=sizeOfObject*0.65


for i in range(1,360,2):

xPos=math.sin(math.radians(i))*viewRadius

yPos=math.cos(math.radians(i))*viewRadius

mgSetCurrentLookAt(db,xPos,yPos,viewRadius*0.4,0,0,viewRadius*0.1,0,0,1)

mgRefreshScene(editorContext)

# TAKE SCREENSHOT HERE

Original Post by: SteveThompson Thu Jul 28 21:02:16 2016


Can mgExecute run the snapshot command though? Or is there any other way of getting screengrabs out of Creator without relying on a third party tool?

Sorry this thread went dead. There was a problem with our forum last year during which we were not getting notifications of new posts. I suspect your last message (then) might have fell victim to that snafu. I apologize for letting this thread go dormant for so long...


That said... as I mentioned in my last post, Snapshot is not something you can script but there are two tools that do let you automate taking "snapshots". They are both in the Attributes Menu: Generate Report and Model Inventory. Check them out to see if they do what you need.

Original Post by: SteveThompson Thu Jul 28 20:57:52 2016


So I’m still looking for a solution to being able to grab my own screenshots from within Creator.

I tried this but it doesn’t do anything :(

BTW Snapshot is not a Creator Script command. I am not sure what you might expect such a command (if it was scriptable) to do differently that running it interactively? Even if we implemented Snapshot as a Creator Script command, it would simply launch the View>Snapshot command.

Original Post by: SteveThompson Thu Jul 28 20:54:45 2016


All of the Creator Script commands are documented in the OpenFlight Script Editor.

Open the OpenFlight Script Editor and do Help>On Creator Script. That will show you all the Creator script commands and all their parameters. Or you can use the Creator Script Snippet Wizard and browse the Creator scripts directly there.

Original Post by: chrisell Thu Jul 28 20:16:23 2016


Just to re-open this long-dead topic -

On some files, IBR billboard forces Creator into a weird render mode where all the polys have transparent edges. These transparent edges are captured in the billboard.

The only solution is to restart creator as this weird mode persists after the IBR tool is closed.

For these models, I can't use IBR because it always goes into this mode.


So I'm still looking for a solution to being able to grab my own screenshots from within Creator.

I tried this but it doesn't do anything :(

paramBlock=mgGetParamBlock("Snapshot")

print paramBlock

mgExecute("Snapshot",paramBlock)

Problem is there's no documentation on mgGetParamBlock or what the internal names of the tools are so I'm just guessing.

Original Post by: chrisell Fri Nov 13 14:41:44 2015


Chris : thanks for that - that got me going on investigating how to use that function. Are any of the mgsettingnames documented anywhere? For example if I look up MGVI_DRAWGRID in the API help file it just says "See the Creator documentation for more information on graphics views and graphics view settings". But the helpfile doesn't contain any more info on what the various integer values can be for that call.


Steve : IBR billboards - that's pretty cool - I've never seen that function before. It's not quite what I'm looking for though.


Can mgExecute run the snapshot command though? Or is there any other way of getting screengrabs out of Creator without relying on a third party tool?

Original Post by: SteveThompson Thu Nov 12 23:19:57 2015


For reference : I’m trying to write a script that will take 360 degree views of a model and output them to a series of JPGS that can then be stitched together to form a movie. I’ve got the orbiting camera and other functions working, but setting the draw mode is an issue.


Note that Creator has a tool that may help you do this directly. Check out LOD>IBR Billboard. You can use this tool to take "snap shots" from different angles around your model. It composites these images into one single texture (with subtextures). To break them out into their own files, use Texture Sequencer : Decompose option.

Original Post by: ChrisRogers Thu Nov 12 23:12:58 2015


Try this:

db = mgGetCurrentDb ()

mgGraphicsViewSettingSetInteger (db, MGVI_DRAWMODE, 0, MGVSM_SETCURRENT)


the 0 param tells it to set the draw mode to wireframe.

Login to post a comment