@@ -846,6 +846,77 @@ Pay attention to the 'delta.source_idx' value as on bigger meshes it could not m
846846
847847![ Morphed Triangle] ( https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/SnippetsForStaticAndSkeletalMeshes_Assets/morph_target.PNG )
848848
849+ ## Animations: Root Motion from SVG path
850+
851+ This funny example build an animation from an SVG file.
852+
853+ The animation will only contain a motion track (for the root bone) and will set keys based on the first path curve found in a SVG file.
854+
855+ You can use the amazing Inkscape to draw your bezier curves:
856+
857+ ![ Bezier] ( https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/SnippetsForStaticAndSkeletalMeshes_Assets/bezier.PNG )
858+
859+ To parse svg paths you need an external python module (https://pypi.python.org/pypi/svgpathtools ).
860+
861+ ```
862+ pip install svgpathtools svgwrite numpy
863+ ```
864+
865+ The svgpathtools transforms SVG curves to a numpy polynomial array, so we can access point values at specific time (or gradients if you prefer):
866+
867+ ``` python
868+ import unreal_engine as ue
869+ from unreal_engine.classes import AnimSequenceFactory, Skeleton
870+ from unreal_engine import FRawAnimSequenceTrack, FVector, FQuat, FRotator
871+ from svgpathtools import svg2paths
872+ import numpy
873+
874+ # use the currently selected skeleton
875+ skeleton = ue.get_selected_assets()[0 ]
876+
877+ # open file dialog to choose the file (returns a list so we get only the first element)
878+ paths, attributes = svg2paths(ue.open_file_dialog(' Open SVG file' , ' ' , ' ' , ' Scalable Vector Graphics|*.svg;' )[0 ])
879+
880+ # an SVG file can contains multiple paths, just get the first one
881+ path = paths[0 ]
882+
883+ # how many frame per second ?
884+ fps = 30
885+ # the duration of the animation
886+ duration = 10
887+ # scale size
888+ scale = 3
889+
890+ factory = AnimSequenceFactory()
891+ factory.TargetSkeleton = skeleton
892+
893+ anim = factory.factory_create_new(' /Game/BezierAnimation001' )
894+ anim.NumFrames = duration * fps
895+ anim.SequenceLength = duration
896+ # enable root motion
897+ anim.bEnableRootMotion = True
898+
899+ pos_keys = []
900+ for t in numpy.arange(0 , 1 , 1.0 / fps/ duration):
901+ # get the point at specific time
902+ point = path.point(t)
903+ x, y = point.real, point.imag
904+ pos_keys.append(FVector(x, y, 0 ) * scale)
905+
906+ # add the track for the root bone
907+ track = FRawAnimSequenceTrack()
908+ track.pos_keys = pos_keys
909+ track.rot_keys = [FQuat()]
910+ anim.add_new_raw_track(' root' , track)
911+
912+ anim.save_package()
913+ ue.open_editor_for_asset(anim)
914+ ```
915+
916+ As we have enabled root motion, once we play the animation (if yo uare using an animation blueprint remember to enable root motion there too) the character will move.
917+
918+ This is a debug session where the character has drawn a point under its position
919+
849920## Animations: Parsing ThreeJS json models (version 3)
850921
851922## Animations: Getting curves from BVH files
0 commit comments