You're welcome, Manuel.
Actually, I usually prepare all the textures and mapping to be in UVW mapping, when texturing is required.
But, mainly, what I need is exporting geometry that is animated.
I have a script that exports a sequence of OBJ files out of an animated Cinema 4D scene. It works perfectly.
I would like to be able to do the same, but export as a sequence of C4D files.
What I need is to export a sequence of frames (the scene has animation, of course), in C4D format, but with everything polygonized.
... doc.SetTime(curr_time) # Force the redraw of the document doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_NONE) c4d.EventAdd(c4d.EVENT_FORCEREDRAW) c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW) bufferedNumber = str(frame_num) frame_num=frame_num+1 # Export the C4D file file_name = os.path.join(file_path,obj_name+bufferedNumber+".c4d") poly_doc=doc.Polygonize(keepanimation = False) if poly_doc != None: c4d.documents.SaveDocument(poly_doc,file_name,c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST | c4d.SAVEDOCUMENTFLAGS_SAVECACHES,c4d.FORMAT_C4DEXPORT)
But all the saved files are the same and I wanted each file to export as different frame, already polygonized.
Is this possible?
Once again, thank you, Manuel.
I had to do a few changes and it is working now.
I even made it select the faces that are within a certain angle from the camera.
Here is my code:
for i,poly in enumerate(faces): a,b,c,d = poly.a,poly.b,poly.c,poly.d pta = points[a]*mg ptb = points[b]*mg ptc = points[c]*mg ptd = points[d]*mg v1 = pta-ptb v2 = ptb-ptc normal = v1.Cross(v2) normal.Normalize() if c != d: center = c4d.Vector((pta.x+ptb.x+ptc.x+ptd.x)/4.0,(pta.y+ptb.y+ptc.y+ptd.y)/4.0,(pta.z+ptb.z+ptc.z+ptd.z)/4.0) else: center = c4d.Vector((pta.x+ptb.x+ptc.x)/3.0,(pta.y+ptb.y+ptc.y)/3.0,(pta.z+ptb.z+ptc.z)/3.0) direction = cam_off - center norm_dir = direction.GetNormalized() angle = NINETY - normal.Dot(norm_dir) if (angle > 0.0 and angle < max_ang): selection.Select(i)
Thank you Manuel.
Your code is for an object, not a face.
So, I tried to adapt it and this is what I got (and it doesn't really work):
def main(): selected=doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0) if selected==: return bd = doc.GetActiveBaseDraw() cam = bd.GetSceneCamera(doc) if cam == None: cam = bd.GetEditorCamera() cam_mg = cam.GetMg() # in case I need it cam_off = cam_mg.off # in case I need it for op in selected: if op.GetType() != 5100: continue mg = op.GetMg() faces = op.GetAllPolygons() points = op.GetAllPoints() selection = op.GetPolygonS() selection.DeselectAll() for i,poly in enumerate(faces): a,b,c,d = poly.a,poly.b,poly.c,poly.d pta = points[a] ptb = points[b] ptc = points[c] ptd = points[d] v1 = pta-ptb v2 = ptb-ptc normal = v1.Cross(v2) normal.Normalize() normal = normal * mg if c != d: center = c4d.Vector((pta.x+ptb.x+ptc.x+ptd.x)/4.0,(pta.y+ptb.y+ptc.y+ptd.y)/4.0,(pta.z+ptb.z+ptc.z+ptd.z)/4.0) else: center = c4d.Vector((pta.x+ptb.x+ptc.x)/3.0,(pta.y+ptb.y+ptc.y)/3.0,(pta.z+ptb.z+ptc.z)/3.0) center = center * mg is_vis = bd.BackfaceCulling(normal, center) if (is_vis == True): selection.Select(i) c4d.EventAdd()
What could be wrong?
How can I determine if a polygon on a polygonal object is facing the current (user or editor) camera?
I know there is a BackfaceCulling function but it always returns me with True.