[x3d-public] Units for BVH vs HAnimMotion.values
John Carlson
yottzumm at gmail.com
Sat Oct 14 07:30:40 PDT 2023
I've decided to go two ways. I will provide both motions and
interpolators. Then we can add a flag to switch between them. I am not
certain of the order of loc or axa at this point, I want to look at the
data further.
Here's the barely tested interpolator code (only Armatures right now,
sorry).
print(f"Exporting interpolators of {tag} {obj.type}")
children = []
if obj.type == 'ARMATURE':
armature = obj
bpy.context.view_layer.objects.active = armature
bpy.ops.object.mode_set(mode='POSE')
print(f"Activated armature {armature} in pose mode")
if armature:
animation_data = armature.animation_data
if animation_data:
print(f"Exporting animation data")
action = animation_data.action
if action:
numbones = len(armature.pose.bones)
frame_range = action.frame_range
keyframe_length = (frame_range[1] -
frame_range[0]) / bpy.context.scene.render.fps
keyframe_time = 0
time_sensor =
TimeSensor(cycleInterval=(frame_range[1] - frame_range[0]), loop=True,
enabled=True)
clock_name = name+"_Clock"
setUSEDEF(clock_name, None, time_sensor)
activate_sensor =
ProximitySensor(size=[ 1000000, 1000000, 1000000 ])
activate_name = name+"_Close"
setUSEDEF(activate_name, None,
activate_sensor)
activate_route = ROUTE(
fromNode=activate_name,
fromField="enterTime",
toNode=clock_name,
toField="startTime")
positionInterpolators = []
orientationInterpolators = []
positionRoutes = []
orientationRoutes = []
for b in range(numbones):
bone = armature.pose.bones[b]
posInterp = PositionInterpolator()
setUSEDEF(name+"_PI_", bone.name,
posInterp)
positionInterpolators.append(posInterp)
positionRoutes.append(ROUTE(
fromNode=clock_name,
fromField="fraction_changed",
toNode=name+"_PI_"+bone.name,
toField="set_fraction"))
positionRoutes.append(ROUTE(
fromNode=name+"_PI_"+bone.name,
fromField="value_changed",
toNode=HANIM_DEF_PREFIX+
bone.name,
toField="translation"))
rotInterp =
OrientationInterpolator()
setUSEDEF(name+"_OI_", bone.name,
rotInterp)
orientationInterpolators.append(rotInterp)
orientationRoutes.append(ROUTE(
fromNode=clock_name,
fromField="fraction_changed",
toNode=name+"_OI_"+bone.name,
toField="set_fraction"))
orientationRoutes.append(ROUTE(
fromNode=name+"_OI_"+bone.name,
fromField="value_changed",
toNode=HANIM_DEF_PREFIX+
bone.name,
toField="rotation"))
for frame in
range(int(action.frame_range.x), int(action.frame_range.y) + 1):
# frame is frame number
bpy.context.scene.frame_set(frame)
print(f"Exporting frame {frame}")
for b in range(numbones):
bone = armature.pose.bones[b]
bone.rotation_mode =
'AXIS_ANGLE'
positionInterpolators[b].key.append(keyframe_time)
loc = [
bone.location[0]*lengthUnitConversion, # location
bone.location[2]*lengthUnitConversion, # location reverse Y and Z for X3D
bone.location[1]*lengthUnitConversion # location reverse Y and Z for X3D
]
positionInterpolators[b].keyValue.append(loc) # location
axa = bone.rotation_axis_angle
rot = [axa[0], axa[1], axa[2],
axa[3]]
orientationInterpolators[b].key.append(keyframe_time)
orientationInterpolators[b].keyValue.append(rot) # SFRotation
keyframe_time = keyframe_time +
keyframe_length
children.append(time_sensor)
children.append(activate_sensor)
children.append(activate_route)
children.append(positionInterpolators[:])
children.append(positionRoutes[:])
children.append(orientationInterpolators[:])
children.append(orientationRoutes[:])
On Sat, Oct 14, 2023 at 6:54 AM GPU Group <gpugroup at gmail.com> wrote:
> The Blender > Export/Import > mocap bvh code may have some hints.
> Hypothesis: on import it converts from mocap to interpolators, on export
> goes the other way.
>
> Q. do you think that HAnim 5.2.4 Angle Conversion Procedure is sufficient
> to imply Motion data is in degrees? It doesn't mention the Motion node
> explicitly (Hypothesis written in an early era).. If so we could make the
> Motion.values degrees by default, as Joe suggested and 5.2.4 'indirectly
> implies'?
> -Doug
>
>
> On Sat, Oct 14, 2023 at 2:47 AM John Carlson <yottzumm at gmail.com> wrote:
>
>> Here's the Euler Angle to Axis-Angle in HAnim Pt section 5.2.4
>>
>>
>> https://www.web3d.org/documents/specifications/19774/V2.0/MotionDataAnimation/AnimationUsingInterpolators.html#AngleConversionProcedure
>>
>> Hmm! I'm guessing that Blender has a routine for this! Sure enough!
>> Trying it now.
>>
>> Not with HAnimMotion, I don't know how to do that yet. Suggestions?
>>
>> John
>>
>> On Sat, Oct 14, 2023 at 12:21 AM Joe D Williams <joedwil at earthlink.net>
>> wrote:
>>
>>> > Um, then why is angle even listed here?
>>>
>>>
>>>
>>> That is easy, take another look.
>>>
>>> Euler angles are not listed anywhere!
>>>
>>> Convert to axis-angle like showed in Part 2 and forget xyz angles/
>>>
>>> Joe
>>>
>>>
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: John Carlson <yottzumm at gmail.com>
>>> Sent: Oct 13, 2023 6:15 PM
>>> To: Joe D Williams <joedwil at earthlink.net>
>>> Cc: <x3d-public at web3d.org>
>>> Subject: Re: [x3d-public] Units for BVH vs HAnimMotion.values
>>>
>>>
>>> Um, then why is angle even listed here?
>>>
>>> Confusing as heck!
>>>
>>>
>>> https://www.web3d.org/documents/specifications/19775-1/V4.0/Part01/concepts.html#t-Standardunits
>>>
>>> John
>>>
>>>
>>> On Fri, Oct 13, 2023 at 7:19 PM Joe D Williams <joedwil at earthlink.net>
>>> wrote:
>>>
>>>> > otherwise specified in a UNIT statement
>>>>
>>>>
>>>>
>>>>
>>>> https://www.web3d.org/documents/specifications/19775-1/V4.0/Part01/concepts.html#Standardunitscoordinates
>>>>
>>>>
>>>>
>>>> "However, the world coordinate units may be modified by specifying a
>>>> different length unit using the UNIT statement."
>>>>
>>>>
>>>>
>>>> There is Not Now nor will there Ever be a UNIT statement that allows
>>>> degrees for rotation and orientation.
>>>>
>>>>
>>>>
>>>> Never, will angles appear in any x3d animation interpolator.
>>>>
>>>> To apply an import using angle units, it is converted to x3d before
>>>> use, then discarded or possibly stored somewhere away from working area for
>>>> reference.
>>>>
>>>>
>>>>
>>>> Thanks and Best,
>>>>
>>>> Joe
>>>>
>>>>
>>>>
>>>> -----Original Message-----
>>>> From: John Carlson <yottzumm at gmail.com>
>>>> Sent: Oct 13, 2023 11:44 AM
>>>> To: X3D Graphics public mailing list <x3d-public at web3d.org>
>>>> Subject: [x3d-public] Units for BVH vs HAnimMotion.values
>>>>
>>>>
>>>> Apparently BVH uses degrees for rotations. Units for HAnimMotion
>>>> should use radians unless otherwise specified in a UNIT statement, AFAIK.
>>>>
>>>> Comments?
>>>>
>>>> Thanks!
>>>>
>>>> John
>>>>
>>>>
>>>>
>>>
>>>
>> _______________________________________________
>> x3d-public mailing list
>> x3d-public at web3d.org
>> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20231014/90cb0f9b/attachment-0001.html>
More information about the x3d-public
mailing list