How to get sphere coordinates
-
Hello colleagues, I used C++ to write the C4D S26 plugin on Windows 10, I import .abc and want to get the center point coordinates of each sphere, not the vertex coordinates
BaseObject* obj = doc->GetActiveObject(); PointObject* pointObj = static_cast<PointObject*>(obj); Int32 pointCount = pointObj->GetPointCount(); Vector* points = pointObj->GetPointW(); const ::Matrix globalMtx = pointObj->GetMg(); for (Int32 i = 0; i < pointCount; ++i) { Vector site = pointObj->GetMg() * points[i]; GePrint("Frame " + String::IntToString(count) + ": " + String::VectorToString(site)); }
-
Thanks in advance!
-
Hello @pchg ,
Normally importers in cinema reflect the geometry contained in the original file, or in other words what's contained in the original scene will be in cinema in the closest possible state.
In your case your original scene contains a single geometry that consists of multiple so-called "polygon islands". It looks to me the easiest way to proceed for you would be to first split your geometry into a list of distinct objects (spheres) and then iterate over them separately.
You can achieve this by calling SendModelingCommand with the MCOMMAND_EXPLODESEGMENTS cmd id. The effect you need is the same as if you were to run command "Polygon Islands to Objects" from within cinema GUI.
Please note, recently there was related discussion on this command call: c4d.MCOMMAND_EXPLODESEGMENTS makes target object dead.
The SMC command will return a hierarchy of polygon objects to you, which you can then normally traverse (using functions GetDown() and GetNext() of BaseObject) and retrieve the transform information using related functions: BaseObject - Properties - PSR.
Cheers,
Ilia -
Thanks @i_mazlov
I want to get the coordinate information of all spheres under this editable objectBaseDocument* doc = GetActiveDocument(); BaseObject* obj = doc->GetActiveObject(); ModelingCommandData mcd; mcd.doc = doc; mcd.op = obj; const bool result = SendModelingCommand(MCOMMAND_EXPLODESEGMENTS, mcd);
Wrong result, result = false, or whether it should be done
const bool result = SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd); BaseObject* res = static_cast<BaseObject*>(mcd.result->GetIndex(0)); while (res != nullptr) { Vector points = res ->GetAbsPos(); res = res -> GetNext(); }
but only one coordinate
-
@i_mazlov Thanks
BaseObject* activeObject = doc->GetActiveObject(); if (!activeObject) return break; ModelingCommandData mcd; mcd.doc = doc; mcd.op = activeObject; const bool result = SendModelingCommand(MCOMMAND_EXPLODESEGMENTS, mcd); if(result) { EventAdd(); }
Although I got all the spheres, all the sphere animation was lost, What should I do?
-
Hi @pchg ,
This thread is almost a full duplicate of your adjacent thread: How to preserve the animation of a sphere. The answer is provided there.
Cheers,
Ilia