Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstrates a simple plane mesh operation for the Modo procedural modelling system.
#include <lxsdk/lx_mesh.hpp>
#include <lxsdk/lx_pmodel.hpp>
#include <lxsdk/lx_seltypes.hpp>
#include <lxsdk/lxu_attributes.hpp>
#define SERVER_NAME "pmodel.createPlane"
#define ATTRs_SIZE "size"
#define ATTRi_SIZE 0
class MeshOp :
public CLxImpl_MeshOperation,
public CLxDynamicAttributes
{
public:
static void initialize ()
{
CLxGenericPolymorph *srv = NULL;
srv = new CLxPolymorph <MeshOp>;
srv->AddInterface (new CLxIfc_MeshOperation <MeshOp>);
srv->AddInterface (new CLxIfc_Attributes <MeshOp>);
srv->AddInterface (new CLxIfc_StaticDesc <MeshOp>);
lx::AddServer (SERVER_NAME, srv);
}
MeshOp ()
{
/*
* Add a single distance attribute to control the plane size. This
* will automatically be converted into a distance channel. Setting
* a default value will set the default channel value.
*/
dyna_Add (ATTRs_SIZE, LXsTYPE_DISTANCE);
attr_SetFlt (ATTRi_SIZE, 1.0);
_size = 1.0;
}
LxResult
mop_Evaluate (
LXtObjectID mesh_obj,
LXtID4 type,
LXtMarkMode mode)
{
CLxUser_Mesh mesh (mesh_obj);
CLxUser_Polygon polygon;
CLxUser_Point point;
LXtPolygonID poly_id = NULL;
LXtPointID point_id[4];
LXtVector pos;
LxResult result = LXe_FAILED;
static double positions[4][3] = {{-0.5, 0.0, -0.5}, {0.5, 0.0, -0.5}, {0.5, 0.0, 0.5}, {-0.5, 0.0, 0.5}};
/*
* Read the size attributes, the same as any other attribute. This
* is set by the wrapper modifier using the channel value.
*/
_size = dyna_Float (ATTRi_SIZE, 1.0);
if (mesh.test ())
{
polygon.fromMesh (mesh);
point.fromMesh (mesh);
if (polygon.test () && point.test ())
{
/*
* Create the points and polygon in the mesh.
*/
if (_size > 0.0)
{
for (unsigned i = 0; i < 4; i++)
{
LXx_VSCL3 (pos, positions[i], _size);
point.New (pos, &point_id[i]);
}
polygon.New (LXiPTYP_FACE, point_id, 4, 0, &poly_id);
mesh.SetMeshEdits (LXf_MESHEDIT_GEOMETRY);
}
result = LXe_OK;
}
}
return result;
}
static LXtTagInfoDesc descInfo[];
double _size;
};
/*
* The LXsMESHOP_PMODEL server tag will automatically convert the mesh operation into
* an item and modifier. Any attributes will be converted into channels.
*/
LXtTagInfoDesc MeshOp::descInfo[] =
{
{ LXsMESHOP_PMODEL, "." },
{ 0 }
};
void
initialize ()
{
MeshOp::initialize ();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment