Moderators: Sascha Willems, walaber
bool OffImport::Import (const char* const fileName, dPluginInterface* const interface)
{
dScene* const scene = interface->GetScene();
dAssert (scene);
NewtonWorld* const world = scene->GetNewtonWorld();
NewtonMesh* const mesh = NewtonMeshLoadOFF (world, fileName);
if (mesh) {
// some OFF files are vert dirty, make sure we do not have any degenerated faces
/*
NewtonMesh* xxx = mesh;
NewtonCollision* collision = NewtonCreateConvexHullFromMesh (world, xxx, 0, 0);
NewtonMesh* xxx1 = NewtonMeshCreateFromCollision(collision);
NewtonMeshTriangulate (xxx1);
int vertexCount = NewtonMeshGetVertexCount(xxx1);
int actualCount = 0;
for (void* vertex = NewtonMeshGetFirstVertex(xxx1); vertex; vertex = NewtonMeshGetNextVertex(xxx1, vertex))
{
++actualCount;
}
dAssert(actualCount == vertexCount );
*/
NewtonMeshFixTJoints (mesh);
dPluginScene* const asset = new dPluginScene(world);
dString name (GetNameFromPath(fileName));
name = name.SubString (0, name.Find ('.'));
dPluginScene::dTreeNode* const sceneNode = asset->CreateSceneNode (asset->GetRoot());
dSceneModelInfo* const sceneNodeInfo = (dSceneModelInfo*) asset->GetInfoFromNode(sceneNode);
sceneNodeInfo->SetName(name.GetStr());
dPluginScene::dTreeNode* const meshNode = asset->CreateMeshNode(sceneNode);
dMeshNodeInfo* const instance = (dMeshNodeInfo*) asset->GetInfoFromNode(meshNode);
instance->SetName ((name + "_mesh").GetStr());
instance->ReplaceMesh (mesh);
interface->MergeScene (asset);
asset->Release();
return true;
}
return false;
}
void NewtonMeshPolygonize (const NewtonMesh* const mesh);
void NewtonMeshTriangulate (const NewtonMesh* const mesh);
void NewtonMeshFixTJoints (const NewtonMesh* const mesh);
Users browsing this forum: No registered users and 2 guests