Creating splineobject returns polyobject [SOLVED]
-
On 27/07/2015 at 06:22, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R16
Platform: Mac OSX ;
Language(s) : C++ ;---------
Hi,Inside GetVirtualObjects() I create a few objects.
One of them is a spline from two combined (joined) splines.
However, it does return a polygonobject with 24 points instead of the splineobject with 8 points, which I want.I've tested it in an empty project, and there everything works fine.. :s
Here is my code for creating the Spline:
SplineObject* firstSpline = SplineObject::Alloc(4, SPLINETYPE_LINEAR); if (!firstSpline) return nullptr; firstSpline->SetParameter(SPLINEOBJECT_CLOSED, GeData(true), DESCFLAGS_SET_0); firstSpline->InsertUnderLast(myNull); SplineObject* secondSpline = SplineObject::Alloc(4, SPLINETYPE_LINEAR); if (!secondSpline) return nullptr; secondSpline->SetParameter(SPLINEOBJECT_CLOSED, GeData(true), DESCFLAGS_SET_0); secondSpline->InsertUnderLast(myNull); SplineObject* mySpline; AutoAlloc<AtomArray> mySplineSelection; if (!mySplineSelection) return nullptr; mySplineSelection->Append(secondSpline); mySplineSelection->Append(firstSpline); ModelingCommandData cdMySpline; cdMySpline.doc = hh->GetDocument(); cdMySpline.arr = mySplineSelection; if (SendModelingCommand(MCOMMAND_JOIN, cdMySpline)) { SplineObject::Free(firstSpline); SplineObject::Free(secondSpline); mySpline = static_cast<SplineObject*>(cdMySpline.result->GetIndex(0)); if (!mySpline) return nullptr; mySpline->SetName("My_Spline"); mySpline->SetRelPos(Vector(0, -bc->GetFloat(SPLINE_HEIGHT) + bc->GetFloat(SPLINE_LENGTH) * 3 / 4, -bc->GetFloat(SPLINE_LENGTH) / 2)); mySpline->InsertUnderLast(myNull); Vector* padrMySpline = mySpline->GetPointW(); if (!padrMySpline) return nullptr; padrMySpline[0] = Vector(bc->GetFloat(SPLINE_WIDTH) / 2, 0, 0); padrMySpline[1] = Vector(-bc->GetFloat(SPLINE_WIDTH) / 2, 0, 0); padrMySpline[2] = Vector(-bc->GetFloat(SPLINE_WIDTH) / 2, -bc->GetFloat(SPLINE_HEIGHT), 0); padrMySpline[3] = Vector(bc->GetFloat(SPLINE_WIDTH) / 2, -bc->GetFloat(SPLINE_HEIGHT), 0); padrMySpline[4] = Vector(bc->GetFloat(SPLINE_WIDTH) / 2, 0, bc->GetFloat(SPLINE_LENGTH)); padrMySpline[5] = Vector(-bc->GetFloat(SPLINE_WIDTH) / 2, 0, bc->GetFloat(SPLINE_LENGTH)); padrMySpline[6] = Vector(-bc->GetFloat(SPLINE_WIDTH) / 2, -bc->GetFloat(SPLINE_HEIGHT), bc->GetFloat(SPLINE_LENGTH)); padrMySpline[7] = Vector(bc->GetFloat(SPLINE_WIDTH) / 2, -bc->GetFloat(SPLINE_HEIGHT), bc->GetFloat(SPLINE_LENGTH)); }
Does somebody know what could cause this?
I really have no idea :sThanks in advance for your help and time!
-
On 27/07/2015 at 07:05, xxxxxxxx wrote:
Also, if I comment out al my code which has something to do with position (axis, or point position) or size, it still gives my object a size.
So, I basically create 2 spline objects, with no additional position (simply 0, 0, 0) and I join them with MCOMMAND_JOIN.
After that, with my new spline (8points) I set NO axis position, neither a point position, yet my "splineobject" is a polygonobject which definately has a size. -
On 28/07/2015 at 05:16, xxxxxxxx wrote:
Hi Casimir,
actually the above code crashed C4D on my system. Remember you are not allowed to change the active document.
So I changed your code a bit and had no problems here. If I use "Make Editable" on the generated object, there's only one spline object containing both generated splines.
Here's my code in GetVirtualObjects() :BaseObject* myNull = BaseObject::Alloc(Onull); if (!myNull) return nullptr; myNull->SetName("My Null"); SplineObject* firstSpline = SplineObject::Alloc(4, SPLINETYPE_LINEAR); if (!firstSpline) return nullptr; firstSpline->SetParameter(SPLINEOBJECT_CLOSED, GeData(true), DESCFLAGS_SET_0); //firstSpline->InsertUnderLast(myNull); SplineObject* secondSpline = SplineObject::Alloc(4, SPLINETYPE_LINEAR); if (!secondSpline) return nullptr; secondSpline->SetParameter(SPLINEOBJECT_CLOSED, GeData(true), DESCFLAGS_SET_0); //secondSpline->InsertUnderLast(myNull); SplineObject* mySpline; AutoAlloc<AtomArray> mySplineSelection; if (!mySplineSelection) return nullptr; mySplineSelection->Append(secondSpline); mySplineSelection->Append(firstSpline); AutoAlloc<BaseDocument> myDoc; if (!myDoc) return nullptr; myDoc->InsertObject(firstSpline, nullptr, nullptr); myDoc->InsertObject(secondSpline, nullptr, nullptr); ModelingCommandData cdMySpline; cdMySpline.doc = myDoc; cdMySpline.arr = mySplineSelection; if (SendModelingCommand(MCOMMAND_JOIN, cdMySpline)) { //SplineObject::Free(firstSpline); //SplineObject::Free(secondSpline); mySpline = static_cast<SplineObject*>(cdMySpline.result->GetIndex(0)); if (!mySpline) return nullptr; mySpline->SetName("My_Spline"); const Float splineHeight = 100.0; // bc->GetFloat(SPLINE_HEIGHT) const Float splineWidth = 200.0; // bc->GetFloat(SPLINE_WIDTH) const Float splineLength = 420.0; // bc->GetFloat(SPLINE_LENGTH) mySpline->SetRelPos(Vector(0, -splineHeight + splineLength * 3 / 4, -splineLength / 2)); mySpline->InsertUnderLast(myNull); Vector* padrMySpline = mySpline->GetPointW(); if (!padrMySpline) return nullptr; padrMySpline[0] = Vector(splineWidth / 2, 0, 0); padrMySpline[1] = Vector(-splineWidth / 2, 0, 0); padrMySpline[2] = Vector(-splineWidth / 2, -splineHeight, 0); padrMySpline[3] = Vector(splineWidth / 2, -splineHeight, 0); padrMySpline[4] = Vector(splineWidth / 2, 0, splineHeight); padrMySpline[5] = Vector(-splineWidth / 2, 0, splineHeight); padrMySpline[6] = Vector(-splineWidth / 2, -splineHeight, splineLength); padrMySpline[7] = Vector(splineWidth / 2, -splineHeight, splineLength); } return myNull;
-
On 28/07/2015 at 06:25, xxxxxxxx wrote:
Hi Andreas,
Thanks for your answer, I will look into that.
One more question though, I still don't understand why the same code would work in one file, and not in the other. Even worse, in my main project, I allready added the spline without any problems.
Only when I added my second splineobject (also containing two splines, the same way) it gave problems :sThanks for your help and time!
-
On 28/07/2015 at 06:50, xxxxxxxx wrote:
Hi Casimir,
I don't think, there's a general answer.
Problems arising from threading (or rather from breaking rules imposed by threading) are rarely deterministic. I'd say, most Schrödin- and Mandelbugs are probably resulting from this. The results can vary from "working for a long time and suddenly not" or "crashing immediately" to "some completely different function starts behaving strangely". There are so many factors, like runtime behavior (for example, which thread gets to run first or on multi processor, which threads run in parallel and with which timely offset), memory availability and usage,... in most cases some memory will be corrupted, due to such bugs. If this memory is not used at that moment, you might not experience any problems (while the code is still buggy). Otherwise the results can be interestingly plenty.
As I said, on my machine your code did not run at all, but crashed immediately. -
On 28/07/2015 at 07:04, xxxxxxxx wrote:
Hi Andreas,
Thanks for your answer!
I will check if it works with your code, and I will let you know.
-
On 28/07/2015 at 07:23, xxxxxxxx wrote:
Hi Andreas,
Your answer was right!
When I do the modelling command in a newly created document, I have no problems at all.
Thanks for your help and time!You can mark this thread as solved!