Profile Picture

Can someone code a Python shaky-cam script?

Posted By gordryd 5 Years Ago
Rated 5 stars based on 1 vote.
Author
Message
gordryd
gordryd
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)

Group: Forum Members
Last Active: Last Week
Posts: 711, Visits: 7.6K
If any of you Python programmers are looking for a project to code, might I suggest a "Shaky-Cam" app?  I guess one way to do this would be to sample the Camera Transform at a given key interval (the program might have to create those keys).  This would allow the shake to be added/subtracted from existing Transform camera movement.  Not sure if it would work with Paths or not?

Just a few thoughts about what I personally think would be helpful to have:

1. Camera Shake Presets, like:
   a. Walking (random + emphasized vertical shake every 0.5 second?  I think that matches standard animation walk cycle...)
   b. Running (random + empahsized vertical shake every 0.25 seconds?)
   c. Vehicle - Wheeled/Aircraft (random short interval shaking in all directions)
   d. Boat (low frequency pitch/roll/yaw)
   The Presets could have a 'multiplier' to control the amount
   
2. A pre-visualizer (maybe a red ball moving inside a square w/crosshairs, to see how much shake will be applied before committing to Timeline)

I'm sure lots of other things could be added, such as more advanced control of Preset settings, but this would be a great start.

Any takers?


Reallusion Certified Director / Reallusion Best Visual Award / Reallusion Certified Content Developer
See all the G-Tools Plug-Ins available for iClone here: G-Tools Plug-Ins


thedirector1974
thedirector1974
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (6.9K reputation)Distinguished Member (6.9K reputation)Distinguished Member (6.9K reputation)Distinguished Member (6.9K reputation)Distinguished Member (6.9K reputation)Distinguished Member (6.9K reputation)Distinguished Member (6.9K reputation)Distinguished Member (6.9K reputation)Distinguished Member (6.9K reputation)

Group: Forum Members
Last Active: 2 days ago
Posts: 783, Visits: 5.2K
You don't need to have a phyton script to get a shaky cam effect. Just link the camera to the head of an avatar and give that avatar a idle/running/walking animation. That's it ...
4u2ges
4u2ges
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 5.0K, Visits: 15.9K
I've done that thing with the character in the past as Director suggested. But today I needed an all directions subtle camera shake.
So I figured I finally would get my hands on Python. Had to go through the crash course (thanks all for the suggestions and discussions in this sub-forum).

Anyhow, came up with this basic script. Nothing fancy. But it can be tweaked to accommodate most situations where camera needs a shake.
Pretty much self explanatory with some comments. Make sure to run the script after you settle your camera with transformation points, smoothing, transitions... etc.
Could also be suited for the dummy driven cameras. Just need to change "Camera" to the prop name and object type. Have not tested for the Cameras on the Path.

Test the script on some demo project first. If after running a script you are not happy and need to change some parameters, perform an undo in iClone and load amended script over again.

import RLPy, math
from random import *

# Created for the camera named "Camera"
cameraMan = RLPy.RScene.FindObject(RLPy.EObjectType_Camera, "Camera")

# Shake angles limit. Represents variation from -0.0035 to 0.0035 radians (-0.2 to 0.2 degrees)
# Random number is generated within those limits and added to each axis for designated frames
minDelta = -35
maxDelta = 35


# For the first 800 frames adds a shake by randomly tweaking an XYZ rotation for every 10th frame

for camFrame in range(0,800,10):
    shakeTime = RLPy.RTime.IndexedFrameTime(camFrame, RLPy.RGlobal.GetFps())
    cameraMan_control = cameraMan.GetControl("Transform")
    cameraMan_data = cameraMan_control.GetDataBlock()
   
    getXRotation = cameraMan_data.GetData("Rotation/RotationX", shakeTime).ToFloat() + randint(minDelta, maxDelta)/10000
    getYRotation = cameraMan_data.GetData("Rotation/RotationY", shakeTime).ToFloat() + randint(minDelta, maxDelta)/10000
    getZRotation = cameraMan_data.GetData("Rotation/RotationZ", shakeTime).ToFloat() + randint(minDelta, maxDelta)/10000
   
    cameraMan_data.SetData("Rotation/RotationX", shakeTime, RLPy.RVariant(getXRotation))
    cameraMan_data.SetData("Rotation/RotationY", shakeTime, RLPy.RVariant(getYRotation))
    cameraMan_data.SetData("Rotation/RotationZ", shakeTime, RLPy.RVariant(getZRotation))
    cameraMan_control.SetKeyTransition(shakeTime, RLPy.ETransitionType_Ease_In_Out, 1.0)


And a sample demo:



UPDATE: It is possible to add shaker to the camera on a Path. Not directly though.
Link a Dummy object to the Path. Align camera with Dummy. Link Camera to Dummy. Apply script to Camera.
It also works with Look At applied to a Dummy (when circling around the object for instance).




Edited
5 Years Ago by 4u2ges
Data Juggler
Data Juggler
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (12.4K reputation)Distinguished Member (12.4K reputation)Distinguished Member (12.4K reputation)Distinguished Member (12.4K reputation)Distinguished Member (12.4K reputation)Distinguished Member (12.4K reputation)Distinguished Member (12.4K reputation)Distinguished Member (12.4K reputation)Distinguished Member (12.4K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.7K, Visits: 5.4K
I just completed my first Python script this morning, let me see if I can get a couple of questions answered and I could probably write out the Python in C# pretty easily to generate a script.

Would you want this to apply to the selected camera in a project? I guess the more robust way is to show a UI element and let you pick, but that would probably be a version 2 thing.

One of my open source projects located in my massive C# code repo I just released on GitHub last week (that no one has even found yet until I finish my animated video I am making and start promoting it) called Random Shuffler, which is used to make Dice and Card game shuffling easy, but it also works for integers. This class library shuffles like a real deck of cards shuffles (even distribution) where as random number generators use Math and time seeds and are not that random at all.

If any C# / SQL developers happen to find this and want it is, it is free:
https://github.com/DataJuggler/SharedRepo/tree/master/Core/RandomShuffler
Full Repo is here:
https://github.com/DataJuggler/SharedRepo 

https://forum.reallusion.com/uploads/images/3f24efe6-7c05-41e3-8065-abce.png




Creator of the free website:
PixelDatabase.Net
A Free Online Text Based Image Editor
https://forum.reallusion.com/uploads/images/6e6663e2-0ecf-447a-ab3d-d49d.png

gordryd
gordryd
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)

Group: Forum Members
Last Active: Last Week
Posts: 711, Visits: 7.6K
4u2gues - Thanks, I'll give this a try tonight.  On a related topic, if you wanted an object to 'shake' (say a car on a bumpy road) while the camera stayed 'still', is this the only line that would need to be changed (subsitute chosen item for ObjectType_Camera and "Camera")?

cameraMan = RLPy.RScene.FindObject(RLPy.EObjectType_Camera, "Camera")


Reallusion Certified Director / Reallusion Best Visual Award / Reallusion Certified Content Developer
See all the G-Tools Plug-Ins available for iClone here: G-Tools Plug-Ins


4u2ges
4u2ges
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 5.0K, Visits: 15.9K
@gordryd
Yes, exactly. Should work fine.
cameraMan = RLPy.RScene.FindObject(RLPy.EObjectType_Prop, "PropName")




Edited
5 Years Ago by 4u2ges
gordryd
gordryd
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)Distinguished Member (4.6K reputation)

Group: Forum Members
Last Active: Last Week
Posts: 711, Visits: 7.6K
@4u2gues - I tried your 'ShakyCam' script and it works well -- thanks for that.  I've actually created half a dozen sub-menu items for different motions (Cam-Walking, Cam-Running, Prop-Car, Prop-Bumpy, Prop-Boat, Prop-Airplane).  The main issue I am having is that the effect is cumulative, which in theory shouldn't be a problem.  Probability says it should all average out, since the rotation angles are supposed to be random.  In actuality though, they seem to be biased in a certain direction, and the longer the scene plays the farther away from 'center' the camera or object will drift (as opposed to random rotations around a fixed point).
I also have a prop which doesn't seem to respond to the script -- no rotation is visible and no keyframes are added.  If I import a cube and rename to the same prop name, the cube will react to the script.  The original prop has no constraints, doesn't have physics enabled, isn't on a path, etc.  Not sure what is going on with this one, but I can live with that.
Now if only I can figure out how to create a UI so I can input/change the values on the fly (instead of changing the script and re-starting iClone)...

Reallusion Certified Director / Reallusion Best Visual Award / Reallusion Certified Content Developer
See all the G-Tools Plug-Ins available for iClone here: G-Tools Plug-Ins


4u2ges
4u2ges
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)Distinguished Member (20.6K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 5.0K, Visits: 15.9K
Yes, you are right, it probably IS cumulative. I should have looped through the frames, gathered values into array and then applied values with another loop parsing resulted array.
As to UI, oh well, it is another story. I have not gotten to that part yet. Probably will at some point Smile




videodv
videodv
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 342, Visits: 12.0K
One way to create a ui is to use the qt designer follow this Link
And the manual from here Link

Hope this helps

Chris.
videodv
videodv
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 342, Visits: 12.0K
Here's a very quick and simple way to load and run a script with the ui design this has one slider as an example.

import PySide2, RLPy, os, math
from PySide2 import *
from PySide2.QtWidgets import *
from PySide2.shiboken2 import wrapInstance

#-- Make a global variable contain Dialog --#
sample_dialog = None
qtui_widget = None

def run_script():
    global sample_dialog

    #-- Make the RL Dialog --#
    sample_dialog = RLPy.RUi.CreateRDialog()
    sample_dialog.SetWindowTitle("Prop Options")

    #-- Wrap to PySide Dialog --#
    pyside_dialog = wrapInstance(int(sample_dialog.GetWindow()), QtWidgets.QDialog)
    sample_layout = pyside_dialog.layout()

    #-- Load Ui file --#
    ui_file = QtCore.QFile(os.path.dirname(__file__) + "/youruiname.ui") # Change Name to your UI here
    ui_file.open(QtCore.QFile.ReadOnly)
    qtui_widget = QtUiTools.QUiLoader().load(ui_file)
    ui_file.close()
   
    # Get Controls from youruiname.ui
    ui_some_slider_name = qtui_widget.findChild(PySide2.QtWidgets.QSlider, "someSliderName")


    # OK lets go and do something
    ui_some_slider_name.valueChanged[int].connect(run_something)
        
    # #-- Assign the Ui file to PySide dialog --#
    sample_layout.addWidget(qtui_widget)

    sample_dialog.Show()

def run_something(value)
    print("Slider Value: {}".format(value))

Make shure the ui is in the folder you are running the script from.
Chris.



Reading This Topic