On 18/03/2014 at 14:43, xxxxxxxx wrote:
Yes. That fixed it.
Thanks a lot for the extra effort.
I'll post my complete working script code so that way people can at least have something that works that they can cut and paste into their script manager to start off with.
import c4d
import math
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]
component = [normal.x, normal.y, normal.z]
for c in range(0,3) :
low_byte, high_byte = float2bytes(component[c])
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()
normal_tag = obj.GetFirstTag() #Assuming the normal tag is the first tag
#These four variabls will be used to change the normal values of a polygon
normal_a = c4d.Vector(0.0,1.0,0.0)
normal_b = c4d.Vector(0.0,1.0,0.0)
normal_c = c4d.Vector(0.0,1.0,0.0)
normal_d = c4d.Vector(0.0,1.0,0.0)
#Set the first polygon normals in the normals tag using the above values
set_normals(normal_tag, 0, normal_a, normal_b, normal_c, normal_d)
obj.Message(c4d.MSG_UPDATE)
c4d.EventAdd()
if __name__=='__main__':
main()
-ScottA