コード例 #1
0
ファイル: modelfile.cpp プロジェクト: pol51/colobot
bool CModelFile::WriteBinaryModel(std::ostream& stream)
{
    if (m_triangles.size() == 0)
    {
        GetLogger()->Error("Empty model\n");
        return false;
    }

    NewModelHeader header;

    header.version        = 1;
    header.totalTriangles = m_triangles.size();

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

    for (int i = 0; i < static_cast<int>( m_triangles.size() ); ++i)
    {
        NewModelTriangle1 t;

        t.p1 = m_triangles[i].p1;
        t.p2 = m_triangles[i].p2;
        t.p3 = m_triangles[i].p3;
        t.material = m_triangles[i].material;
        t.tex1Name = m_triangles[i].tex1Name;
        t.tex2Name = m_triangles[i].tex2Name;
        t.variableTex2 = m_triangles[i].variableTex2;
        t.state = m_triangles[i].state;

        switch (m_triangles[i].lodLevel)
        {
            case LOD_Constant: t.lodLevel = 0; break;
            case LOD_Low:      t.lodLevel = 1; break;
            case LOD_Medium:   t.lodLevel = 2; break;
            case LOD_High:     t.lodLevel = 3; break;
        }

        WriteBinaryVertexTex2(t.p1, stream);
        WriteBinaryVertexTex2(t.p2, stream);
        WriteBinaryVertexTex2(t.p3, stream);
        WriteBinaryMaterial(t.material, stream);
        IOUtils::WriteBinaryString<1>(t.tex1Name, stream);
        IOUtils::WriteBinaryString<1>(t.tex2Name, stream);
        IOUtils::WriteBinaryBool(t.variableTex2, stream);
        IOUtils::WriteBinary<4, int>(t.lodLevel, stream);
        IOUtils::WriteBinary<4, int>(t.state, stream);

        if (stream.fail())
        {
            GetLogger()->Error("Error writing model file\n");
            return false;
        }
    }

    return true;
}
コード例 #2
0
ファイル: WriteDumb.cpp プロジェクト: tonttu/assimp
// -----------------------------------------------------------------------------------
uint32_t WriteBinaryScene(const aiScene* scene)
{
	uint32_t len = 0, old = WriteMagic(ASSBIN_CHUNK_AISCENE);

	// basic scene information
	len += Write<unsigned int>(scene->mFlags);
	len += Write<unsigned int>(scene->mNumMeshes);
	len += Write<unsigned int>(scene->mNumMaterials);
	len += Write<unsigned int>(scene->mNumAnimations);
	len += Write<unsigned int>(scene->mNumTextures);
	len += Write<unsigned int>(scene->mNumLights);
	len += Write<unsigned int>(scene->mNumCameras);
	
	// write node graph
	len += WriteBinaryNode(scene->mRootNode)+8;

	// write all meshes
	for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
		const aiMesh* mesh = scene->mMeshes[i];
		len += WriteBinaryMesh(mesh)+8;
	}

	// write materials
	for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
		const aiMaterial* mat = scene->mMaterials[i];
		len += WriteBinaryMaterial(mat)+8;
	}

	// write all animations
	for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
		const aiAnimation* anim = scene->mAnimations[i];
		len += WriteBinaryAnim(anim)+8;
	}


	// write all textures
	for (unsigned int i = 0; i < scene->mNumTextures;++i) {
		const aiTexture* mesh = scene->mTextures[i];
		len += WriteBinaryTexture(mesh)+8;
	}

	// write lights
	for (unsigned int i = 0; i < scene->mNumLights;++i) {
		const aiLight* l = scene->mLights[i];
		len += WriteBinaryLight(l)+8;
	}

	// write cameras
	for (unsigned int i = 0; i < scene->mNumCameras;++i) {
		const aiCamera* cam = scene->mCameras[i];
		len += WriteBinaryCamera(cam)+8;
	}

	ChangeInteger(old,len);
	return len;
}
コード例 #3
0
ファイル: modelfile.cpp プロジェクト: pol51/colobot
bool CModelFile::WriteModel(std::ostream& stream)
{
    if (m_triangles.size() == 0)
    {
        GetLogger()->Error("Empty model\n");
        return false;
    }

    OldModelHeader header;
    header.revision   = 1;
    header.version  = 2;
    header.totalTriangles = m_triangles.size();

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

    for (int i = 0; i < static_cast<int>( m_triangles.size() ); ++i)
    {
        OldModelTriangle3 t;

        t.used = true;

        t.p1 = m_triangles[i].p1;
        t.p2 = m_triangles[i].p2;
        t.p3 = m_triangles[i].p3;

        t.material = m_triangles[i].material;
        strncpy(t.texName, m_triangles[i].tex1Name.c_str(), 20);
        LODLevelToMinMax(m_triangles[i].lodLevel, t.min, t.max);
        t.state = m_triangles[i].state;

        int no = 0;
        if (m_triangles[i].variableTex2)
            no = 1;
        else
            sscanf(m_triangles[i].tex2Name.c_str(), "dirty%d.png", &no); // hardcoded as in the original code

        t.texNum2 = no;


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

        /* padding */ IOUtils::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);
        IOUtils::WriteBinaryFloat(t.min, stream);
        IOUtils::WriteBinaryFloat(t.max, stream);
        IOUtils::WriteBinary<4, long>(t.state, stream);
        IOUtils::WriteBinary<2, short>(t.texNum2, stream);

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

    return true;
}