{"id":711,"date":"2019-09-18T17:06:24","date_gmt":"2019-09-18T21:06:24","guid":{"rendered":"http:\/\/www.vicdebaie.com\/blog\/?p=711"},"modified":"2019-09-25T14:41:32","modified_gmt":"2019-09-25T18:41:32","slug":"using-motionbuilder-python-to-cast-real-time-shadows","status":"publish","type":"post","link":"http:\/\/www.vicdebaie.com\/blog\/using-motionbuilder-python-to-cast-real-time-shadows\/","title":{"rendered":"Using MotionBuilder Python To Cast Real-Time Shadows"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img data-attachment-id=\"712\" data-permalink=\"http:\/\/www.vicdebaie.com\/blog\/using-motionbuilder-python-to-cast-real-time-shadows\/shadowcube\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?fit=1157%2C526\" data-orig-size=\"1157,526\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"MotionBuliderShadowCube\" data-image-description=\"&lt;p&gt;Using Python To Quickly Add A Real Time Shadow To Your MotionBuilder Scene.&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Using Python To Quickly Add A Real Time Shadow To Your MotionBuilder Scene.&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?fit=300%2C136\" data-large-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?fit=678%2C309\" decoding=\"async\" loading=\"lazy\" width=\"678\" height=\"309\" src=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?resize=678%2C309\" alt=\"\" class=\"wp-image-712\" srcset=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?resize=1024%2C466 1024w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?resize=300%2C136 300w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?resize=768%2C349 768w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?w=1157 1157w\" sizes=\"(max-width: 678px) 100vw, 678px\" data-recalc-dims=\"1\" \/><figcaption>Using Python To Quickly Add A Real Time Shadow To Your MotionBuilder Scene.<\/figcaption><\/figure>\n\n\n\n<p>I was watching a great series on YouTube by a MotionBuilder animator named <a href=\"https:\/\/www.youtube.com\/channel\/UCqI1UqP0M4-LDphqlwaEBKg\">Bryan Brewer<\/a>. I highly recommend his series to anyone starting out with MotionBuilder or to anyone who uses MotionBuilder and is looking for tips. While watching the fore mentioned videos, I noticed how nice it was to have a shadow in the scene. I kept looking at the character&#8217;s silhouette and  shadow&#8217;s silhouette, comparing the two and the space they create.  <\/p>\n\n\n\n<p>Creating real time shadows in MotionBuilder has been around for a while but I thought it would be fun to figure out a quick script that would add them to any scene I have open.<\/p>\n\n\n\n<p style=\"text-align:left\">MotionBuilder has a shader called &#8220;Live Shadow&#8221;, this can be applied to a object and that will allow the object to receive real-time shadows. <\/p>\n\n\n\n<p style=\"text-align:center\"><a rel=\"noreferrer noopener\" href=\"https:\/\/knowledge.autodesk.com\/support\/motionbuilder\/learn-explore\/caas\/CloudHelp\/cloudhelp\/2017\/ENU\/MotionBuilder\/files\/GUID-F92E1A9C-681F-4F59-9BD7-7E85DCFEB7FD-htm.html\" target=\"_blank\">You Can Read Up On MotionBuilder Live Shadow Shader Here. <\/a><\/p>\n\n\n\n<p>The Script creates a Live Shadow shader, a ground plane which the Live Shadow shader will be applied to, a light that will produce shadows and a sphere used as a controller that can adjust the shadow direction and length within your scene. <\/p>\n\n\n\n<p>Here is a video demo of the script in action followed by the script itself. I added as many comments to the script as I felt would be needed in hopes to help you break it down.<\/p>\n\n\n<p><iframe loading=\"lazy\" style=\"display: block; margin: auto;\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/F9TqB4J58Js\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\"><\/iframe><\/p>\n\n\n<pre class=\"wp-block-code\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">import pyfbsdk as fb\n\n##Set Up Real-Time Shadows To The Scene\ndef CreateShadowCastingLight():\n    ##Add Ground Plain\n    groundplane = fb.FBModelPlane( 'GroundPlane' )\n    groundplane.Translation = fb.FBVector3d( 0, 0, 0 )\n    ##Scale The Ground So That It Cover A Large Area\n    groundplane.SetVector( fb.FBVector3d( 5, 5, 5 ), fb.FBModelTransformationType.kModelScaling, False )\n    groundplane.Show = True\n    groundplane.PropertyList.Find( 'Pickable' ).Data = False\n    \n    # Create shader.\n    groundplane_shader = fb.FBShaderShadowLive( 'GroundPlane_ShadowCaster_Shader' )\n    groundplane_shader.ReplaceAll( groundplane )\n    \n    ##Ensure Display Mode For Models Within Scene Is Correct\n    for i in fb.FBSystem().Scene.Components:\n        i.ShadingMode = fb.FBModelShadingMode.kFBModelShadingAll  \n        \n    ##Create Sphere To Be A Controler For The Shadow Casting Light\n    shadowlight_CTRL = fb.FBCreateObject( 'Browsing\/Templates\/Elements\/Primitives', 'Sphere', 'Sphere' )\n    shadowlight_CTRL.Name = &amp;quot;shadowlight_CTRL&amp;quot;\n    ##Set The Initial Location And Size Of The shadowlight_CTRL\n    shadowlight_CTRL.SetVector( fb.FBVector3d( 1, 1, 1 ), fb.FBModelTransformationType.kModelScaling, True )\n    shadowlight_CTRL.SetVector( fb.FBVector3d( 180, 240, 50 ), fb.FBModelTransformationType.kModelTranslation, True )\n    ##Make shadowlight_CTRL Visible\n    shadowlight_CTRL.Show = True\n    \n    ##Parent shadowlight_CTRL To groundplane\n    groundplane.ConnectSrc( shadowlight_CTRL )\n    \n    ##Create Shadow Casting Light\n    shadowlight = fb.FBLight( 'GroundPlane_ShadowCaster' )\n    shadowlight.Translation = fb.FBVector3d( 0, -12, 0 )\n    shadowlight.SetVector( fb.FBVector3d(1,1,1), fb.FBModelTransformationType.kModelScaling, True )\n    shadowlight.PropertyList.Find( 'Scaling Inheritance' ).Data = 2\n    shadowlight.Show = True\n    shadowlight.CastLightOnObject  = False\n    \n    ##Add The Light To The Shader So That It Casts Shadows \n    groundplane_shader.Lights.append( shadowlight )\n    \n    ##Parent shadowlight To shadowlight_CTRL\n    shadowlight_CTRL.ConnectSrc( shadowlight )\n    \n    ##Add Flat Yellow Material To The Controller For The Shadow Casting Light\n    ShadowLight_CTRL_Material = fb.FBMaterial( &amp;quot;shadowlight_CTRL_Material&amp;quot; )\n    ShadowLight_CTRL_Material.Emissive  = fb.FBColor( 1, 1, 0 )\n    ShadowLight_CTRL_Material.Ambient   = fb.FBColor( 0, 0, 0 )\n    ShadowLight_CTRL_Material.Diffuse   = fb.FBColor( 0, 0, 0 )\n    ShadowLight_CTRL_Material.Specular  = fb.FBColor( 0, 0, 0 )\n    shadowlight_CTRL.Materials.append( ShadowLight_CTRL_Material )\n\n##Add Real-Time Shadows    \nCreateShadowCastingLight()<\/pre><\/pre>\n\n\n\n<p>\n\nThis was a great excuse to use learn about using python to create shaders, materials, a sphere (lol), and assigning a parent\/child without using constraints. I had a lot of fun with this simple little script and I hope you were able to learn something from it as well. If you know of a better way to script this type of process please feel free to share in the comments below. \ud83d\ude42<\/p>\n\n\n\n<p>Thanks for reading and as always I hope this helps. \n\n<\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Using Python To Quickly Add A Real Time Shadow To Your MotionBuilder Scene.<\/p>\n","protected":false},"author":1,"featured_media":712,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"Using #Python To Quickly Add A Real Time Shadow To Your #MotionBuilder Scene.","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[4],"tags":[5,7],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?fit=1157%2C526","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8pltq-bt","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":190,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-tool-saveit\/","url_meta":{"origin":711,"position":0},"title":"MotionBuilder Python Tool &#8220;SaveIt&#8221;","author":"admin","date":"February 12, 2017","format":false,"excerpt":"Here is a script\/tool I created for MotionBuilder using Python. \u00a0This tool will\u00a0do an incremental save of your scene. Why? Incremental saves are amazingly useful, I thought a tool that automates the process down to one click would be fun. A big thanks goes out to my college Raphael Lappiere\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/SaveIt_tool.jpg?fit=600%2C220&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":77,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-where-to-start\/","url_meta":{"origin":711,"position":1},"title":"MotionBuilder Python &#8211; Where to start","author":"admin","date":"February 6, 2017","format":false,"excerpt":"Finding information for Python scripting in MotionBuilder can be an uphill battle. Here is a list of some of the resources that I have been able to find (thanks google). A lot of the listed links have valuable scripts in which one can hack through and decipher what each line\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/16697171583_7c33584c4b.jpg?fit=500%2C333&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":627,"url":"http:\/\/www.vicdebaie.com\/blog\/pivot-tool-v1-motionbuilder-python\/","url_meta":{"origin":711,"position":2},"title":"Pivot Tool v1 &#8211; MotionBuilder Python","author":"admin","date":"October 19, 2018","format":false,"excerpt":"\u00a0 Updated: Pivot Tool\u00a0 now supports MotionBuilder 2018! :) and in the post below under \"Versions\". 2018 version can be found here and in the post below under \"Versions\". Versions: PivotTool v1.0 for MotionBuilder 2018 PivotTool v1.0 for MotionBuilder 2015 Here is a tool that will help you quickly create\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/10\/pivot.gif?fit=498%2C284&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":566,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-parent-constraint-tool\/","url_meta":{"origin":711,"position":3},"title":"MotionBuilder Python Parent Constraint Tool","author":"admin","date":"June 18, 2018","format":false,"excerpt":"Here is a quick post to share a tool I created a little while back. It is designed to help to quickly create Parent Constraints between two objects as well as easily allow the user to bake that constraint down. The script can be found HERE and there are a\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/img_3937.jpg?fit=443%2C364&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":83,"url":"http:\/\/www.vicdebaie.com\/blog\/using-python-to-create-a-layer-on-the-current-selected-take-in-motionbuilder\/","url_meta":{"origin":711,"position":4},"title":"Using Python to Create a layer on the Current Selected Take in MotionBuilder.\u00a0","author":"admin","date":"February 9, 2017","format":false,"excerpt":"In MotionBuilder using animation layers are great for edits, blending, additives and in general adding quality passes to your animations. So below I'm going to demo how I learned to add layers\u00a0using Python. To create an Animation Layer on the Current Take script: [code language=\"python\"] from pyfbsdk import * lSystem\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":188,"url":"http:\/\/www.vicdebaie.com\/blog\/shelveit-tool\/","url_meta":{"origin":711,"position":5},"title":"ShelveIt tool","author":"admin","date":"February 21, 2017","format":false,"excerpt":"Here is a tool that I whipped up:\u00a0Shelve It. It's a simple Python script that will duplicate your current MotionBuilder take, name it using the original take's name but add the suffix \"_Shelved\". It can come in hand when you want to explore some more changes on a take you\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-21-at-10.29.02-PM.png?fit=962%2C524&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-21-at-10.29.02-PM.png?fit=962%2C524&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-21-at-10.29.02-PM.png?fit=962%2C524&resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/711"}],"collection":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/comments?post=711"}],"version-history":[{"count":13,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/711\/revisions"}],"predecessor-version":[{"id":728,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/711\/revisions\/728"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media\/712"}],"wp:attachment":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media?parent=711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/categories?post=711"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/tags?post=711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}