On 27/01/2015 at 13:17, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R16
Platform: Windows ;
Language(s) : C++ ;
---------
Hello Forum,
I'm working on a plugin that places objects along a spline. SplineHelp::GetLinePointSegment() is returning results I did not expect(probably more accurately(I do not understand)). I have created a simple CommandData plugin to demonstrate:
// main.cpp
#include "c4d.h"
#include "splinehelp_test.h"
Bool PluginStart( void )
{
if ( !RegisterSplineHelpTest() )
{
return false;
}
return true;
}
void PluginEnd( void )
{
}
Bool PluginMessage( Int32 id, void* data )
{
return false;
}
// splinehelp_test.h
#ifndef SPLINEHELP_TEST_H_
#define SPLINEHELP_TEST_H_
#include "c4d.h"
class SplineHelpTest : public CommandData
{
public:
virtual Bool Execute( BaseDocument* doc );
static SplineHelpTest* Alloc()
{
return NewObjClear( SplineHelpTest );
}
};
Bool RegisterSplineHelpTest();
#endif // SPLINEHELP_TEST_H_
// splinehelp_test.cpp
#include "lib_splinehelp.h"
#include "splinehelp_test.h"
#define PID_SPLINEHELP_TEST 1034539 //unique from plugincafe.com
Bool SplineHelpTest::Execute( BaseDocument* doc )
{
BaseObject* op = doc->GetActiveObject();
if ( ! op )
{
GeOutString( "SplineHelp Test\n"
"Plugin Error:\n"
"No object selected.\n"
"Execution stopping.",
GEMB_OK );
return true;
}
if ( op->GetType() != Ospline )
{
GeOutString( "SplineHelp Test\n"
"Plugin Error:\n"
"Selected object is not Ospline.\n"
"Execution stopping.",
GEMB_OK );
return true;
}
SplineHelp* spline_help = SplineHelp::Alloc();
if ( ! spline_help )
{
GeOutString( "SplineHelp Test\n"
"Plugin Error:\n"
"Could not allocate SplineHelp.\n"
"Execution stopping.",
GEMB_OK );
return true;
}
Bool init_ok = spline_help->InitSpline( op, Vector(), nullptr, false, false, true, true );
if ( ! init_ok )
{
GeOutString( "SplineHelp Test\n"
"Plugin Error:\n"
"Could not Initialize SplineHelp.\n"
"Execution stopping.",
GEMB_OK );
return true;
}
Int32 pcnt = static_cast<PointObject*>( op )->GetPointCount();
for ( Int32 i = 0; i < pcnt; i++ )
{
GePrint( "------------------------" );
GePrint( "spline point idx: " + String::IntToString( i ) );
Int32 line_point_idx = spline_help->SplineToLineIndex( i );
GePrint( "line point idx: " + String::IntToString( line_point_idx ) );
Float64 offset;
Int32 local_idx;
Int32 segment_idx;
spline_help->GetLinePointSegment( line_point_idx, &offset, &local_idx, &segment_idx );
GePrint( "offset: " + String::FloatToString( offset ) );
}
return true;
}
Bool RegisterSplineHelpTest()
{
return RegisterCommandPlugin( PID_SPLINEHELP_TEST, String( "SplineHelp Test" ), 0, nullptr, String( "SplineHelp Test Help" ), SplineHelpTest::Alloc() );
}
I created a curved, 2-point bezier spline and ran this plugin with the following results:
------------------------
spline point idx: 0
line point idx: 0
offset: 0
------------------------
spline point idx: 1
line point idx: 33
offset: 0.971
I expected the offset of the second spline point to be 1.0.
Next I made a 3-point bezier spline where all of the points are in a straight line, all of the tangent values are zero and the 2nd point is exactly in the center of the first and last points. Here are the results:
------------------------
spline point idx: 0
line point idx: 0
offset: 0
------------------------
spline point idx: 1
line point idx: 1
offset: 0.333
------------------------
spline point idx: 2
line point idx: 2
offset: 0.667
I expected the 2nd point's offset to be 0.5 and the last point's offset to be 1.0.
Next I made the interpolation of all points soft and twisted the tangents around to make a curvy, 3-point spline. Here are the results:
------------------------
spline point idx: 0
line point idx: 0
offset: 0
------------------------
spline point idx: 1
line point idx: 28
offset: 0.509
------------------------
spline point idx: 2
line point idx: 54
offset: 0.982
I had no expectation for the 2nd point, but did expect the 3rd point have an offset of 1.0.
If anyone understands how SplineHelp::GetLinePointSegment() works, an explanation would be greatly appreciated by me.
Thanks for your time,
Joe