OpenGEX icon indicating copy to clipboard operation
OpenGEX copied to clipboard

OGEX Blender exporter updated for 2.8 mesh api

Open joeld42 opened this issue 4 years ago • 2 comments

This updates your blender exporter to use the new 2.8 mesh API and to use Node based materials (using Principled BSDF shader), as blender internal render is no longer supported.

I'm just using this for static scenes so I'm not sure if it works on animated characters. I didn't update the API for shape keys (morph targets) yet, so right now it just ignores shape keys, I'll try and go back and fix that in the future if I have a chance.

Thanks for the OpenGEX pipeline and all the resources you provide!

joeld42 avatar May 27 '21 19:05 joeld42

First thanks for this, been waiting to have a way to export OpenGex from Blender for a long time, to try it out. A few things though.

  1. It fails to export when you choose "Export Selection Only" in the export options.
Python: Traceback (most recent call last):
  File "C:\Users\<UserName>\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\ExportOpenGex.py", line 2736, in execute
    self.ProcessNode(object)
  File "C:\Users\<UserName>\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\ExportOpenGex.py", line 711, in ProcessNode
    if ((self.exportAllFlag) or (node.select)):
AttributeError: 'Object' object has no attribute 'select'

location: <unknown location>:-1
  1. Also, in https://opengex.org/comparison.html the example opengex file has floats written in hex, which your script also does not support. I guess it wouldn't be hard to change, just need to change the WriteFloat() function to make the conversion. Something like:
import struct
def FloatToHex(self, f):
      i = struct.unpack('<I', struct.pack('<f', f))[0]
      return '0x{:08x}'.format(i)

I'm not a python expert, I just looked it up. I'm not sure what the other plugins (Max and Maya) do for it, maybe it should be an export option if the user wants hex or floats. This also makes the file smaller.

EDIT: I just noticed, the attributes say float but you're writing doubles, so you're adding way more precision, for reference:

import struct
def DoubleToHex(self, d):
      i = struct.unpack('<Q', struct.pack('<d', d))[0]
      return '0x{:016x}'.format(i)

EDIT 2: I downloaded a free blender 3d model with some animations, tried to export it and failed :(

Looks like every call: scene.frame_set(currentFrame, currentSubframe) needs to change to: scene.frame_set(currentFrame, subframe = currentSubframe) otherwise you get the following error:

  File "C:\Users\<UserName>\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\ExportOpenGex.py", line 1130, in ExportBoneSampledAnimation
    scene.frame_set(currentFrame, currentSubframe)
TypeError: Scene.frame_set(): required parameter "subframe" to be a keyword argument!

After that I managed to export, no idea if it exported everything from the .blend file imported, but at least it looks valid.

miguelcartaxo avatar Jun 20 '21 14:06 miguelcartaxo

I've been using it in batch mode on static scenes so I didn't test the export selection or much animation. I'll take a look at these issues in a couple of weeks when I'm back from vacation. The WriteFloat... stuff is from the old plugin, but adding the hex format shouldn't be too hard. Thanks for testing!

joeld42 avatar Jun 20 '21 17:06 joeld42