Esempio n. 1
0
void ModelOutput::WriteTextModel(const CModel& model, std::ostream &stream)
{
    ModelHeaderV3 header;
    header.version = 3;
    header.totalCrashSpheres = model.GetCrashSphereCount();
    header.hasShadowSpot = model.HasShadowSpot();
    header.hasCameraCollisionSphere = model.HasCameraCollisionSphere();
    header.totalMeshes = model.GetMeshCount();
    WriteTextHeader(header, stream);

    stream << "# MODEL PROPERTIES" << std::endl;

    for (const auto& crashSphere : model.GetCrashSpheres())
        WriteCrashSphere(crashSphere, stream);

    if (model.HasShadowSpot())
        WriteShadowSpot(model.GetShadowSpot(), stream);

    if (model.HasCameraCollisionSphere())
        WriteCameraCollisionSphere(model.GetCameraCollisionSphere(), stream);

    stream << std::endl;

    for (const std::string& meshName : model.GetMeshNames())
    {
        const CModelMesh* mesh = model.GetMesh(meshName);
        assert(mesh != nullptr);
        WriteTextMesh(mesh, meshName, stream);
    }
}
Esempio n. 2
0
void DumpInfo(const CModel& model)
{
    const CModelMesh* mesh = model.GetMesh("main");
    if (mesh == nullptr)
    {
        std::cerr << "Main mesh not found!" << std::endl;
        return;
    }

    Math::Vector bboxMin( Math::HUGE_NUM,  Math::HUGE_NUM,  Math::HUGE_NUM);
    Math::Vector bboxMax(-Math::HUGE_NUM, -Math::HUGE_NUM, -Math::HUGE_NUM);

    std::map<std::string, int> texs1, texs2;
    std::map<int, int> states;
    int variableTexs2 = 0;

    for (const ModelTriangle& t : mesh->GetTriangles())
    {
        bboxMin.x = Math::Min(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, bboxMin.x);
        bboxMin.y = Math::Min(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, bboxMin.y);
        bboxMin.z = Math::Min(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, bboxMin.z);

        bboxMax.x = Math::Max(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, bboxMax.x);
        bboxMax.y = Math::Max(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, bboxMax.y);
        bboxMax.z = Math::Max(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, bboxMax.z);

        texs1[t.tex1Name] += 1;
        if (! t.tex2Name.empty())
            texs2[t.tex2Name] += 1;
        if (t.variableTex2)
            variableTexs2 += 1;
    }

    int total = mesh->GetTriangleCount();

    std::cerr << "---- Info ----" << std::endl;
    std::cerr << "Total triangles: " << total;
    std::cerr << std::endl;
    std::cerr << "Bounding box:" << std::endl;
    std::cerr << " bboxMin: [" << bboxMin.x << ", " << bboxMin.y << ", " << bboxMin.z << "]" << std::endl;
    std::cerr << " bboxMax: [" << bboxMax.x << ", " << bboxMax.y << ", " << bboxMax.z << "]" << std::endl;
    std::cerr << std::endl;
    std::cerr << "Textures:" << std::endl;
    std::cerr << " tex1:" << std::endl;
    PrintStats(texs1, total);
    std::cerr << " tex2:" << std::endl;
    PrintStats(texs2, total);
    std::cerr << " variable tex2: " << variableTexs2 << " / " << total << std::endl;
    std::cerr << std::endl;
}
Esempio n. 3
0
void ModelOutput::WriteBinaryModel(const CModel& model, std::ostream &stream)
{
    const CModelMesh* mesh = model.GetMesh("main");
    if (mesh == nullptr)
        throw CModelIOException("No main mesh found in model");

    ModelHeaderV1AndV2 header;

    header.version = 2;
    header.totalTriangles = mesh->GetTriangleCount();

    WriteBinary<4, int>(header.version, stream);
    WriteBinary<4, int>(header.totalTriangles, stream);

    for (const ModelTriangle& triangle : mesh->GetTriangles())
    {
        ModelTriangleV1AndV2 t;

        t.p1 = triangle.p1;
        t.p2 = triangle.p2;
        t.p3 = triangle.p3;
        t.material.ambient = triangle.ambient;
        t.material.diffuse = triangle.diffuse;
        t.material.specular = triangle.specular;
        t.tex1Name = triangle.tex1Name;
        t.tex2Name = triangle.tex2Name;
        t.variableTex2 = triangle.variableTex2;
        t.state = ConvertToOldState(triangle);

        WriteBinaryVertexTex2(t.p1, stream);
        WriteBinaryVertexTex2(t.p2, stream);
        WriteBinaryVertexTex2(t.p3, stream);
        WriteBinaryMaterial(t.material, stream);
        WriteBinaryString<1>(t.tex1Name, stream);
        WriteBinaryString<1>(t.tex2Name, stream);
        WriteBinaryBool(t.variableTex2, stream);
        WriteBinary<4, int>(t.state, stream);
    }
}
Esempio n. 4
0
void ModelOutput::WriteOldModel(const CModel& model, std::ostream &stream)
{
    const CModelMesh* mesh = model.GetMesh("main");
    if (mesh == nullptr)
        throw CModelIOException("No main mesh found in model");

    OldModelHeader header;
    header.revision = 1;
    header.version = 2;
    header.totalTriangles = mesh->GetTriangleCount();

    WriteBinary<4, int>(header.revision, stream);
    WriteBinary<4, int>(header.version, stream);
    WriteBinary<4, int>(header.totalTriangles, stream);
    for (int i = 0; i < 10; ++i)
        WriteBinary<4, int>(header.reserved[i], stream);

    for (const ModelTriangle& triangle : mesh->GetTriangles())
    {
        OldModelTriangleV3 t;

        t.used = true;

        t.p1 = triangle.p1;
        t.p2 = triangle.p2;
        t.p3 = triangle.p3;

        t.material.ambient = triangle.ambient;
        t.material.diffuse = triangle.diffuse;
        t.material.specular = triangle.specular;
        strncpy(t.texName, triangle.tex1Name.c_str(), 20);
        t.min = 0.0f;
        t.max = 1000000.0f;
        t.state = ConvertToOldState(triangle);

        int no = 0;
        if (triangle.variableTex2)
            no = 1;
        else
            std::sscanf(triangle.tex2Name.c_str(), "dirty%d.png", &no);

        t.texNum2 = no;


        WriteBinary<1, char>(t.used,     stream);
        WriteBinary<1, char>(t.selected, stream);

        /* padding */ WriteBinary<2, unsigned int>(0, stream);

        WriteBinaryVertexTex2(t.p1, stream);
        WriteBinaryVertexTex2(t.p2, stream);
        WriteBinaryVertexTex2(t.p3, stream);

        WriteBinaryMaterial(t.material, stream);
        stream.write(t.texName, 20);
        WriteBinaryFloat(t.min, stream);
        WriteBinaryFloat(t.max, stream);
        WriteBinary<4, long>(t.state, stream);
        WriteBinary<2, short>(t.texNum2, stream);

        WriteBinary<2, short>(t.reserved2, stream);
        WriteBinary<2, short>(t.reserved3, stream);
        WriteBinary<2, short>(t.reserved4, stream);
    }
}