Create asset to set units = kilometers

23 views
Skip to first unread message

Carl Drews

unread,
Mar 9, 2021, 10:00:53 PM3/9/21
to pycollada
I want to have the asset section of my .dae file to look like this:

  <asset>
    <created>2021-03-09T16:44:30.798955</created>
    <modified>2021-03-09T16:44:30.798960</modified>
    <unit name="kilometer" meter="1000" />
    <up_axis>Z_UP</up_axis>
  </asset>

Here is my Python code:

mesh = collada.Collada()
unitKm = collada.asset.Asset(title="unit", unitname="kilometer", unitmeter=1000)
mesh.assetInfo.unit = unitKm
axis = collada.asset.UP_AXIS.Z_UP
mesh.assetInfo.upaxis = axis
print("assetInfo = {}".format(mesh.assetInfo))
print("assetInfo.unit = {}".format(mesh.assetInfo.unit))
print("assetInfo.upaxis = {}".format(mesh.assetInfo.upaxis))

Here is the output:

assetInfo = <Asset title=None>
assetInfo.unit = <Asset title=unit>
assetInfo.upaxis = Z_UP

But the asset section of my .dae file is missing the units:

  <asset>
    <created>2021-03-09T19:51:49.562205</created>
    <modified>2021-03-09T19:51:49.562209</modified>
    <up_axis>Z_UP</up_axis>
  </asset>

It should be easy to add one XML element. Is there some collection of assets that I am not finding in the documentation and examples?

Jeff Terrace

unread,
Mar 9, 2021, 11:11:18 PM3/9/21
to pyco...@googlegroups.com
The assetInfo property is an instance of Asset:
https://pycollada.readthedocs.io/en/latest/reference/generated/collada.Collada.html#collada.Collada.assetInfo

I think you want:
mesh.assetInfo = unitKm

instead of:
mesh.assetInfo.unit = unitKm

You can also pass upaxis to the constructor of Asset instead of setting it after the fact like that.

Jeff


--
You received this message because you are subscribed to the Google Groups "pycollada" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pycollada+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pycollada/4093d9c7-9f07-4284-a104-9c625072915cn%40googlegroups.com.

Carl Drews

unread,
Mar 10, 2021, 11:15:28 AM3/10/21
to pycollada
Jeff, thanks so much! That solution works. Here is the new Python code:

mesh = collada.Collada()
axis = collada.asset.UP_AXIS.Z_UP
assetSection = collada.asset.Asset(
   title="Simple demo of mapping texture to flat surfaces.",
   unitname="kilometer", unitmeter=1000,
   upaxis=axis)
mesh.assetInfo = assetSection

Here is the resulting Buildings.dae:

<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
  <asset>
    <created>2021-03-10T09:12:19.674806</created>
    <modified>2021-03-10T09:12:19.674808</modified>
    <title>Simple demo of mapping texture to flat surfaces.</title>
    <unit meter="1000" name="kilometer" />
    <up_axis>Z_UP</up_axis>
  </asset>

Carl

Reply all
Reply to author
Forward
0 new messages