Solved Accessing Sweep's spline data from C4DImportExport.cpp

Hello,
In the process of writing tool (https://github.com/syanenko/pov-tools) for exporting C4D objects to POV-Ray, I've ran into following problem: can not find any information about accessing spline data, available in Details tab of Sweep node, from C++.

This spline is marked on following image:
c4d_spline.png

I would like to use this data to alter sphere radius in POV's Sphere sweep object. The code of this tool is based on C4DImportExport.cpp example.

Could you please point me in the right direction?

Thanks in advance,
Sergey (Yesbird).

--
YB

Hi,

It's true that the sweep nurbs is not there in the example. Supporting it is easy, at least once you know how to ^^'
in the file alien_def.h you must add a class to support the SweepNurb

class AlienSweepObjectData : public NodeData
{
	INSTANCEOF(AlienSweepObjectData, NodeData)

public:
	virtual Bool Execute();
};

And of course you need to implement it and retrieve all the parameter you need.

Bool AlienSweepObjectData::Execute()
{
	BaseObject* op = (BaseObject*)GetNode();
	Char* pChar = op->GetName().GetCStringCopy();
	if (pChar)
	{
		printf("\n - AlienExtrudeObjectData (%d): %s\n", (int)op->GetType(), pChar);
		DeleteMem(pChar);
	}
	else
		printf("\n - AlienExtrudeObjectData (%d): <noname>\n", (int)op->GetType());


	GeData splineScaleParameter;
	op->GetParameter(SWEEPOBJECT_SPLINESCALE, splineScaleParameter);
	
	if (splineScaleParameter.GetType() == CUSTOMDATATYPE_SPLINE)
	{
		SplineData* splineData = static_cast<SplineData*>(splineScaleParameter.GetCustomDataType(CUSTOMDATATYPE_SPLINE));

		if (splineData != nullptr)
		{
			Int32 knotCount = splineData->GetKnotCount();
			printf("\n   - number of knots %d \n", (int)knotCount);
		}
	}
	return false;
}

Now, to make the object getting supported, you must add a case in the function NodeData *AllocAlienObjectData(Int32 id, Bool &known, BaseList2D* node) like so:

case Osweep:
	m_data = NewObj(AlienSweepObjectData);
	break;

Now that the object is getting called you can retrieve all the data you want from it. This parameter is storing SplineData type. In our "regular" sdk (available with all c4d build in the main directory you have a zip archive) we have an example on how to retrieve or set SplineData. The file is in the directory "gui" and is called "objectdata_descriptions.cpp"

// somewhere in objectdata_descriptions.cpp
node->GetParameter(DescID(ID_DYNAMIC_ELEMENT + DESCRIPTIONELEMENTS::SPLINE), data, DESCFLAGS_GET::NONE);

if (data.GetType() == CUSTOMDATATYPE_SPLINE)
{
	SplineData* splineData = (SplineData*)data.GetCustomDataType(CUSTOMDATATYPE_SPLINE);

	if (splineData != nullptr)
	{

		splineData->SetRange(0.0, 100.0, 0.1, 0.0, 100, 0.0);

		splineData->DeleteAllPoints();
		splineData->InsertKnot(0, 0);
		splineData->InsertKnot(100, 100);

		// set parameter
		node->SetParameter(DescID(ID_DYNAMIC_ELEMENT + DESCRIPTIONELEMENTS::SPLINE), data, DESCFLAGS_SET::NONE);
	}
}

Finally, to retrieve an ID of a parameter you can drag and drop it on the console
For the sweep object you are interested by SWEEPOBJECT_SPLINESCALE and SWEEPOBJECT_SPLINEROTATION

let me know if i forgot something or if it is not clear.

Cheers,
Manuel

MAXON SDK Specialist

MAXON Registered Developer

Hi, @manuel.

Many thanks for fast and detailed response. Fortunately, I've alredy passed all steps, but last - getting spline points (not knots), and unfortunately, can not do it by strange issue: in file customgui_splinecontrol.h method that I need:

//Vector GetPoint(Float r) const;

is commented out and when uncommented, gives 'unresolved externa' error.

I have the lates SDK version:
22.008_RBCinewaresdk22.0_355130

Could you please help me to find workaroud for this problem ?

Thanks in advance,
Sergey (Yesbird).

--
YB

hi,

ha yes, did not saw that. This is not available in the implementation, which is why it is commented out (and why you have this error message 'unresolved external')
I first though you could create a spline and use GetSplinePoint but this is not available neither.

The only option is to retrieve the knots corresponding to the range of your value and calculate yourself the interpolation.
From each knot you can retrieve the CustomSplineKnot data from where you can get the position and the right or left tangent. that will be your four points to calculate the interpolation. Of course, t must be a value from 0.0 to 1.0. That should be your initial value minus the first knot position.x. <- It is more complicate than that but you have the idea 😛

There are only three interpolation modes, but you might want to support only Bezier and linear.

CustomSplineKnotInterpolationBezier 	Bezier interpolation.
CustomSplineKnotInterpolationLinear 	Linear interpolation.
CustomSplineKnotInterpolationCubic 	Cubic interpolation.

Cheers,
Manuel

MAXON SDK Specialist

MAXON Registered Developer

Hi,@manuel.

Thank you for explanation, I will calculate spline points myself, no problem.

All the best,
....
YB

--
YB

Hi, @Manuel
You wrote:

This is not available in the implementation, which is why it is commented out (and why you have this error message 'unresolved external')

about this method:

// Vector GetPoint(Float r) const;

Although now I have spline implementation (cubic and linear) and using it for calculation the more neat solution could be to implementing method, mentioned above.

Could you tell me please, if you have plans of it's implementation ?
If not, I could implement it myself, having access to Cineware sources.

All the best,
....
YB

--
YB

@yesbird said in Accessing Sweep's spline data from C4DImportExport.cpp:

Could you tell me please, if you have plans of it's implementation ?
If not, I could implement it myself, having access to Cineware sources.

HI,

I'm sorry but we cannot share this kind of information or the source code. The function is implemented in the regular SDK. i am sure that there were technical difficulties to make it available in Cineware.

Cheers,
Manuel

MAXON SDK Specialist

MAXON Registered Developer

Hi, @Manuel.

I understand, thank you.

All the best,
....
YB

--
YB