Jump to content

numpy question.


saelly

Recommended Posts

node = hou.pwd()

geo = hou.pwd().geometry()

 

for p in geo.points():

    npole = hou.Vector3(node.parmTuple('north_pole').eval())

 

    pos = hou.Vector3(p.position())

 

    print pos - npole

 

 

============================================================

 

"pos - npole" (vector subtraction)

 

To replace this code with a "numpy", what should I do? (no for loop)

 

help me plz..

Edited by saelly
Link to comment
Share on other sites

import numpy

 

node = hou.pwd()

geo = node.geometry()

 

# Add code to modify contents of geo.

# Use drop down menu to select examples.

 

 

#get array of all points attr "P" as string buffer...

string_buffer = geo.pointFloatAttribValuesAsString("P", float_type=hou.numericData.Float32)

 

#create numpy array from our string buffer...

array_of_pos = numpy.fromstring(string_buffer, dtype='float32' ).reshape(-1, 3)  # and reshape to make it 2dimentional (array of vectors)

 

# doing something with your array... (google the numpy broadcast rules)

array_of_pos -= (20, 4, 2) #per-element operation

 

#and then you need to copy your numpy array back to points attr "P"

geo.setPointFloatAttribValuesFromString("P", numpy.getbuffer(array_of_pos), float_type=hou.numericData.Float32)

 

# WORKED (h13)!

Edited by ali
Link to comment
Share on other sites

 

import numpy
 
node = hou.pwd()
geo = node.geometry()
 
# Add code to modify contents of geo.
# Use drop down menu to select examples.
 
 
#get array of all points attr "P" as string buffer...
string_buffer = geo.pointFloatAttribValuesAsString("P", float_type=hou.numericData.Float32)
 
#create numpy array from our string buffer...
array_of_pos = numpy.fromstring(string_buffer, dtype='float32' ).reshape(-1, 3)  # and reshape to make it 2dimentional (array of vectors)
 
# doing something with your array... (google the numpy broadcast rules)
array_of_pos -= (20, 4, 2) #per-element operation
 
#and then you need to copy your numpy array back to points attr "P"
geo.setPointFloatAttribValuesFromString("P", numpy.getbuffer(array_of_pos), float_type=hou.numericData.Float32)
 
# WORKED (h13)!

 

 

Thank you peon!!!

 

thanks a lot~^^

Have a nice day~!!!

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