Accessing Dynamics Fields [MEL]


 

 

Dynamics Fields allow maya users to affect particle systems, soft bodies and cloth in a number of pre-defined ways. The field types Maya currently supports are :

  • MFn::kAir
  • MFn::kDrag
  • MFn::kGravity
  • MFn::kNewton
  • MFn::kRadial
  • MFn::kTurbulence
  • MFn::kUniform
  • MFn::kVortex
  • MFn::kVolumeAxis

All of those types are derived from the general base class MFn::kField. This inturn is derived from an MFn::kTransform node. This means that accessing most of the field data, has already been covered in the transform and animation chapters. Additional information can be extracted using a specialised function set for each field type.

 

 

 

 

 

Shared Field Data

The base class of all dynamics fields has some generic attributes that control the force and distance range over which the field is active.

 

 

 

 


#include<maya/MFnField.h>

void OutputField(MObject& obj )
{
 

// attach the function set to the object
MFnField
fn(obj);

// fields are inherited from transform nodes. We may
// as well re-use our transform functions

outputTransformData
(obj);
outputParentingInfo(obj);

cout<<"\tMagnitude "<<fn.magnitude()<<endl;
cout<<"\tAttenuation "<<fn.attenuation()<<endl;
cout<<"\tMaxDistance "<<fn.maxDistance()<<endl;
cout<<"\tUseMaxDistance "<<fn.useMaxDistance()<<endl;
cout<<"\tPerVertex "<<fn.perVertex()<<endl;

}



 

Air Field

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


#include<maya/MFnAirField.h>

void OutputAir(MObject& obj)
{
 

// attach the function set to the object
MFnAirField
fn(obj);

// write name
cout << "Air " << fn.name().asChar() << endl;

OutputField(obj);

const MVector& V = fn.direction();

cout << "\tDirection "
<< V.x << " "
<< V.y << " "
<< V.z << "\n";

cout << "\tSpeed " << fn.speed() << endl;

cout << "\tInheritVelocity"
<< V.inheritVelocity() << endl;

cout << "\tInheritRotation"
<< V.inheritRotation() << endl;

cout << "\tComponentOnly"
<< V.componentOnly() << endl;

cout << "\tSpread " << fn.spread() << endl;

cout << "\tEnableSpread"
<< V.enableSpread() << endl;
}


 

 

Drag Field

 

 

 

 

 

 

 

 

 

 

 

#include<maya/MFnDragField.h>

void OutputDrag(MObject& obj)
{
 

// attach the function set to the object
MFnDragField
fn(obj);

// write name
cout << "Drag " << fn.name().asChar() << endl;

OutputField(obj);

const MVector& V = fn.direction();

cout << "\tDirection "
<< V.x << " "
<< V.y << " "
<< V.z << "\n";

cout << "\tUseDirection"<< fn.useDirection()<< endl;

}


 

 

Gravity Field

 

 

 

 

 

 

 

 

 

#include<maya/MFnGravityField.h>

void OutputGravity(MObject& obj)
{
 

// attach the function set to the object
MFnGravityField
fn(obj);

// write name
cout << "Gravity " << fn.name().asChar() << endl;

OutputField(obj);

const MVector& V = fn.direction();

cout << "\tDirection "
<< V.x << " "
<< V.y << " "
<< V.z << "\n";
}

 

 

Newton Field

 

 

 

 

 

 

 

#include<maya/MFnNewtonField.h>

void OutputNewton(MObject& obj)
{
 

// attach the function set to the object
MFnNewtonField fn(obj);

// write name
cout << "Newton " << fn.name().asChar() << endl;

OutputField(obj);

cout<< "\tMinDistance " << fn.minDistance() <<endl;

}

 

 

Radial Field

 

 

 

 

 

 

 

 

#include<maya/MFnRadialField.h>

void OutputRadial(MObject& obj)
{
 

// attach the function set to the object
MFnRadialField fn(obj);

// write name
cout << "Radial " << fn.name().asChar() << endl;

OutputField(obj);

cout<< "\tRadialType " << fn.radialType() <<endl;

}

 

 

Uniform Field

 

 

 

 

 

 

 

 

 

#include<maya/MFnUniformField.h>

void OutputUniform(MObject& obj)
{
 

// attach the function set to the object
MFnUniformField(obj);

// write name
cout << "Uniform " << fn.name().asChar() << endl;

OutputField(obj);

const MVector& V = fn.direction();

cout << "\tDirection "
<< V.x << " "
<< V.y << " "
<< V.z << "\n";
}

 

 

Volume Axis Field

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


#include<maya/MFnVolumeAxisField.h>

void OutputVolumeAxis(MObject& obj)
{
 

// attach the function set to the object
MFnVolumeAxisField
fn(obj);

// write name
cout << "VolumeAxis " << fn.name().asChar() << endl;

OutputField(obj);

const MVector& V = fn.direction();

cout << "\tDirection "
<< V.x << " "
<< V.y << " "
<< V.z << "\n";

cout << "\tSpeed " << fn.speed() << endl;

cout << "\tSpeedAlongAxis "
<< V.speedAlongAxis() << endl;

cout << "\tSpeedAroundAxis "
<< V.speedAroundAxis() << endl;

cout << "\tSpeedAwayFromAxis "
<< V.speedAwayFromAxis() << endl;

cout << "\tSpeedAwayFromCenter "
<< V.speedAwayFromCenter() << endl;

cout << "\tTurbulence " << fn.turbulence() << endl;

cout << "\tTurbulenceSpeed "
<< V.turbulenceSpeed() << endl;

const MVector& V2 = fn.turbulenceFrequency();

cout << "\tTurbulenceFrequency "
<< V2.x << " "
<< V2.y << " "
<< V2.z << "\n";

const MVector& V3 = fn.turbulenceOffset();

cout << "\tTurbulenceOffset "
<< V3.x << " "
<< V3.y << " "
<< V3.z << "\n";

cout << "\tDetailTurbulence "
<< V.detailTurbulence() << endl;
}


 

 

Vortex Field

 

 

 

 

 

 

 

 

#include<maya/MFnVortexField.h>

void OutputVortex(MObject& obj)
{
 

// attach the function set to the object
MFnVortexField(obj);

// write name
cout << "Vortex " << fn.name().asChar() << endl;

OutputField(obj);

const MVector& V = fn.axis();

cout << "\tAxis "
<< V.x << " "
<< V.y << " "
<< V.z << "\n";
}




 

 

What Next?

Material Data

Transformation Data

Particle Systems

Animation Curves

index

Rob Bateman [2004]

[HOME] [MEL] [API]