On 10/08/2017 at 15:03, xxxxxxxx wrote:
I can't see any bug or any unexcepted event. You mesh is not evently distrubuted. By that I mean each raw are not valid int so basicly you round it (so it's why some pixel are never printed).
Another solution for you would be to use https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d.utils/GeRayCollider/index.html#c4d.utils.GeRayCollider and create an even spaced grid and not use actual geometry.
So it will end with something like this
import c4d
def get_height(ray, x, y, height=10000) :
start_pos = c4d.Vector(x, height, y)
ray_dir = c4d.Vector(0, -1, 0)
ray_lenght = height*2
if ray.Intersect(start_pos, ray_dir, ray_lenght) :
intersection = ray.GetNearestIntersection()
hit_pos = intersection["hitpos"]
return hit_pos.y
return 0
def optimize(obj, tolerance) :
doc = c4d.documents.GetActiveDocument()
doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
settings = c4d.BaseContainer()
settings[c4d.MDATA_OPTIMIZE_TOLERANCE] = tolerance
settings[c4d.MDATA_OPTIMIZE_POINTS] = True
settings[c4d.MDATA_OPTIMIZE_POLYGONS] = True
settings[c4d.MDATA_OPTIMIZE_UNUSEDPOINTS] = True
c4d.utils.SendModelingCommand(command=c4d.MCOMMAND_OPTIMIZE,
list=[obj],
mode=c4d.MODELINGCOMMANDMODE_ALL,
bc=settings,
doc=doc)
def main() :
doc = c4d.documents.GetActiveDocument()
obj = doc.GetFirstObject()
optimize(obj, 0.001)
ray = c4d.utils.GeRayCollider()
ray.Init(obj)
bmp = c4d.bitmaps.BaseBitmap()
bmp.Init(256, 256)
bounding_box_y = obj.GetRad().y
for x in range(-128, 128) :
for y in range(-128, 128) :
h = get_height(ray, x, y)
mx = 128 + int(x)
my = 255 - (128 + int(y))
normalized_height = c4d.utils.Smoothstep(-bounding_box_y, bounding_box_y, h)
heigt_color = normalized_height * 255
bmp.SetPixel(mx, my, heigt_color, heigt_color, heigt_color)
c4d.bitmaps.ShowBitmap(bmp)
if __name__=='__main__':
main()
Btw I this example I assume, the obj is in the default c4d orientation and his pivot is centered in the object.