sherlockHound Posted August 5, 2020 Share Posted August 5, 2020 (edited) 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? Thanks! Edited August 5, 2020 by sherlockHound Quote Link to comment Share on other sites More sharing options...
Noobini Posted August 5, 2020 Share Posted August 5, 2020 ray ? and no, dunno via scripting. Quote Link to comment Share on other sites More sharing options...
sherlockHound Posted August 6, 2020 Author Share Posted August 6, 2020 (edited) 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() try: if (hou.intFrame() == 1): file = open(filename, "w+") file.close() file = open(filename, "a") except: 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] str1="{:.8f}".format(depth) file.write(str1 + "\n") fend = hou.playbar.frameRange()[1] if (hou.intFrame() == fend): file.close() Edited August 6, 2020 by sherlockHound Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.