本文整理汇总了C++中NiNodeRef::SetCollisionObject方法的典型用法代码示例。如果您正苦于以下问题:C++ NiNodeRef::SetCollisionObject方法的具体用法?C++ NiNodeRef::SetCollisionObject怎么用?C++ NiNodeRef::SetCollisionObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NiNodeRef
的用法示例。
在下文中一共展示了NiNodeRef::SetCollisionObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanTreeCollision
/*---------------------------------------------------------------------------*/
void NifCollisionUtility::cleanTreeCollision(NiNodeRef pNode)
{
vector<NiAVObjectRef> srcChildList(pNode->GetChildren()); // children of node
// remove collision object (new style [>= Oblivion])
pNode->SetCollisionObject(NULL);
// iterate over source nodes and remove possible old-style [Morrowind] collision node
for (auto ppIter=srcChildList.begin(), pEnd=srcChildList.end(); ppIter != pEnd; ppIter++)
{
// RootCollisionNode
if (DynamicCast<RootCollisionNode>(*ppIter) != NULL)
{
pNode->RemoveChild(*ppIter);
}
// NiNode
else if (DynamicCast<NiNode>(*ppIter) != NULL)
{
cleanTreeCollision(DynamicCast<NiNode>(*ppIter));
}
// other children
else
{
(*ppIter)->SetCollisionObject(NULL);
}
} // for (vector<NiAVObjectRef>::iterator ppIter = srcChildList.begin(); ....
}
示例2: convertShape
/*---------------------------------------------------------------------------*/
unsigned int NifConvertUtility::convertShape(string fileNameSrc, string fileNameDst, string fileNameTmpl)
{
NiNodeRef pRootInput (NULL);
NiNodeRef pRootOutput (NULL);
NiNodeRef pRootTemplate (NULL);
NiTriShapeRef pNiTriShapeTmpl(NULL);
vector<NiAVObjectRef> srcChildList;
bool fakedRoot (false);
// test on existing file names
if (fileNameSrc.empty()) return NCU_ERROR_MISSING_FILE_NAME;
if (fileNameDst.empty()) return NCU_ERROR_MISSING_FILE_NAME;
if (fileNameTmpl.empty()) return NCU_ERROR_MISSING_FILE_NAME;
// initialize user messages
_userMessages.clear();
logMessage(NCU_MSG_TYPE_INFO, "Source: " + (fileNameSrc.empty() ? "- none -" : fileNameSrc));
logMessage(NCU_MSG_TYPE_INFO, "Template: " + (fileNameTmpl.empty() ? "- none -" : fileNameTmpl));
logMessage(NCU_MSG_TYPE_INFO, "Destination: " + (fileNameDst.empty() ? "- none -" : fileNameDst));
logMessage(NCU_MSG_TYPE_INFO, "Texture: " + (_pathTexture.empty() ? "- none -" : _pathTexture));
// initialize used texture list
_usedTextures.clear();
_newTextures.clear();
// read input NIF
if ((pRootInput = getRootNodeFromNifFile(fileNameSrc, "source", fakedRoot)) == NULL)
{
logMessage(NCU_MSG_TYPE_ERROR, "Can't open '" + fileNameSrc + "' as input");
return NCU_ERROR_CANT_OPEN_INPUT;
}
// get template nif
pRootTemplate = DynamicCast<BSFadeNode>(ReadNifTree((const char*) fileNameTmpl.c_str()));
if (pRootTemplate == NULL)
{
logMessage(NCU_MSG_TYPE_ERROR, "Can't open '" + fileNameTmpl + "' as template");
return NCU_ERROR_CANT_OPEN_TEMPLATE;
}
// get shapes from template
// - shape root
pNiTriShapeTmpl = DynamicCast<NiTriShape>(pRootTemplate->GetChildren().at(0));
if (pNiTriShapeTmpl == NULL)
{
logMessage(NCU_MSG_TYPE_INFO, "Template has no NiTriShape.");
}
// template root is used as root of output
pRootOutput = pRootTemplate;
// get rid of unwanted subnodes
pRootOutput->ClearChildren(); // remove all children
pRootOutput->SetCollisionObject(NULL); // unlink collision object
// hold extra data and property nodes
// copy translation from input node
pRootOutput->SetLocalTransform(pRootInput->GetLocalTransform());
// copy name of root node
pRootOutput->SetName(pRootInput->GetName());
// get list of children from input node
srcChildList = pRootInput->GetChildren();
// unlink children 'cause moved to output
pRootInput->ClearChildren();
// iterate over source nodes and convert using template
for (vector<NiAVObjectRef>::iterator ppIter = srcChildList.begin(); ppIter != srcChildList.end(); ppIter++)
{
// NiTriShape
if (DynamicCast<NiTriShape>(*ppIter) != NULL)
{
pRootOutput->AddChild(&(*convertNiTriShape(DynamicCast<NiTriShape>(*ppIter), pNiTriShapeTmpl)));
}
// RootCollisionNode
else if (DynamicCast<RootCollisionNode>(*ppIter) != NULL)
{
// ignore node
}
// NiNode (and derived classes?)
else if (DynamicCast<NiNode>(*ppIter) != NULL)
{
pRootOutput->AddChild(&(*convertNiNode(DynamicCast<NiNode>(*ppIter), pNiTriShapeTmpl, pRootOutput)));
}
}
// write missing textures to log - as block
for (set<string>::iterator pIter(_newTextures.begin()); pIter != _newTextures.end(); ++pIter)
{
logMessage(NCU_MSG_TYPE_TEXTURE_MISS, *pIter);
}
// write modified nif file
WriteNifTree((const char*) fileNameDst.c_str(), pRootOutput, NifInfo(VER_20_2_0_7, 12, 83));
return NCU_OK;
}
示例3: convertShape
/*---------------------------------------------------------------------------*/
unsigned int NifConvertUtility::convertShape(string fileNameSrc, string fileNameDst, string fileNameTmpl)
{
cout << "Here3" << endl;
NiNodeRef pRootInput (NULL);
NiNodeRef pRootOutput (NULL);
NiNodeRef pRootTemplate (NULL);
NiTriShapeRef pNiTriShapeTmpl(NULL);
NiCollisionObjectRef pRootCollObject(NULL);
NifInfo nifInfo;
vector<NiAVObjectRef> srcChildList;
bool fakedRoot (false);
cout << "Here4" << endl;
// test on existing file names
if (fileNameSrc.empty()) return NCU_ERROR_MISSING_FILE_NAME;
if (fileNameDst.empty()) return NCU_ERROR_MISSING_FILE_NAME;
if (fileNameTmpl.empty()) return NCU_ERROR_MISSING_FILE_NAME;
cout << "Here5" << endl;
// initialize user messages
_userMessages.clear();
logMessage(NCU_MSG_TYPE_INFO, "Source: " + (fileNameSrc.empty() ? "- none -" : fileNameSrc));
logMessage(NCU_MSG_TYPE_INFO, "Template: " + (fileNameTmpl.empty() ? "- none -" : fileNameTmpl));
logMessage(NCU_MSG_TYPE_INFO, "Destination: " + (fileNameDst.empty() ? "- none -" : fileNameDst));
logMessage(NCU_MSG_TYPE_INFO, "Texture: " + (_pathTexture.empty() ? "- none -" : _pathTexture));
cout << "Here6" << endl;
// initialize used texture list
_usedTextures.clear();
_newTextures.clear();
cout << "Here7" << endl;
// read input NIF
if ((pRootInput = getRootNodeFromNifFile(fileNameSrc, "source", fakedRoot, &nifInfo)) == NULL)
{
logMessage(NCU_MSG_TYPE_ERROR, "Can't open '" + fileNameSrc + "' as input");
return NCU_ERROR_CANT_OPEN_INPUT;
}
cout << "Here8" << endl;
// get template nif
pRootTemplate = DynamicCast<BSFadeNode>(ReadNifTree((const char*) fileNameTmpl.c_str()));
if (pRootTemplate == NULL)
{
logMessage(NCU_MSG_TYPE_ERROR, "Can't open '" + fileNameTmpl + "' as template");
return NCU_ERROR_CANT_OPEN_TEMPLATE;
}
cout << "Here9" << endl;
// get shapes from template
// - shape root
pNiTriShapeTmpl = DynamicCast<NiTriShape>(pRootTemplate->GetChildren().at(0));
if (pNiTriShapeTmpl == NULL)
{
logMessage(NCU_MSG_TYPE_INFO, "Template has no NiTriShape.");
}
cout << "Here10" << endl;
// get data from input node
srcChildList = pRootInput->GetChildren();
pRootCollObject = pRootInput->GetCollisionObject();
cout << "Here11" << endl;
// template root is used as root of output
pRootOutput = pRootTemplate;
// move date from input to output
pRootInput ->SetCollisionObject(NULL);
pRootOutput->SetCollisionObject(pRootCollObject);
pRootOutput->SetLocalTransform(pRootInput->GetLocalTransform());
pRootOutput->SetName(pRootInput->GetName());
cout << "Here12" << endl;
// get rid of unwanted subnodes
pRootOutput->ClearChildren();
pRootInput->ClearChildren();
cout << "Here13" << endl;
// move children to output
for (auto pIter=srcChildList.begin(), pEnd=srcChildList.end(); pIter != pEnd; ++pIter)
{
pRootOutput->AddChild(*pIter);
}
cout << "Here14" << endl;
// iterate over source nodes and convert using template
root_bsafade = pRootOutput;
pRootOutput = convertNiNode(pRootOutput, pNiTriShapeTmpl, pRootOutput);
cout << "Here15" << endl;
// write missing textures to log - as block
for (auto pIter=_newTextures.begin(), pEnd=_newTextures.end(); pIter != pEnd; ++pIter)
{
logMessage(NCU_MSG_TYPE_TEXTURE_MISS, *pIter);
}
cout << "Here16" << endl;
// set version information
stringstream sStream;
cout << "Here17" << endl;
sStream << nifInfo.version << ';' << nifInfo.userVersion;
nifInfo.version = VER_20_2_0_7;
nifInfo.userVersion = 12;
nifInfo.userVersion2 = 83;
nifInfo.creator = "NifConvert";
nifInfo.exportInfo1 = MASTER_PRODUCT_VERSION_STR;
nifInfo.exportInfo2 = sStream.str();
cout << "Here18" << endl;
// write modified nif file
WriteNifTree((const char*) fileNameDst.c_str(), pRootOutput, nifInfo);
cout << "Here19" << endl;
return NCU_OK;
//.........这里部分代码省略.........
示例4: convertNiNode
//.........这里部分代码省略.........
NiExtraDataRef ed = root_bsafade->GetExtraData().front();
NiIntegerExtraDataRef iref = DynamicCast<NiIntegerExtraData>(ed);
iref->SetData(147);
cout << "Adding CandleFlame Addon" << endl;
BSValueNodeRef candle_flame = new BSValueNode();
candle_flame->SetName("AddOnNode");
candle_flame->value = 49;
pDstNode->AddChild(DynamicCast<NiAVObject>(candle_flame));
}
vector<NiAVObjectRef> srcShapeList(pDstNode->GetChildren());
//if (!pDstNode->GetType().IsSameType(NiNode::TYPE) && !pDstNode->GetType().IsSameType(BSFadeNode::TYPE) && !pDstNode->GetType().IsSameType(NiTriShape::TYPE) && !pDstNode->GetType().IsSameType(NiTriStrips::TYPE))
{
}
// find NiAlphaProperty and use as template in sub-nodes
if (DynamicCast<NiAlphaProperty>(pDstNode->GetPropertyByType(NiAlphaProperty::TYPE)) != NULL)
{
pTmplAlphaProp = DynamicCast<NiAlphaProperty>(pDstNode->GetPropertyByType(NiAlphaProperty::TYPE));
}
// unlink protperties -> not used in new format
pDstNode->ClearProperties();
// shift extra data to new version
pDstNode->ShiftExtraData(VER_20_2_0_7);
// unlink children
pDstNode->ClearChildren();
pDstNode->ClearEffects();
pDstNode->ClearControllers();
if (!pDstNode->GetType().IsSameType(BSFadeNode::TYPE))
{
pDstNode->ClearExtraData();
}
// iterate over source nodes and convert using template
for (auto ppIter=srcShapeList.begin(), pEnd=srcShapeList.end(); ppIter != pEnd; ppIter++)
{
//DynamicCast<NiTriShape>(*ppIter) == NULL && DynamicCast<NiTriStrips>(*ppIter) == NULL ** DynamicCast<NiTriStrips>(*ppIter) != NULL
// NiTriShape
if (DynamicCast<NiTriShape>(*ppIter) != NULL)
{
pDstNode->AddChild(&(*convertNiTriShape(DynamicCast<NiTriShape>(*ppIter), pTmplNode, pTmplAlphaProp)));
}
// NiTriStrips
else if (DynamicCast<NiTriStrips>(*ppIter) != NULL)
{
pDstNode->AddChild(&(*convertNiTriStrips(DynamicCast<NiTriStrips>(*ppIter), pTmplNode, pTmplAlphaProp)));
}
// RootCollisionNode
else if ((DynamicCast<RootCollisionNode>(*ppIter) != NULL) && _cleanTreeCollision)
{
// ignore node
}
// NiNode (and derived classes?)
else if (DynamicCast<NiNode>(*ppIter) != NULL)
{
NiNode* node_hashmi = DynamicCast<NiNode>(*ppIter);
if (node_hashmi->GetType().IsSameType(NiNode::TYPE) || node_hashmi->GetType().IsSameType(BSFadeNode::TYPE) || node_hashmi->GetType().IsSameType(BSValueNode::TYPE))
{
pDstNode->AddChild(&(*convertNiNode(DynamicCast<NiNode>(*ppIter), pTmplNode, pRootNode, pTmplAlphaProp)));
}
}
}
// remove collision object (newer version)
if (_cleanTreeCollision)
{
pDstNode->SetCollisionObject(NULL);
}
else if (DynamicCast<bhkCollisionObject>(pDstNode->GetCollisionObject()) != NULL)
{
bhkRigidBodyRef pBody(DynamicCast<bhkRigidBody>((DynamicCast<bhkCollisionObject>(pDstNode->GetCollisionObject()))->GetBody()));
if (pBody != NULL)
{
parseCollisionTree(pBody->GetShape());
}
}
return pDstNode;
}
示例5: addCollision
//.........这里部分代码省略.........
// get shapes from template
// - collision root
pCollNodeTmpl = DynamicCast<bhkCollisionObject>(pRootTemplate->GetCollisionObject());
if (pCollNodeTmpl == NULL)
{
logMessage(NCU_MSG_TYPE_ERROR, "Template has no bhkCollisionObject.");
return NCU_ERROR_CANT_OPEN_TEMPLATE;
}
// get root node from destination
if ((pRootInput = getRootNodeFromNifFile(fileNameNifDst, "target", fakedRoot, false)) == NULL)
{
logMessage(NCU_MSG_TYPE_ERROR, "Can't open '" + fileNameNifDst + "' as template");
return NCU_ERROR_CANT_OPEN_INPUT;
}
// test on collision source having collision data
// CollisionNodeHandling::NCU_CN_FALLBACK should be osolete after this point
if (!collSourceHasCollNodes(fileNameCollSrc))
{
cout << "Source File Has No Collision. No collision will be added to converted file." << endl;
return NCU_OK;
// fallback to create single collision from model data
_mergeCollision = true;
_cnHandling = CollisionNodeHandling(NCU_CN_SHAPES);
}
/* temp. removed due to non-implemented functionality
else if (_cnHandling == NCU_CN_FALLBACK)
{
// collision node existing
_cnHandling = CollisionNodeHandling(NCU_CN_COLLISION);
}
*/
// output != collision source => force merge
_mergeCollision = (_mergeCollision || (fileNameCollSrc != fileNameNifDst));
// replace each collision node
if (!_mergeCollision)
{
vector<hkGeometry> geometryMapCollLocal;
logMessage(NCU_MSG_TYPE_INFO, "!!! Using replace-node-method due to target is source !!!");
// replace each collision node with new style one
parseTreeCollision(pRootInput, fileNameCollTmpl, geometryMapCollLocal);
}
// create combined collision node
else
{
// get geometry data
switch (fileNameCollSrc[fileNameCollSrc.size() - 3])
{
// from OBJ file
case 'O':
case 'o':
{
logMessage(NCU_MSG_TYPE_INFO, "Getting geometry from OBJ.");
getGeometryFromObjFile(fileNameCollSrc, geometryMap);
break;
}
// from NIF file
case 'N':
case 'n':
{
logMessage(NCU_MSG_TYPE_INFO, "Getting geometry from NIF.");
getGeometryFromNifFile(fileNameCollSrc, geometryMap);
break;
}
// from 3DS file
case '3':
{
// would be nice ;-)
logMessage(NCU_MSG_TYPE_INFO, "Getting geometry from 3DS.");
break;
}
} // switch (fileNameCollSrc[fileNameCollSrc.size() - 3])
// early break on missing geometry data
if (geometryMap.size() <= 0)
{
logMessage(NCU_MSG_TYPE_ERROR, "Can't get geometry from input file.");
return NCU_ERROR_CANT_GET_GEOMETRY;
}
// create collision node
bhkCollisionObjectRef pCollNodeDest(createCollNode(geometryMap, pCollNodeTmpl, pRootInput));
// remove all collision sub nodes
cleanTreeCollision(pRootInput);
// add collision node to target
pRootInput->SetCollisionObject(pCollNodeDest);
}
// write modified nif file
WriteNifTree((const char*) fileNameNifDst.c_str(), pRootInput, NifInfo(VER_20_2_0_7, 12, 83));
return NCU_OK;
}
示例6: parseTreeCollision
/*---------------------------------------------------------------------------*/
bool NifCollisionUtility::parseTreeCollision(NiNodeRef pNode, string fileNameCollTmpl, vector<hkGeometry>& geometryMapColl)
{
vector<NiAVObjectRef> srcChildList (pNode->GetChildren()); // get list of children from input node
bool haveCollision(false);
// check for own collision object
if (DynamicCast<bhkCollisionObject>(pNode->GetCollisionObject()) != NULL)
{
bhkCollisionObjectRef pCollObj(DynamicCast<bhkCollisionObject>(pNode->GetCollisionObject()));
bhkRigidBodyRef pRBody (DynamicCast<bhkRigidBody> (pCollObj->GetBody()));
// check on valid body
if (pRBody != NULL)
{
array<7, unsigned short> unknown7(pRBody->GetUnknown7Shorts());
// force SKYRIM values
unknown7[3] = 0;
unknown7[4] = 0;
unknown7[5] = 1;
unknown7[6] = 65535;
pRBody->SetUnknown7Shorts(unknown7);
pRBody->SetTranslation(pRBody->GetTranslation() * 0.1f);
pRBody->SetShape(parseCollisionShape(fileNameCollTmpl, pRBody->GetShape(), pRBody));
} // if (pRBody != NULL)
haveCollision |= true;
} // if (DynamicCast<bhkCollisionObject>(pNode->GetCollisionObject()) != NULL)
// iterate over source nodes and get geometry
for (vector<NiAVObjectRef>::iterator ppIter = srcChildList.begin(); ppIter != srcChildList.end(); ppIter++)
{
// RootCollisionNode
if (DynamicCast<RootCollisionNode>(*ppIter) != NULL)
{
NiNodeRef pRootTemplate(DynamicCast<BSFadeNode>(ReadNifTree((const char*) fileNameCollTmpl.c_str())));
vector<hkGeometry> geometryMapCollLocal;
vector<Matrix44> transformAryLocal;
// get template
if (pRootTemplate != NULL)
{
bhkCollisionObjectRef pCollNodeTmpl(DynamicCast<bhkCollisionObject>(pRootTemplate->GetCollisionObject()));
if (pCollNodeTmpl != NULL)
{
// get collision data from sub-nodes
getGeometryFromNode(&(*DynamicCast<RootCollisionNode>(*ppIter)), geometryMapCollLocal, geometryMapCollLocal, transformAryLocal);
// replace collision object
pNode->SetCollisionObject(createCollNode(geometryMapCollLocal, pCollNodeTmpl, pNode));
pNode->RemoveChild(*ppIter);
haveCollision |= true;
} // if (pCollNodeTmpl == NULL)
} // if (pRootTemplate != NULL)
}
// NiNode (and derived classes?)
else if (DynamicCast<NiNode>(*ppIter) != NULL)
{
haveCollision |= parseTreeCollision(DynamicCast<NiNode>(*ppIter), fileNameCollTmpl, geometryMapColl);
}
} // for (vector<NiAVObjectRef>::iterator ppIter = srcChildList.begin(); ppIter != srcChildList.end(); ppIter++)
return haveCollision;
}
示例7: makeHavokRigidBody
//.........这里部分代码省略.........
lh.perp2AxleInA1 = TOVECTOR4(parentRotation.GetRow(0));
lh.perp2AxleInA2 = TOVECTOR4(parentRotation.GetRow(1));
lh.axleA = TOVECTOR4(parentRotation.GetRow(2));
lh.perp2AxleInB1 = TOVECTOR4(childRotation.GetRow(0));
lh.perp2AxleInB2 = TOVECTOR4(childRotation.GetRow(1));
lh.axleB = TOVECTOR4(childRotation.GetRow(2));
}
if (IParamBlock2* constraintParameters = constraintMod->GetParamBlockByID(PB_HINGE_MOD_PBLOCK)) {
float minAngle;
float maxAngle;
float maxFriction;
constraintParameters->GetValue(PA_HINGE_MOD_LIMIT_MIN, 0, minAngle, FOREVER);
constraintParameters->GetValue(PA_HINGE_MOD_LIMIT_MAX, 0, maxAngle, FOREVER);
constraintParameters->GetValue(PA_HINGE_MOD_MAX_FRICTION_TORQUE, 0, maxFriction, FOREVER);
// constraintParameters->SetValue(PA_HINGE_MOD_MOTOR_TYPE, 0, lh.motor., 0);
lh.minAngle = TORAD(minAngle);
lh.maxAngle = TORAD(maxAngle);
lh.maxAngle = maxFriction;
}
limitedHingeConstraint->SetLimitedHinge(lh);
body->AddConstraint(limitedHingeConstraint);
}
}
//InitializeRigidBody(body, node);
body->SetShape(shape);
blendObj->SetBody(StaticCast<NiObject>(body));
parent->SetCollisionObject(StaticCast<NiCollisionObject>(blendObj));
}
////rigid body parameters
// // get data from node
//int lyr = NP_DEFAULT_HVK_LAYER;
//int mtl = NP_DEFAULT_HVK_MATERIAL;
//int msys = NP_DEFAULT_HVK_MOTION_SYSTEM;
//int qtype = NP_DEFAULT_HVK_QUALITY_TYPE;
//float mass = NP_DEFAULT_HVK_MASS;
//float lindamp = NP_DEFAULT_HVK_LINEAR_DAMPING;
//float angdamp = NP_DEFAULT_HVK_ANGULAR_DAMPING;
//float frict = NP_DEFAULT_HVK_FRICTION;
//float maxlinvel = NP_DEFAULT_HVK_MAX_LINEAR_VELOCITY;
//float maxangvel = NP_DEFAULT_HVK_MAX_ANGULAR_VELOCITY;
//float resti = NP_DEFAULT_HVK_RESTITUTION;
//float pendepth = NP_DEFAULT_HVK_PENETRATION_DEPTH;
//BOOL transenable = TRUE;
//if (IParamBlock2* rbParameters = rbMod->GetParamBlockByID(PB_SHAPE_MOD_PBLOCK))
//{
// //These are fundamental parameters
// rbParameters->GetValue(PA_RB_MOD_MASS, 0, mass, FOREVER);
// rbParameters->GetValue(PA_RB_MOD_RESTITUTION, 0, resti, FOREVER);
// rbParameters->GetValue(PA_RB_MOD_FRICTION, 0, frict, FOREVER);
// rbParameters->GetValue(PA_RB_MOD_LINEAR_DAMPING, 0, lindamp, FOREVER);
// rbParameters->GetValue(PA_RB_MOD_CHANGE_ANGULAR_DAMPING, 0, angdamp, FOREVER);
// rbParameters->GetValue(PA_RB_MOD_MAX_LINEAR_VELOCITY, 0, maxlinvel, FOREVER);
// rbParameters->GetValue(PA_RB_MOD_MAX_ANGULAR_VELOCITY, 0, maxangvel, FOREVER);
// rbParameters->GetValue(PA_RB_MOD_ALLOWED_PENETRATION_DEPTH, 0, pendepth, FOREVER);