usd point instancer reading external prototypes

   1481   5   3
User Avatar
Member
3 posts
Joined: 11月 2019
Offline
by default when creating a point instancer in houdini solaris, the prototypes are left underneath it, even when instanced, which creates lots of descendants which in turn slow down considerably the loading and viewing of the data for very complex shots.

Is there an easy way to go around this issue other than python scripting from scratch a custom point instancer ?
User Avatar
Member
3 posts
Joined: 11月 2019
Offline
anyone tried to recreate a point instancer through python with external prototypes ?
User Avatar
スタッフ
359 posts
Joined: 2月 2008
Offline
Here's an example:
Create a sphere, a cube and a torus, plug a python LOP and set it to use this code:

from random import random, randint
import hou
from hou import hmath
from pxr import UsdGeom, Gf

node = hou.pwd()
stage = node.editableStage()

numinstances = 20

prim = stage.DefinePrim("/pointinstancer", 'PointInstancer')
pi = UsdGeom.PointInstancer(prim)
rel = pi.GetPrototypesRel()
rel.AddTarget("/cube1")
rel.AddTarget("/sphere1")
rel.AddTarget("/torus1")

protoindices = pi.GetProtoIndicesAttr()
protoindices.Set([randint(0,2) for x in range(numinstances)])

pos = pi.GetPositionsAttr()
pos.Set([[float(x * 5), 3.0, 0.0] for x in range(numinstances)])

rot = pi.GetOrientationsAttr()
rot.Set([Gf.Quath(*list(hou.Quaternion(hmath.buildRotate(random()*180, random()*360, random()*270)))) for x in range(numinstances)])

scl = pi.GetScalesAttr()
scl.Set([[random()*2+0.2]*3 for x in range(numinstances)])
User Avatar
Member
3 posts
Joined: 11月 2019
Offline
This is a great example, thx for this.
For complex ecosystems I see this option as being quite useful for hierarchical scattering

maybe something to add as a feature in the current point instancer options
Edited by drhein - 2023年10月3日 18:33:42
User Avatar
Member
21 posts
Joined: 5月 2015
Offline
npetit
Here's an example:
Create a sphere, a cube and a torus, plug a python LOP and set it to use this code:

from random import random, randint
import hou
from hou import hmath
from pxr import UsdGeom, Gf

node = hou.pwd()
stage = node.editableStage()

numinstances = 20

prim = stage.DefinePrim("/pointinstancer", 'PointInstancer')
pi = UsdGeom.PointInstancer(prim)
rel = pi.GetPrototypesRel()
rel.AddTarget("/cube1")
rel.AddTarget("/sphere1")
rel.AddTarget("/torus1")

protoindices = pi.GetProtoIndicesAttr()
protoindices.Set([randint(0,2) for x in range(numinstances)])

pos = pi.GetPositionsAttr()
pos.Set([[float(x * 5), 3.0, 0.0] for x in range(numinstances)])

rot = pi.GetOrientationsAttr()
rot.Set([Gf.Quath(*list(hou.Quaternion(hmath.buildRotate(random()*180, random()*360, random()*270)))) for x in range(numinstances)])

scl = pi.GetScalesAttr()
scl.Set([[random()*2+0.2]*3 for x in range(numinstances)])
Is there a way to do this with variants? For example, to have instancer randomly choose variants of a sphere.
User Avatar
スタッフ
4438 posts
Joined: 7月 2005
Offline
Sure, you just need a separate prototype per variant. The explore variants LOP is great for creating this kind of setup.
  • Quick Links