Jump to content

Virtual Depth Sensors


Recommended Posts

Hi -

I have a ship that is behaving nicely with pretty realistic buoyancy on a Houdini Ocean. I would like to outfit the ship with sensors that will give me their depth below the ocean surface at any given time. Any ideas how best to do that?


Edited by sherlockHound
Link to comment
Share on other sites

Hey! For anyone interested, I found a solution that works. 

I started by creating a "sensor" (a small sphere) and constraining to the ship. 

Next I used an Extract Centroid SOP, with Detail for Run Over, Center of Mass for Method, Attribute (called "centroid") for Output.

Next, I added an Object Merge SOP, to merge the sea surface. 

I then dropped a Python SOP and attached the sensor to Input 1 and the sea surface merge into Input 2.

I wanted to export a csv with depths for the entire frame range. Works great as long as the sensor is always under the surface. Would need to tweak the equation for depth on line 24.

node = hou.pwd()
hipFile = hou.hipFile
path = hipFile.path()
filename = path.replace(hipFile.basename(), node.parent().name() + ".csv")

inputs = node.inputs()
sensor_geo = inputs[0].geometry()
sea_surface_geo = inputs[1].geometry()

    if (hou.intFrame() == 1):
        file = open(filename, "w+")
    file = open(filename, "a")
    print("ermagerd! ferl errr!")
with file: 
    position = hou.Vector3()
    normal = hou.Vector3()
    uvw = hou.Vector3()
    ray_origin = hou.Vector3(geo.attribValue("centroid"))
    ray_dir  = hou.Vector3(0,100,0)
    intersected = sea_surface_geo.intersect(ray_origin, ray_dir, position, normal, uvw)
    depth = position[1] - ray_origin[1]    
    file.write(str1 + "\n")   
    fend = hou.playbar.frameRange()[1]
    if (hou.intFrame() == fend):


Edited by sherlockHound
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...