コード例 #1
0
ファイル: MeshSaverImplv10.cpp プロジェクト: obhi-d/nextar
void MeshSaverImplv1_0::WriteSubMeshData(MeshTemplate* templ,
		const MeshTemplate::PrimitiveGroup& gr,
		ChunkOutputStream& outStream) {

	bool sharedMeshBuffer = false;
	MeshBuffer* buffer = templ->GetSharedMeshBuffer();
	if (!gr.buffer || gr.buffer == buffer) {
		sharedMeshBuffer = true;
	} else
		buffer = gr.buffer;

	{
		uint8 primType = (uint8)buffer->GetPrimitiveType();
		OutputSerializer& ser = outStream.BeginChunk(MCID_SUBMESH_INFO);
		ser << primType;
		outStream.EndChunk();
	}

	if (sharedMeshBuffer) {
		{
			uint32 start = gr.startVertex;
			uint32 count = gr.vertexCount;
			OutputSerializer& ser = outStream.BeginChunk(MCID_SHARED_VERTEX_DATA);
			ser << start << count;
			outStream.EndChunk();
		}
		{
			uint32 start = gr.startIndex;
			uint32 count = gr.indexCount;
			OutputSerializer& ser = outStream.BeginChunk(MCID_SHARED_INDEX_DATA);
			ser << start << count;
			outStream.EndChunk();
		}
	} else {
		WriteVertexData(buffer, outStream);
		WriteIndexData(buffer, outStream);
	}

	WriteBoundsInfo(gr.bounds, outStream);
	if (gr.material && gr.material != templ->GetSharedMaterial()) {
		WriteMaterialData(gr.material, outStream);
	}

	{
		OutputSerializer& ser = outStream.BeginChunk(MCID_SUBMESH_END);
		outStream.EndChunk();
	}
}
コード例 #2
0
ファイル: MeshSaverImplv10.cpp プロジェクト: obhi-d/nextar
void MeshSaverImplv1_0::Save(OutputStreamPtr& out,
		AssetSaver& saver) {

	try {
		MeshTemplate* mesh = static_cast<MeshTemplate*>(
					saver.GetRequestPtr()->GetStreamedObject());

		WriteVersion(out);

		ChunkOutputStream stream(out);
		WriteMeshHeader(mesh, stream);
		WriteBoundsInfo(mesh->GetBounds(), stream);
		MeshBuffer* buffer = mesh->GetSharedMeshBuffer();
		MaterialTemplatePtr material = mesh->GetSharedMaterial();
		if (buffer) {
			WriteVertexData(buffer, stream);
			WriteIndexData(buffer, stream);
		}

		if (material) {
			WriteMaterialData(material, stream);
		}

		uint32 numPrim = mesh->GetNumPrimitiveGroups();
		for (uint32 i = 0; i < numPrim; ++i) {
			OutputSerializer& ser = stream.BeginChunk(MCID_SUBMESH_DATA);
			WriteSubMeshData(mesh, mesh->GetPrimitive(i), stream);
			stream.EndChunk();
		}
	} catch (const GracefulErrorExcept& e) {
		saver.GetRequestPtr()->SetCompleted(false);
		NEX_THROW(e);
	}

	saver.GetRequestPtr()->SetCompleted(true);
}
コード例 #3
0
int Blockporter::DoExport(const TCHAR* name, ExpInterface* ei, Interface* i, BOOL supressPrompts, DWORD options)
{
	INode* root;
	//caption and message for MessagesBoxes
	TCHAR msg[MB_BUFFER_LENGTH];
	TCHAR cap[MB_BUFFER_LENGTH];

	//Get the root node
	root = i->GetRootNode();

	//the node of our object should be a groupnode, which contains every object
	//we want to export
	i->PushPrompt(_T("Searching for Group..."));
	bool found = false;
	for(int idx = 0; idx < root->NumberOfChildren(); idx++)
	{
		if(root->GetChildNode(idx)->IsGroupHead())
		{
			//we found our group
			//next step is to make the group node our new root, because every object
			//we want is part of this group

			found = true;
			root = root->GetChildNode(idx);
			break;
		}
	}

	if(!found)
	{
		MessageBox(nullptr, GetString(IDS_ERROR_NO_GROUP, msg), GetString(IDS_GENERAL_ERROR, cap), MB_OK | MB_ICONERROR);
		return 0;
	}

	//Now that we have the groupnode let's compare the fileversions
	if(!IsNewModelVersion(name, root->GetName()))
	{
		if(MessageBox(nullptr, GetString(IDS_VER_TO_LOW_MSG, msg), GetString(IDS_VER_TO_LOW_CAP, cap), MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
			return 1;
	}

	i->PushPrompt(_T("Opening File"));
	Interface14* iface = GetCOREInterface14();
	UINT code = iface->DefaultTextSaveCodePage(true);
	MaxSDK::Util::Path storageNamePath(name);
	storageNamePath.SaveBaseFile();
	switch (code & MaxSDK::Util::MaxStringDataEncoding::MSDE_CP_MASK)
	{
	case CP_UTF8:
		mStream = _tfopen(name, _T("wt, ccs=UFT-8"));
		break;
	case MaxSDK::Util::MaxStringDataEncoding::MSDE_CP_UTF16:
		mStream = _tfopen(name, _T("wt, ccs=UTF-16BE"));
		break;
	default:
		mStream = _tfopen(name, _T("wt"));
	}
	if(!mStream)
		return 0;

	//now we have our file stream, so let's write the header
	i->PushPrompt(_T("Writing Header"));
	WriteHeader(root->GetName(), root->NumberOfChildren());

	//now that we have the header written, let's iterate through the objects in the
	//group and export the meshes and lights

	INode* child;
    Point3 pMin(0,0,0), pMax(0,0,0);

	for(int idx = 0; idx < root->NumberOfChildren(); idx++)
	{
		child = root->GetChildNode(idx);
		i->PushPrompt(_T("Processing Object %s", child->GetName()));
		if(child->IsGroupHead())
		{
			MessageBox(nullptr, GetString(IDS_ERROR_TO_MANY_GROUPS, msg), GetString(IDS_GENERAL_ERROR, cap), MB_OK | MB_ICONERROR);
			continue;
		}

		ObjectState os = child->EvalWorldState(0);

		//let's take a look at the SuperClassID of the object
		//so we find out if it's a mesh or a light
		if(!os.obj)
			continue; //somehow this node doesn't have an object

        Box3 boundBox;

		switch(os.obj->SuperClassID())
		{
		case GEOMOBJECT_CLASS_ID:
			_ftprintf(mStream, _T("<ObjectID=%i>\n"), idx);
			i->PushPrompt(_T("Writing MeshData for Object %s", child->GetName()));
			boundBox = WriteMeshData(child, idx);
            pMin.x = (boundBox.Min().x < pMin.x) ? boundBox.Min().x : pMin.x;
            pMin.y = (boundBox.Min().y < pMin.y) ? boundBox.Min().y : pMin.y;
            pMax.x = (boundBox.Max().x > pMax.x) ? boundBox.Max().x : pMax.x;
            pMax.y = (boundBox.Max().y > pMax.y) ? boundBox.Max().y : pMax.y;
			i->PushPrompt(_T("Writing MaterialData for Object %s", child->GetName()));
			WriteMaterialData(child);
			_ftprintf(mStream, _T("</Object>\n"));
			break;
		//case LIGHT_CLASS_ID:
		//	WriteLightData(child, idx);
		//	break;
		}
	}

    //Write the Bounding Box
    _ftprintf(mStream, _T("<BoundingBox>\n"));
    _ftprintf(mStream, _T("\t<Min=%f,%f>\n"), pMin.x, pMin.y);
    _ftprintf(mStream, _T("\t<Max=%f,%f>\n"), pMax.x, pMax.y);
    _ftprintf(mStream, _T("</BoundingBox>\n"));
	//we are done exporting, so close the stream
	i->PushPrompt(_T("Closing file..."));
	fclose(mStream);

	MessageBox(nullptr, GetString(IDS_FINISH_MSG, msg), GetString(IDS_FINISH_CAP, cap), MB_OK | MB_ICONINFORMATION);

	return 1;
}
コード例 #4
0
ファイル: SaveLoadMap.cpp プロジェクト: ignatenkobrain/e2dit
void MapEditor2D::SaveToTextFile (const char *fn) {
	objectId = 0;
	FILE *F = fopen (fn, "w+");
	string ws = "                   ";

	fputs ("Room\n", F);
	fputs (string("    Size : "+IntToStr (RoomSize.x)+", "+IntToStr (RoomSize.y)+";\n").c_str(), F);
	fputs ("end;\n\n", F);

	// Cameras
	for (int i = 0; i < Cameras.size(); i++) {
		fputs ("Camera\n", F);
		fputs (string("    Id : "+IntToStr(i)+";\n").c_str(), F);
		fputs (string("    Name : \""+wstring2string(Cameras[i]->Name)+"\";\n").c_str(), F);
		fputs (string("    Position : "+IntToStr (Cameras[i]->Position.x)+", "+IntToStr (Cameras[i]->Position.y)+";\n").c_str(), F);
		fputs (string("    Size : "+IntToStr (Cameras[i]->Size.x)+", "+IntToStr (Cameras[i]->Size.y)+";\n").c_str(), F);
		fputs ("end;\n\n", F);
	}

	// Layers
	for (int i = 0; i < Layers.size(); i++) {
		string bVisible = Layers[i]->Visible ? "True" : "False";
		fputs ("Layer\n", F);
		fputs (string("    Id : "+IntToStr(i)+";\n").c_str(), F);
		fputs (string("    Name : \""+Layers[i]->Name+"\";\n").c_str(), F);
		fputs (string("    Visible : "+bVisible+";\n").c_str(), F);
		fputs ("end;\n\n", F);

		for (int j = 0; j < Layers[i]->Objects.size(); j++) {
			Layers[i]->Objects[j]->Id = j;
			Layers[i]->Objects[j]->LayerId = i;
		}
	}

	// Objects
	for (int i = 0; i < Layers.size(); i++) {
		for (int j = 0; j < Layers[i]->Objects.size(); j++) {
			BaseGameObject *Obj = Layers[i]->Objects[j];
			string Type = "";

			if (dynamic_cast<PolygonObject*>(Obj)) Type = "Polygon";
			else if (dynamic_cast<PointObject*>(Obj)) Type = "Point";
			else if (dynamic_cast<LightObject*>(Obj)) Type = "Light";
			else Type = "Sprite";

			fputs (string("Object ("+Type+")\n").c_str(), F);
			fputs (string("    Id : "      +IntToStr(j)+";\n").c_str(), F);
			fputs (string("    Layer : "   +IntToStr(i)+";\n").c_str(), F);
			fputs (string("    Class : \"" +Obj->GameClass+";\"\n").c_str(), F);
			fputs (string("    Position : "+FloatToStr(Obj->Position.x)+", "+FloatToStr(Obj->Position.y)+";\n").c_str(), F);
			fputs (string("    Size : "    +FloatToStr(Obj->Size.x)+", "+FloatToStr(Obj->Size.y)+";\n").c_str(), F);
			fputs (string("    Rotation : "+FloatToStr(Obj->Rotation)+";\n").c_str(), F);

			if (dynamic_cast<PolygonObject*>(Obj))    WritePolygonObjectData ((PolygonObject*) Obj, F);
			else if (dynamic_cast<PointObject*>(Obj)) WritePointObjectData   (  (PointObject*) Obj, F);
			else if (dynamic_cast<LightObject*>(Obj)) WriteLightObjectData   (  (LightObject*) Obj, F);
			else WriteSpriteObjectData (Obj, F);
			//
			WriteMaterialData (Obj, F);
			WritePolygonsData (Obj, F);
			WriteLabelsData   (Obj, F);

			fputs ("end;\n\n", F);
			/*if (dynamic_cast<PolygonObject*>(Obj)) {

			} else {
				
				
				fputs ("end;\n\n", F);
			}*/
		}
	}

	fclose (F);
}