📄 propertiesevaluator.cpp
字号:
//**************************************************************************
//* PropertiesEvaluator.cpp - Virtools File Exporter
//*
//* Francisco Cabrita - Copyright (c) Virtools 2001
//*
//* This file contain all the function used to evaluate
//* the Virtools Command used in User Defined Properties
//*
//***************************************************************************
#include "Precomp.h"
#include "Max2Nmo.h"
#include "PropertiesEvaluator.h"
//****************************************************************************
//*
//* Constructor / Destructor
//*
//****************************************************************************
PropertiesEvaluator::PropertiesEvaluator( Export2Virtools *VirtoolsExporter, INode *node, Max2Nmo *max2nmo, CKObjectArray* generatedArray ){
if( !VirtoolsExporter ) return;
// The ObjectState is a 'thing' that flows down the pipeline containing
// all information about the object. By calling EvalWorldState() we tell
// max to eveluate the object at end of the pipeline.
ObjectState os = node->EvalWorldState(0);
// The obj member of ObjectState is the actual object we will export.
if( !os.obj ) return;
// We look at the super class ID to determine the type of the object.
switch(os.obj->SuperClassID()) {
case GEOMOBJECT_CLASS_ID:
case SHAPE_CLASS_ID:
case HELPER_CLASS_ID:
{
m_Ent = VirtoolsExporter->GetEntityByKey( node );
} break;
case CAMERA_CLASS_ID:
{
m_Ent = VirtoolsExporter->GetCameraByKey( node );
} break;
case LIGHT_CLASS_ID:
{
m_Ent = VirtoolsExporter->GetLightByKey( node );
} break;
}
if( !m_Ent ) return;
m_Node = node;
m_VirtoolsExporter = VirtoolsExporter;
TSTR buf;
m_Node->GetUserPropBuffer(buf);
m_CurrentLine = 1;
m_NmsPath = CKGetStartPath();
m_NmsPath << "plugins\\Virtools AddOns\\";
m_Character = m_VirtoolsExporter->GetCharacter();
m_GlobalAnimation = m_VirtoolsExporter->GetGlobalAnimation();
m_Max2Nmo = max2nmo;
m_GeneratedArray = generatedArray;
EvaluateBuffer( buf );
}
PropertiesEvaluator::~PropertiesEvaluator(){
}
//****************************************************************************
//*
//* Properties Evaluator
//*
//* Evaluates each lines of the buffer, and try to execute
//* the virtools commands.
//* return 0, if there are no errors.
//* return error line number, if some error occure.
//*
//****************************************************************************
int PropertiesEvaluator::EvaluateBuffer( char *buf ){
int bufLen = strlen( buf );
m_Ptr = buf;
m_Ptr_final = buf + bufLen;
XAP<char> command(new char[bufLen]);
XAP<char> param1(new char[bufLen]);
XAP<char> param2(new char[bufLen]);
XAP<char> param3(new char[bufLen]);
XAP<char> param4(new char[bufLen]);
while( GetStringBetween( "CK_", command, "(") == 0){
//______________________________________________________________
// AttachScriptOnThis( ScriptName )
if( !strcmp("AttachScriptOnThis", command) ){
if( !GetStringBetween( "\"", param1,"\"" ) ){
m_VirtoolsExporter->AttachScript( m_Ent, (m_NmsPath+(char*)param1+".nms").Str() );
}
//______________________________________________________________
// AttachScriptOnCharacter( ScriptName )
} else if( !strcmp("AttachScriptOnCharacter", command) ){
if( !GetStringBetween( "\"", param1,"\"" ) ){
m_VirtoolsExporter->AttachScript( m_Character, (m_NmsPath+(char*)param1+".nms").Str() );
}
//______________________________________________________________
// SetParamOnThis( ParamName, ParamValue )
} else if( !strcmp("SetParamOnThis", command) ){
if( !GetStringBetween( "\"", param1,"\"" ) ){
if( !GetStringBetweenExt( "\"", param2,"\"" ) ){ // can be CK_EXPORTEDANIMATION, // can be CK_EXPORTEDCHARACTER
m_VirtoolsExporter->SetParam( m_Ent, param1, param2 );
}
}
//______________________________________________________________
// SetParam( MaxObjName, ParamName, ParamValue )
} else if( !strcmp("SetParam", command) ){
if( !GetStringBetween( "\"", param1,"\"" ) ){
if( !GetStringBetween( "\"", param2,"\"" ) ){
if( !GetStringBetweenExt( "\"", param3,"\"" ) ){ // can be CK_EXPORTEDANIMATION, // can be CK_EXPORTEDCHARACTER
CKContext *ctx = m_Ent->GetCKContext();
CK3dEntity *target = (CK3dEntity *)ctx->GetObjectByNameAndParentClass( param1, CKCID_3DENTITY, NULL );
if( target ){
m_VirtoolsExporter->SetParam( target, param2, param3 );
}
}
}
}
//_______________________________________________________________
// SetAttributeOnThis( AttName, AttValue, AttType, AttCatego )
} else if( !strcmp("SetAttributeOnThis", command) ){
if( !GetStringBetween( "\"", param1,"\"" ) ){
if( !GetStringBetween( "\"", param2,"\"" ) ){
if( !GetStringBetween( "\"", param3,"\"" ) ){
if( !GetStringBetween( "\"", param4,"\"" ) ){
m_VirtoolsExporter->SetAttribute( m_Ent, param1, param2, param3, param4 );
}
}
}
}
//_________________________________________________________________
// SetAttributeOnCharacter( AttName, AttValue, AttType, AttCatego )
} else if( !strcmp("SetAttributeOnCharacter", command) ){
if( !GetStringBetween( "\"", param1,"\"" ) ){
if( !GetStringBetween( "\"", param2,"\"" ) ){
if( !GetStringBetween( "\"", param3,"\"" ) ){
if( !GetStringBetween( "\"", param4,"\"" ) ){
m_VirtoolsExporter->SetAttribute( m_Character, param1, param2, param3, param4 );
}
}
}
}
//_______________________________________________________________
// Load( fileName )
} else if( !strcmp("Load", command) ){
if( !GetStringBetween( "\"", param1,"\"" ) ){
CKBOOL loadOK = m_VirtoolsExporter->Load( m_Ent->GetCKContext(), param1, m_GeneratedArray );
if( !loadOK ){
m_VirtoolsExporter->Load( m_Ent->GetCKContext(), (m_NmsPath+(char *)param1+".nmo").Str(), m_GeneratedArray );
}
}
}
}
return 0;
}
//********************************************************
//*
//* GetStringBetween
//*
//* Retrieve the string between two other string
//* return 1, if reach the end of the file (reset m_Ptr to
//* previous position).
//* return 0, if find a string
//* put m_Ptr after the found word
//********************************************************
int PropertiesEvaluator::GetStringBetween( const char *debut, char *str, const char *fin ){
char *ptr_old = m_Ptr;
char *ptr_find0 = NULL;
char *ptr_find1 = NULL;
if( debut ){
while(1){
ptr_find0 = strstr( m_Ptr, debut);
if(m_Ptr > m_Ptr_final ){ m_Ptr = ptr_old; return 1;}
if( ptr_find0 ){
ptr_find0 += strlen( debut );
m_Ptr = ptr_find0;
break;
} else {
m_Ptr += strlen( m_Ptr ) + 1;
}
}
} else {
ptr_find0 = m_Ptr;
}
if( fin ){
while(1){
ptr_find1 = strstr( m_Ptr, fin);
if(m_Ptr > m_Ptr_final ){ m_Ptr = ptr_old; return 1;}
if( ptr_find1 ){
m_Ptr = ptr_find1 + strlen( fin );
break;
} else {
m_Ptr += strlen( m_Ptr ) + 1;
}
}
} else {
ptr_find1 = m_Ptr_final;
}
str[ptr_find1-ptr_find0] = 0;
memcpy(str, ptr_find0, (ptr_find1-ptr_find0) );
return 0;
}
//********************************************************
//*
//* GetStringBetweenExt
//*
//* Same as GetStringBetween but test if the string
//* is "CK_EXPORTEDANIMATION" or "CK_EXPORTEDCHARACTER"
//* and replace this string by the real name
//*
//********************************************************
int PropertiesEvaluator::GetStringBetweenExt( const char *debut, char *str, const char *fin ){
if( GetStringBetween( debut, str, fin ) ) return 1;
if( !strcmp( str, "CK_EXPORTEDANIMATION") ){
strcpy( str, m_Max2Nmo->GetAnimationName() );
} else if( !strcmp( str, "CK_EXPORTEDCHARACTER") ){
strcpy( str, m_Max2Nmo->GetCharacterName() );
} else if( !strcmp( str, "CK_THIS") ){
strcpy( str, m_Ent->GetName() );
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -