Newer
Older
Mesh& mesh = triObj->GetMesh();
switch (bvType)
{
case bv_type_box:
//case bv_type_sphere:
// shape = makeProxySphereShape(node, obj, mesh, tm);
// break;
break;
}
}
}
}
return shape;
}
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
bhkShapeRef Exporter::makeProxyBoxShape(INode *node, Object *obj, Mesh& mesh, Matrix3& tm)
{
enum { list_params, bv_mesh, }; // pblock2 ID
enum { PB_MATERIAL, PB_MESHLIST, PB_BOUND_TYPE, PB_CENTER, };
enum { bv_type_none, bv_type_box, bv_type_shapes, bv_type_packed, bv_type_convex, }; // pblock ID
bhkShapeRef retval;
if (IParamBlock2* pblock2 = obj->GetParamBlockByID(list_params))
{
Box3 box; box.Init();
CalcAxisAlignedBox(mesh, box, NULL);
int mtl = 0;
float length = 0, width = 0, height = 0;
pblock2->GetValue(PB_MATERIAL, 0, mtl, FOREVER, 0);
bhkBoxShapeRef shape = new bhkBoxShape();
Vector3 dim(box.Max().x-box.Min().x, box.Max().y-box.Min().y, box.Max().z-box.Min().z);
dim /= (Exporter::bhkScaleFactor * 2);
shape->SetMaterial(HavokMaterial(mtl));
shape->SetDimensions(dim);
Matrix3 ltm = /*GetLocalTM(node) * */TransMatrix(box.Center()) * tm;
if (ltm.IsIdentity())
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
transform->SetShape(shape);
transform->SetMaterial(HavokMaterial(mtl));
retval = StaticCast<bhkShape>(transform);
}
}
return retval;
}
bhkShapeRef Exporter::makeProxySphereShape(INode *node, Object *obj, Mesh& mesh, Matrix3& tm)
{
enum { list_params, bv_mesh, }; // pblock2 ID
enum { PB_MATERIAL, PB_MESHLIST, PB_BOUND_TYPE, PB_CENTER, };
enum { bv_type_none, bv_type_box, bv_type_shapes, bv_type_packed, bv_type_convex, }; // pblock ID
bhkShapeRef shape;
if (IParamBlock2* pblock2 = obj->GetParamBlockByID(list_params))
{
//Matrix3 tm = GetLocalTM(node) * TransMatrix(box.Center());
}
return shape;
}
bhkShapeRef Exporter::makeProxyConvexShape(INode *node, Object *obj, Mesh& mesh, Matrix3& tm)
{
enum { list_params, bv_mesh, }; // pblock2 ID
enum { PB_MATERIAL, PB_MESHLIST, PB_BOUND_TYPE, PB_CENTER, };
enum { bv_type_none, bv_type_box, bv_type_shapes, bv_type_packed, bv_type_convex, }; // pblock ID
bhkShapeRef shape;
if (IParamBlock2* pblock2 = obj->GetParamBlockByID(list_params))
{
if (bhkConvexVerticesShapeRef convShape = makeConvexShape(mesh, tm))
{
int mtl = pblock2->GetInt(PB_MATERIAL, 0, 0);
convShape->SetMaterial(HavokMaterial(mtl));
shape = StaticCast<bhkShape>(convShape);
}
}
return shape;
}
bhkShapeRef Exporter::makeProxyTriStripShape(INode *node, Object *obj, Mesh& mesh, Matrix3& tm)
{
enum { list_params, bv_mesh, }; // pblock2 ID
enum { PB_MATERIAL, PB_MESHLIST, PB_BOUND_TYPE, PB_CENTER, };
enum { bv_type_none, bv_type_box, bv_type_shapes, bv_type_packed, bv_type_convex, }; // pblock ID
bhkShapeRef shape;
if (IParamBlock2* pblock2 = obj->GetParamBlockByID(list_params))
{
int mtl = pblock2->GetInt(PB_MATERIAL, 0, 0);
// Transform location
Mesh localmesh(mesh);
MNMesh tmpMesh(localmesh);
tmpMesh.Transform(tm);
tmpMesh.buildNormals();
tmpMesh.OutToTri(localmesh);
localmesh.buildNormals();
trishape->SetMaterial(HavokMaterial(mtl));
shape = StaticCast<bhkShape>(trishape);
}
return shape;
}
bhkShapeRef Exporter::makeProxyPackedTriStripShape(INode *node, Object *obj, Mesh& mesh, Matrix3& tm)
{
enum { list_params, bv_mesh, }; // pblock2 ID
enum { PB_MATERIAL, PB_MESHLIST, PB_BOUND_TYPE, PB_CENTER, };
enum { bv_type_none, bv_type_box, bv_type_shapes, bv_type_packed, bv_type_convex, }; // pblock ID
bhkShapeRef shape;
if (IParamBlock2* pblock2 = obj->GetParamBlockByID(list_params))
{
int mtl = pblock2->GetInt(PB_MATERIAL, 0, 0);
// Transform location
Mesh localmesh(mesh);
MNMesh tmpMesh(localmesh);
tmpMesh.Transform(tm);
tmpMesh.buildNormals();
tmpMesh.OutToTri(localmesh);
localmesh.buildNormals();
bhkPackedNiTriStripsShapeRef trishape = makePackedTriStripsShape(localmesh, ident);
if ( TheHavokCode.Initialize() )
shape = StaticCast<bhkShape>( makeTreeShape(trishape) );
else
shape = StaticCast<bhkShape>(trishape);
bhkShapeRef Exporter::makeModifierShape(INode *node, Object* obj, Modifier* mod, Matrix3& tm)
{
enum { havok_params };
enum { PB_BOUND_TYPE, PB_MATERIAL, };
enum { bv_type_none, bv_type_box, bv_type_sphere, bv_type_capsule, bv_type_shapes, bv_type_convex, bv_type_packed, }; // pblock ID
bhkShapeRef shape;
const Mesh* mesh = NULL;
int material = NP_DEFAULT_HVK_MATERIAL;
int type = bv_type_none;
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
if (bhkHelperInterface* bhkHelp = (bhkHelperInterface*)mod->GetInterface(BHKHELPERINTERFACE_DESC))
{
mesh = bhkHelp->GetMesh();
}
else
{
if (TriObject *tri = (TriObject *)obj->ConvertToType(0, Class_ID(TRIOBJ_CLASS_ID, 0)))
{
mesh = &tri->GetMesh();
}
}
if (IParamBlock2* pblock2 = mod->GetParamBlockByID(havok_params))
{
pblock2->GetValue(PB_BOUND_TYPE, 0, type, FOREVER, 0);
pblock2->GetValue(PB_MATERIAL, 0, material, FOREVER, 0);
}
switch (type)
{
default:
case bv_type_none:
break;
case bv_type_box:
shape = makeModConvexShape(node, mod, const_cast<Mesh&>(*mesh), tm);
break;
case bv_type_packed:
shape = makeModPackedTriStripShape(node, mod, const_cast<Mesh&>(*mesh), tm);
break;
}
return shape;
}
bhkShapeRef Exporter::makeModBoxShape(INode *node, Modifier* mod, Mesh& mesh, Matrix3& tm)
{
enum { havok_params };
enum { PB_BOUND_TYPE, PB_MATERIAL, };
enum { bv_type_none, bv_type_box, bv_type_sphere, bv_type_capsule, bv_type_shapes, bv_type_convex, bv_type_packed, }; // pblock ID
int material = NP_DEFAULT_HVK_MATERIAL;
if (IParamBlock2* pblock2 = mod->GetParamBlockByID(havok_params))
{
pblock2->GetValue(PB_MATERIAL, 0, material, FOREVER, 0);
}
bhkShapeRef retval;
if (bhkBoxShapeRef shape = new bhkBoxShape())
{
Box3 box; box.Init();
CalcAxisAlignedBox(mesh, box, NULL);
Vector3 dim(box.Max().x-box.Min().x, box.Max().y-box.Min().y, box.Max().z-box.Min().z);
dim /= (Exporter::bhkScaleFactor * 2);
shape->SetDimensions(dim);
shape->SetMaterial(HavokMaterial(material));
Matrix3 ltm = TransMatrix(box.Center()) * node->GetNodeTM(0) * tm;
if (ltm.IsIdentity())
transform->SetShape(shape);
transform->SetMaterial(HavokMaterial(material));
retval = StaticCast<bhkShape>(transform);
}
}
return retval;
}
bhkShapeRef Exporter::makeModSphereShape(INode *node, Modifier* mod, Mesh& mesh, Matrix3& tm)
{
enum { havok_params };
enum { PB_BOUND_TYPE, PB_MATERIAL, };
enum { bv_type_none, bv_type_box, bv_type_sphere, bv_type_capsule, bv_type_shapes, bv_type_convex, bv_type_packed, }; // pblock ID
int material = NP_DEFAULT_HVK_MATERIAL;
if (IParamBlock2* pblock2 = mod->GetParamBlockByID(havok_params))
{
pblock2->GetValue(PB_MATERIAL, 0, material, FOREVER, 0);
}
bhkShapeRef retval;
Point3 center = Point3::Origin;
float radius = 0.0f;
CalcCenteredSphere(mesh, center, radius);
if (bhkSphereShapeRef shape = new bhkSphereShape())
{
shape->SetRadius(radius / Exporter::bhkScaleFactor);
shape->SetMaterial(HavokMaterial(material));
Matrix3 ltm = TransMatrix(center) * node->GetObjTMAfterWSM(0) * tm;
if (ltm.IsIdentity())
transform->SetShape(shape);
transform->SetMaterial(HavokMaterial(material));
retval = StaticCast<bhkShape>(transform);
}
return retval;
}
bhkShapeRef Exporter::makeModCapsuleShape(INode *node, Modifier* mod, Mesh& mesh, Matrix3& tm)
{
enum { havok_params };
enum { PB_BOUND_TYPE, PB_MATERIAL, };
enum { bv_type_none, bv_type_box, bv_type_sphere, bv_type_capsule, bv_type_shapes, bv_type_convex, bv_type_packed, }; // pblock ID
if (IParamBlock2* pblock2 = mod->GetParamBlockByID(havok_params))
{
pblock2->GetValue(PB_MATERIAL, 0, material, FOREVER, 0);
}
bhkShapeRef retval;
Point3 center = Point3::Origin;
float radius = 0.0f;
CalcCenteredSphere(mesh, center, radius);
if (bhkCapsuleShapeRef shape = new bhkCapsuleShape())
{
shape->SetRadius(radius / Exporter::bhkScaleFactor);
shape->SetRadius1(radius / Exporter::bhkScaleFactor);
shape->SetRadius2(radius / Exporter::bhkScaleFactor);
shape->SetFirstPoint(TOVECTOR3(center/Exporter::bhkScaleFactor));
shape->SetSecondPoint(TOVECTOR3(center/Exporter::bhkScaleFactor));
shape->SetMaterial(HavokMaterial(material));
Matrix3 ltm = TransMatrix(center) * node->GetObjTMAfterWSM(0) * tm;
if (ltm.IsIdentity())
transform->SetShape(shape);
transform->SetMaterial(HavokMaterial(material));
retval = StaticCast<bhkShape>(transform);
}
}
return retval;
}
bhkShapeRef Exporter::makeModConvexShape(INode *node, Modifier* mod, Mesh& mesh, Matrix3& tm)
{
enum { havok_params };
enum { PB_BOUND_TYPE, PB_MATERIAL, };
enum { bv_type_none, bv_type_box, bv_type_sphere, bv_type_capsule, bv_type_shapes, bv_type_convex, bv_type_packed, }; // pblock ID
{
if (IParamBlock2* pblock2 = mod->GetParamBlockByID(havok_params))
{
pblock2->GetValue(PB_MATERIAL, 0, material, FOREVER, 0);
}
convShape->SetMaterial(HavokMaterial(material));
shape = StaticCast<bhkShape>(convShape);
}
return shape;
}
bhkShapeRef Exporter::makeModTriStripShape(INode *node, Modifier* mod, Mesh& mesh, Matrix3& tm)
{
enum { havok_params };
enum { PB_BOUND_TYPE, PB_MATERIAL, };
enum { bv_type_none, bv_type_box, bv_type_sphere, bv_type_capsule, bv_type_shapes, bv_type_convex, bv_type_packed, }; // pblock ID
{
trishape->SetMaterial(HavokMaterial(material));
if (IParamBlock2* pblock2 = mod->GetParamBlockByID(havok_params))
{
pblock2->GetValue(PB_MATERIAL, 0, material, FOREVER, 0);
}
shape = StaticCast<bhkShape>(trishape);
}
bhkShapeRef Exporter::makeModPackedTriStripShape(INode *node, Modifier* mod, Mesh& mesh, Matrix3& tm)
{
enum { havok_params };
enum { PB_BOUND_TYPE, PB_MATERIAL, };
enum { bv_type_none, bv_type_box, bv_type_sphere, bv_type_capsule, bv_type_shapes, bv_type_convex, bv_type_packed, }; // pblock ID
int material = NP_DEFAULT_HVK_MATERIAL;
Matrix3 ltm = node->GetObjTMAfterWSM(0) * tm;
bhkShapeRef shape;
if (bhkPackedNiTriStripsShapeRef trishape = makePackedTriStripsShape(mesh, ltm))
{
//trishape->SetMaterial(HavokMaterial(material));
if (IParamBlock2* pblock2 = mod->GetParamBlockByID(havok_params))
{
pblock2->GetValue(PB_MATERIAL, 0, material, FOREVER, 0);
}
if ( TheHavokCode.Initialize() )
shape = StaticCast<bhkShape>( makeTreeShape(trishape) );
else
shape = StaticCast<bhkShape>(trishape);