On 17/03/2014 at 17:29, xxxxxxxx wrote:
I'm having some trouble using your custom set_normals() method.
It's throwing a type error.
Any idea why? Am I using it wrong?
import c4d
def float2bytes(f) :
int_value = int(math.fabs(f * 32000.0))
high_byte = int(int_value / 256)
low_byte = int_value - 256 * high_byte
if f < 0:
high_byte = 255-high_byte
low_byte = 255-low_byte
return (low_byte,high_byte)
def set_normals(normal_tag,polygon,normal_a,normal_b,normal_c,normal_d) :
normal_list = [normal_a,normal_b,normal_c,normal_d]
normal_buffer = normal_tag.GetLowlevelDataAddressW()
vector_size = 6
component_size = 2
for v in range(0,4) :
normal = normal_list[v]
for c in range(0,3) :
low_byte, high_byte = float2bytes(normal[c]) #<--- TypeError: int is unscriptable
normal_buffer[normal_tag.GetDataSize()*polygon+v*vector_size+c*component_size+0] = chr(low_byte)
normal_buffer[normal_tag.GetDataSize()*polygon+v*vector_size+c*component_size+1] = chr(high_byte)
def main() :
obj = doc.GetActiveObject()
normalTag = obj.GetFirstTag() #Assuming the normal tag is the first tag
polys = obj.GetAllPolygons()
#Change the normals for the first polygon in the normal tag
set_normals(normalTag, polys[0], polys[0].a, polys[0].b, polys[0].c, polys[0].d)
if __name__=='__main__':
main()
-ScottA