Jump to content

PythonSOP:How to get a copy of external geometry


sanostol

Recommended Posts

Hi, I want to import several geometries from different nodes into my PythonSOP and I want to attach data and transform it.

something like this

sourcetransform = source.worldTransform()

sourcegeo = source.displayNode().geometry()

geo.merge(source)

but before i merge it into the geo I would like to multiply by the transform.

right now it tells me that tis geometry is read only, of course, but how can I make a independent copy of that geometry.

I first thought sourcegeo.freeze() would do help, but no.

martin

Link to comment
Share on other sites

Unfortunately there's no way to get a copy of the external geometry that is modifiable.

There's a couple things you can do however:

You can do something for transforming the merged in primitives using a bit of trickery and hou.Geometry.transformPrims(). Basically before you merge in your external geo you need to create a set of the current prims. After that you would merge in the external geometry and create another set of primitives. Once you've got those two sets you can get the difference, which gives you all the new primitives. You can then transform them by your source transform.

As an example, the SOP input geometry is a cone that's somewhere nearish the origin. I then have a torus that I've translated, rotated and scaled off somewhere whose geometry I wish to combine with the cone.

sopnode = hou.pwd()
geo = sopnode.geometry()

target = hou.node("/obj/torus_object1")
target_geo = target.displayNode().geometry()
target_xform = target.worldTransform()

old_prims = set(geo.prims())
geo.merge(target_geo)
new_prims = set(geo.prims())

geo.transformPrims(list(new_prims - old_prims), target_xform)

However, this doesn't work so very well when you have points that aren't attached to primitives.

A better and less complex solution is to transform your current geometry by the inverse of the transform of the geometry you want to merge in. After you do that you can call merge() to bring the external geometry in with no transform and then you transform it all by the non-inverted transform back to the original location of the original geometry and the target location of the recently merged geometry.

sopnode = hou.pwd()
geo = sopnode.geometry()

target = hou.node("/obj/torus_object1")
target_geo = target.displayNode().geometry()
target_xform = target.worldTransform()

geo.transform(target_xform.inverted())
geo.merge(target_geo)
geo.transform(target_xform)

Edited by graham
Link to comment
Share on other sites

Nope. You can only transform it if it's modifiable and the only way to get modifiable geometry is if you are inside a Python operator that is working on that gdp. Unfortunately you also can't even make copies of geometry (modifiable or not). It would definitely be nice to be able to make a modifiable copy that you could work on before merging into another geo object.

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.

Guest
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...