示例#1
0
void MakeBentCylinder()
{
	float radius = 10, height = 10, angle = 10;
	int segments = 20;

	// Create a new object using CreateInstance()
	Object *obj = (Object*)CreateInstance(GEOMOBJECT_CLASS_ID, Class_ID(CYLINDER_CLASS_ID, 0));

	// Get ahold of the parameter block
	IParamArray *iCylParams = obj->GetParamBlock();

	// Get the current animation time
	TimeValue time = GetCOREInterface()->GetTime();

	// Set the value of radius, height and segments.
	iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_RADIUS), time, radius);
	iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_HEIGHT), time, height);
	iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_SEGMENTS), time, segments);
	
	auto ip = GetCOREInterface();
	// Create the object
	INode *node = ip->CreateObjectNode(obj);

	// Create a bend modifier
	//Modifier *bend = (Modifier*)ip->CreateInstance(OSM_CLASS_ID, Class_ID(BENDOSM_CLASS_ID, 0));
	//
	//// Set the bend angle
	//IParamBlock2* ipBendBlock = ((Animatable*)bend)->GetParamBlock(0);  //only one pblock2
	//ipBendBlock->SetValue(BEND_ANGLE, time, angle);

	//// Create a node in the scene for the object
	//// Note that COREInterface12 derives from Interface7
	//GetCOREInterface12()->AddModifier(*node, *bend);
}
示例#2
0
void addbend()
{
	try
	{
		float radius = 10, height = 10, angle = 10;
		int segments = 20;

		// Create a new object using CreateInstance()
		Object *obj = (Object*)CreateInstance(GEOMOBJECT_CLASS_ID, Class_ID(CYLINDER_CLASS_ID, 0));

		// Get ahold of the parameter block
		IParamArray *iCylParams = obj->GetParamBlock();

		// Get the current animation time
		TimeValue time = GetCOREInterface()->GetTime();

		// Set the value of radius, height and segments.
		iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_RADIUS), time, radius);
		iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_HEIGHT), time, height);
		iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_SEGMENTS), time, segments);
		
		auto* ip = GetCOREInterface();
		INode *node = ip->CreateObjectNode(obj);
		
		//Create a new object using CreateInstance()
		auto pINode = ip->GetSelNode(0);
		log(L"New node name is {0} : \n", pINode->GetName());

		// Get the current animation time

		/*iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_RADIUS), time, 10);
		iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_HEIGHT), time, 20);
		iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_SEGMENTS), time, 10);*/

		// Create a bend modifier
		Modifier *bend = (Modifier*)ip->CreateInstance(OSM_CLASS_ID, Class_ID(BENDOSM_CLASS_ID, 0));

		log(L"{}",bend->GetName().data());

		// Set the bend angle
		IParamBlock2* ipBendBlock = ((Animatable*)bend)->GetParamBlock(0);  //only one pblock2
		//ipBendBlock->SetValue(BEND_ANGLE, time, 10);
		ipBendBlock->SetValue(BEND_ANGLE, time, angle);

		GetCOREInterface12()->AddModifier(*pINode, *bend);
		GetCOREInterface12()->AddModifier(*node, *bend);

	}
	catch (const std::exception& e)
	{
		/*e.what();
		log("Exception: " + std::string(e.what()));*/
	}
}
示例#3
0
static INode *MakeGroupObj(Interface *ip,Point3 p)
{
    Object *obj = (Object*)ip->CreateInstance(
                      GEOMOBJECT_CLASS_ID,
                      Class_ID(CYLINDER_CLASS_ID,0));
    IParamArray *iCylParams = obj->GetParamBlock();
    int rad = obj->GetParamBlockIndex(CYLINDER_RADIUS);
    iCylParams->SetValue(rad,TimeValue(0),20.0f);
    int height = obj->GetParamBlockIndex(CYLINDER_HEIGHT);
    iCylParams->SetValue(height,TimeValue(0),50.0f);
    INode *node = ip->CreateObjectNode(obj);
    Matrix3 tm(1);
    tm.SetTrans(p);
    node->SetNodeTM(0,tm);
    return node;
}
示例#4
0
void UtilTest::MakeObject()
{
    // Create a new object through the CreateInstance() API
    Object *obj = (Object*)ip->CreateInstance(
                      GEOMOBJECT_CLASS_ID,
                      Class_ID(CYLINDER_CLASS_ID,0));
    assert(obj);

    // Get a hold of the parameter block
    IParamArray *iCylParams = obj->GetParamBlock();
    assert(iCylParams);

    // Set the value of radius, height and segs.
    int rad = obj->GetParamBlockIndex(CYLINDER_RADIUS);
    assert(rad>=0);
    iCylParams->SetValue(rad,TimeValue(0),30.0f);
    int height = obj->GetParamBlockIndex(CYLINDER_HEIGHT);
    assert(height>=0);
    iCylParams->SetValue(height,TimeValue(0),100.0f);
    int segs = obj->GetParamBlockIndex(CYLINDER_SEGMENTS);
    assert(segs>=0);
    iCylParams->SetValue(segs,TimeValue(0),10);

    // Create a derived object that references the cylinder
    IDerivedObject *dobj = CreateDerivedObject(obj);

    // Create a bend modifier
    Modifier *bend = (Modifier*)ip->CreateInstance(
                         OSM_CLASS_ID,
                         Class_ID(BENDOSM_CLASS_ID,0));

    // Set the bend angle - ParamBlock2
    IParamBlock2* iBendBlock = ((Animatable*)bend)->GetParamBlock(0);  //only one pblock2
    assert(iBendBlock);
    ParamID pid = BEND_ANGLE;
    iBendBlock->SetValue(pid,TimeValue(0),90.0f);

    // Add the bend modifier to the derived object.
    dobj->AddModifier(bend);

    // Create a node in the scene that references the derived object
    INode *node = ip->CreateObjectNode(dobj);

    // Name the node and make the name unique.
    TSTR name(_T("MyNode"));
    ip->MakeNameUnique(name);
    node->SetName(name);

    // Get ready to add WSMs to this node
    node->CreateWSMDerivedObject();
    IDerivedObject *wsdobj = node->GetWSMDerivedObject();
    if (wsdobj) {
        WSMObject *swobj = (WSMObject*)ip->CreateInstance(
                               WSM_OBJECT_CLASS_ID,
                               Class_ID(SINEWAVE_OBJECT_CLASS_ID,0));
        int ix;
        IParamArray *iRipParams = swobj->GetParamBlock();

        ix = swobj->GetParamBlockIndex(RWAVE_AMPLITUDE);
        iRipParams->SetValue(ix,TimeValue(0),10.0f);

        ix = swobj->GetParamBlockIndex(RWAVE_AMPLITUDE2);
        iRipParams->SetValue(ix,TimeValue(0),10.0f);

        ix = swobj->GetParamBlockIndex(RWAVE_WAVELEN);
        iRipParams->SetValue(ix,TimeValue(0),40.0f);

        ix = swobj->GetParamBlockIndex(RWAVE_CIRCLES);
        iRipParams->SetValue(ix,TimeValue(0),10);

        ix = swobj->GetParamBlockIndex(RWAVE_DIVISIONS);
        iRipParams->SetValue(ix,TimeValue(0),4);

        ix = swobj->GetParamBlockIndex(RWAVE_SEGMENTS);
        iRipParams->SetValue(ix,TimeValue(0),16);

        INode *swnode = ip->CreateObjectNode(swobj);

        TSTR swname(_T("RippleNode"));
        ip->MakeNameUnique(swname);
        node->SetName(swname);

        // Create a Space Warp Modifier
        Modifier *swmod = swobj->CreateWSMMod(swnode);
        if (swmod) {
            wsdobj->AddModifier(swmod);
        }
    }

    // Redraw the views
    ip->RedrawViews(ip->GetTime());
}
示例#5
0
文件: physics.cpp 项目: skopp/rush
JObject* RBExport::ProcessPhysicsObject( INode* node )
{
    ObjectState os = node->EvalWorldState( m_CurTime ); 
    Object* pObj = os.obj;
    const char* pNodeName = node->GetName();

    if (!pObj)
    {
        Warn( "Physics node %s is invalid.", pNodeName );
    }

    JObject* pPhysObj = NULL;
    Mat4 objTM = Convert( GetLocalTM( node, m_CurTime ) );

    JString hostName = "";

    ExpNode* pExportedParent = GetExportedNode( node->GetParentNode() );
    if (pExportedParent && pExportedParent->m_pObject)
    {
        JObject* pParentObj = pExportedParent->m_pObject;
        if (obj_cast<PhysBody>( pParentObj ))
        {
            hostName = pParentObj->GetName();
        }
        else if (obj_cast<JBone>( pParentObj ))
        {
            hostName = pParentObj->GetName();
        }
    }

    //  check for joint type
    DWORD scID = pObj->SuperClassID();
    if (scID == HELPER_CLASS_ID) 
    {
        PhysJoint* pJoint = new PhysJoint(); 
        pJoint->SetHostBone( hostName.c_str() );
        pPhysObj = pJoint;
    }
    else
    {
        CStr className;
        pObj->GetClassName( className );
        IParamArray* pParam = pObj->GetParamBlock();
        IParamBlock* pParamBlock = NULL;

        if (pParam) pParamBlock = pParam->GetParamBlock();

        if (!stricmp( className, "sphere" ))
        {
            ColSphere* pSphere = new ColSphere();
            pPhysObj = pSphere;
            float radius = 0.0f;
            pParamBlock->GetValue( SPHERE_RADIUS, 0, radius, FOREVER );
            pSphere->SetRadius( radius );
            pSphere->SetHost( hostName.c_str() );
            pSphere->SetOffsetTM( objTM );
        }

        if (!stricmp( className, "box" ))
        {
            ColBox* pBox = new ColBox();
            pPhysObj = pBox;
            Vec3 ext;
            pParamBlock->GetValue( BOXOBJ_LENGTH, 0, ext.x, FOREVER );
            pParamBlock->GetValue( BOXOBJ_WIDTH,  0, ext.y, FOREVER );
            pParamBlock->GetValue( BOXOBJ_HEIGHT, 0, ext.z, FOREVER );
            pBox->SetExtents( ext );
            pBox->SetHost( hostName.c_str() );
            pBox->SetOffsetTM( objTM );
        }
        
        if (!stricmp( className, "capsule" ))
        {
            ColCapsule* pCapsule = new ColCapsule();
            pPhysObj = pCapsule;
            int   bCenters = 0;
            float radius   = 0.0f;
            float height   = 0.0f;
            pParamBlock->GetValue( PB_RADIUS,  0, radius,   FOREVER );
            pParamBlock->GetValue( PB_HEIGHT,  0, height,   FOREVER );
            pParamBlock->GetValue( PB_CENTERS, 0, bCenters, FOREVER );
            pCapsule->SetRadius( radius );
            pCapsule->SetHeight( height );
            pCapsule->SetHost( hostName.c_str() );
            pCapsule->SetOffsetTM( objTM );
        }

        if (!stricmp( className, "cylinder" ))
        {
            ColCylinder* pCylinder = new ColCylinder();
            pPhysObj = pCylinder;
            int   bCenters = 0;
            float radius   = 0.0f;
            float height   = 0.0f;
            pParamBlock->GetValue( PB_RADIUS,  0, radius,   FOREVER );
            pParamBlock->GetValue( PB_HEIGHT,  0, height,   FOREVER );
            pParamBlock->GetValue( PB_CENTERS, 0, bCenters, FOREVER );
            pCylinder->SetRadius( radius );
            pCylinder->SetHeight( height );
            pCylinder->SetHost( hostName.c_str() );
            pCylinder->SetOffsetTM( objTM );
        }

        if (!stricmp( className, "teapot" ))
        {
            //  by teapot we represent physical body (point of mass)
            PhysBody* pBody = new PhysBody();
            pBody->SetHostBone( hostName.c_str() );
            pPhysObj = pBody;
            pBody->SetOffsetTM( objTM );
        }

        //  if none of above,  try to export as trimesh collision primitive
        if (pPhysObj == NULL && scID == GEOMOBJECT_CLASS_ID)
        {
            ColMesh* pMesh = GetColMesh( node );
            if (pMesh)
            {
                pPhysObj = pMesh;
                pMesh->SetHost( hostName.c_str() );
                pMesh->SetOffsetTM( objTM );
            }
        }
    }
    
    if (pPhysObj)
    {
        if (!m_pPhysicsGroup)
        {
            m_pPhysicsGroup = new JGroup();
            m_pPhysicsGroup->SetName( "physics" );
        }
        pPhysObj->SetName( pNodeName );
        m_pPhysicsGroup->AddChild( pPhysObj );
    }
    else
    {
        Warn( "Unrecognized physics object type in  node %s", pNodeName );
        return NULL;
    }
    return pPhysObj;
} // RBExport::ProcessPhysicsObject