generate point on edge
Posted: 28 Dec 2017, 18:17
Hi i want to create very simple ice node that can generate point on edge, but i'm get lost when it doesn't create number point that i want per edge
This is a ice node --> https://drive.google.com/open?id=1kL1To ... MSItSbriqn
This is a ice node --> https://drive.google.com/open?id=1kL1To ... MSItSbriqn
Code: Select all
// PointGeneratorFromGeometry Plugin
// Initial code generated by Softimage SDK Wizard
// Executed Mon Feb 2 15:16:26 EST 2009 by belzilm
//
//
// Tip: You need to compile the generated code before you can load the plug-in.
// After you compile the plug-in, you can load it by clicking Update All in the Plugin Manager.
#include <xsi_application.h>
#include <xsi_context.h>
#include <xsi_pluginregistrar.h>
#include <xsi_status.h>
#include <xsi_icenodecontext.h>
#include <xsi_icenodedef.h>
#include <xsi_command.h>
#include <xsi_factory.h>
#include <xsi_math.h>
#include <xsi_vector2f.h>
#include <xsi_vector3f.h>
#include <xsi_vector4f.h>
#include <xsi_matrix3f.h>
#include <xsi_matrix4f.h>
#include <xsi_rotationf.h>
#include <xsi_quaternionf.h>
#include <xsi_color4f.h>
#include <xsi_shape.h>
#include <xsi_indexset.h>
#include <xsi_dataarray.h>
#include <xsi_dataarray2D.h>
#include <xsi_icegeometry.h>
#include <xsi_doublearray.h>
#include <xsi_random.h>
#include <xsi_progressbar.h>
#include <xsi_uitoolkit.h>
#include <vector>
// Defines port, group and map identifiers used for registering the ICENode
enum IDs
{
ID_IN_geometry = 0,
ID_IN_sampling_type = 1,
ID_IN_random_point_count = 2,
ID_G_100 = 100,
ID_G_101 = 101,
ID_OUT_sample_points = 200,
ID_TYPE_CNS = 400,
ID_STRUCT_CNS,
ID_CTXT_CNS,
ID_UNDEF = ULONG_MAX
};
XSI::CStatus RegisterPointGeneratorFromGeometry(XSI::PluginRegistrar& in_reg);
using namespace XSI;
XSIPLUGINCALLBACK CStatus XSILoadPlugin(PluginRegistrar& in_reg)
{
in_reg.PutAuthor(L"belzilm");
in_reg.PutName(L"PointGeneratorFromGeometry Plugin");
in_reg.PutVersion(1, 0);
RegisterPointGeneratorFromGeometry(in_reg);
return CStatus::OK;
}
CStatus RegisterPointGeneratorFromGeometry(PluginRegistrar& in_reg)
{
ICENodeDef nodeDef;
nodeDef = Application().GetFactory().CreateICENodeDef(L"PointGeneratorFromGeometry", L"Point Generator From Geometry");
CStatus st;
// Add input ports and groups.
st = nodeDef.AddPortGroup(ID_G_100);
st.AssertSucceeded();
st = nodeDef.AddPortGroup(ID_G_101);
st.AssertSucceeded();
st = nodeDef.AddInputPort(ID_IN_geometry, ID_G_100,
siICENodeDataGeometry, siICENodeStructureSingle, siICENodeContextSingleton,
L"geometry", L"geometry");
st.AssertSucceeded();
st = nodeDef.AddInputPort(ID_IN_sampling_type, ID_G_101,
siICENodeDataLong, siICENodeStructureSingle, siICENodeContextSingleton,
L"sampling type", L"sampling type", (LONG)0);
st.AssertSucceeded();
st = nodeDef.AddInputPort(ID_IN_random_point_count, ID_G_101,
siICENodeDataLong, siICENodeStructureSingle, siICENodeContextSingleton,
L"random points", L"random points", (LONG)3);
st.AssertSucceeded();
// Add output ports.
st = nodeDef.AddOutputPort(ID_OUT_sample_points,
siICENodeDataVector3, siICENodeStructureSingle, siICENodeContextElementGenerator,
L"sample points", L"sample points");
st.AssertSucceeded();
PluginItem nodeItem = in_reg.RegisterICENode(nodeDef);
nodeItem.PutCategories(L"Custom ICENode Sample");
return CStatus::OK;
}
/*
PointGeneratorFromGeometry_BeginEvaluate:
This callback generates points according to the sampling method selected by the user.
*/
XSIPLUGINCALLBACK CStatus PointGeneratorFromGeometry_BeginEvaluate(ICENodeContext& in_ctxt)
{
Application app;
CDataArrayLong samplingType(in_ctxt, ID_IN_sampling_type);
CDataArrayLong randomPointCount(in_ctxt, ID_IN_random_point_count);
CICEGeometry geom(in_ctxt, ID_IN_geometry);
CDoubleArray points;
geom.GetPointPositions(points);
MATH::CMatrix4f transfo;
geom.GetTransformation(transfo);
std::vector< MATH::CVector3f >* pPointVector = new std::vector< MATH::CVector3f >;
switch (samplingType[0])
{
/* segment center points */
case 2:
{
ULONG nCount = geom.GetSegmentCount();
in_ctxt.PutNumberOfElementsToProcess(nCount);
CLongArray indices;
geom.GetSegmentIndices(indices);
ULONG nOffset = 0;
for (ULONG i = 0; i<nCount; i++)
{
MATH::CVector3f vTotal;
MATH::CVector3f v0((float)points[indices[nOffset] * 3],
(float)points[indices[nOffset] * 3 + 1],
(float)points[indices[nOffset] * 3 + 2]);
MATH::CVector3f v((float)points[indices[nOffset+1] * 3],
(float)points[indices[nOffset+1] * 3 + 1],
(float)points[indices[nOffset+1] * 3 + 2]);
//app.LogMessage(CString(i) +"-->"+ CString(nOffset));
app.LogMessage(CString(nOffset));
app.LogMessage(CString(nOffset+1));
for (int o = 0; o <= 10; o++) //resample .. ?
{
vTotal.MulByMatrix4InPlace(transfo);
vTotal.LinearlyInterpolate(v0, v, (float)o/99);
pPointVector->push_back(vTotal);
}
nOffset += 2;
}
}
break;
default:
{
in_ctxt.PutNumberOfElementsToProcess(0);
}
};
in_ctxt.PutUserData((CValue::siPtrType) pPointVector);
return CStatus::OK;
}
/*
PointGeneratorFromGeometry_Evaluate:
Sets the node output port with the points computed in the _BeginEvaluate callback.
*/
XSIPLUGINCALLBACK CStatus PointGeneratorFromGeometry_Evaluate(ICENodeContext& in_ctxt)
{
ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID();
switch (out_portID)
{
case ID_OUT_sample_points:
{
std::vector<MATH::CVector3f>* pPointVector = (std::vector<MATH::CVector3f>*)(CValue::siPtrType)in_ctxt.GetUserData();
CDataArrayVector3f outData(in_ctxt);
CIndexSet indexSet(in_ctxt);
for (CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
{
// Note: The output buffer is relative to the 'batch' data therefore we can index the batch with the iterator directly.
// On the other hand pPointVector has to be indexed with the 'batch' global index i.e. CIndexSet::Iterator::GetAbsoluteIndex()
outData[it] = (*pPointVector)[it.GetAbsoluteIndex()];
}
}
break;
};
return CStatus::OK;
}
/*
PointGeneratorFromGeometry_EndEvaluate:
Release the memeory allocated to store the points;
*/
XSIPLUGINCALLBACK CStatus PointGeneratorFromGeometry_EndEvaluate(ICENodeContext& in_ctxt)
{
CValue userData = in_ctxt.GetUserData();
if (userData.IsEmpty())
{
return CStatus::OK;
}
std::vector<MATH::CVector3f>* pPointVector = (std::vector<MATH::CVector3f>*)(CValue::siPtrType)userData;
if (pPointVector)
delete pPointVector;
in_ctxt.PutUserData(CValue());
return CStatus::OK;
}