//----------------------------------------------------------------------------
Object* Object::Copy(const std::string& uniqueNameAppend)
{
	// Save the object to a memory buffer.
	OutStream saveStream;

	saveStream.Insert((Object*)this);
	int bufferSize = 0;
	char* buffer = 0;
	saveStream.Save(bufferSize, buffer, BufferIO::BM_DEFAULT_WRITE);

	// Load the object from the memory buffer.
	InStream loadStream;
	loadStream.Load(bufferSize, buffer, BufferIO::BM_DEFAULT_READ);
	delete1(buffer);

	if (uniqueNameAppend != "")
	{
		int numObjects = loadStream.GetNumObjects();
		for (int i = 0; i < numObjects; i++)
		{
			PX2::Object *obj = loadStream.GetObjectAt(i);
			std::string name = obj->GetName();
			if (name.length() > 0)
			{
				name += uniqueNameAppend;
				obj->SetName(name);
			}
		}
	}

	return loadStream.GetObjectAt(0);
}
//----------------------------------------------------------------------------
bool ResourceManager::SaveCachedResource (const std::string &filename)
{
	ScopedCS scopeCS(mResTableMutex);

	OutStream outPut;

	ResTable::iterator it = mResTable.begin();
	for (; it!=mResTable.end(); it++)
	{
		Object *obj = it->second.Obj;
		if (obj)
		{
			outPut.Insert(obj);
		}
	}

	return outPut.Save(filename);
}
Beispiel #3
0
//----------------------------------------------------------------------------
bool EditMap::SaveSceneAs (const char *pathname)
{
	if (!mScene)
		return false;

	OutStream outStream;

	outStream.Insert(mScene);

	if (outStream.Save(pathname))
	{
		Event *event = EditorEventSpace::CreateEventX(
			EditorEventSpace::SavedScene);
		EventWorld::GetSingleton().BroadcastingLocalEvent(event);

		return true;
	}

	return false;
}
Beispiel #4
0
//----------------------------------------------------------------------------
bool Project::Save(const std::string &filename)
{
    if (!SaveConfig(filename))
        return false;

    std::string outPath;
    std::string outBaseName;
    std::string outExt;
    StringHelp::SplitFullFilename(filename, outPath, outBaseName, outExt);

    if (mUIFrame)
    {
        std::string outName = outPath + outBaseName + "_ui.px2obj";

        OutStream output;
        output.Insert(mUIFrame);
        output.Save(outName);
    }

    return false;
}
Beispiel #5
0
//----------------------------------------------------------------------------
Object* Object::Copy (const std::string& uniqueNameAppend) const
{
	// Save the object to a memory buffer.
	OutStream saveStream;
	saveStream.Insert((Object*)this);
	int bufferSize = 0;
	char* buffer = 0;
	saveStream.Save(bufferSize, buffer, BufferIO::BM_DEFAULT_WRITE);

	// Load the object from the memory buffer.
	InStream loadStream;
	loadStream.Load(bufferSize, buffer, BufferIO::BM_DEFAULT_READ);
	delete1(buffer);

	if (uniqueNameAppend != "")
	{
		// The names of the input scene were copied as is.  Generate unique
		// names for the output scene.
		int numObjects = loadStream.GetNumObjects();
		for (int i=0; i<numObjects; i++)
		{
			PX2::Object *obj = loadStream.GetObjectAt(i);
			std::string name = obj->GetName();
			if (name.length() > 0)
			{
				// The object has a name.  Append a string to make the name
				// unique.  TODO:  This code does not ensure that the
				// appended name is some other name in the copied scene.  To
				// do this would require building a set of names and verifying
				// that the appended names are not in this set.  For now we
				// think this is not worth the effort, but maybe later we can
				// add code to do this.
				name += uniqueNameAppend;
				obj->SetName(name);
			}
		}
	}

	return loadStream.GetObjectAt(0);
}
Beispiel #6
0
//----------------------------------------------------------------------------
void SkinnedBiped::CreateScene ()
{
    // Allow for toggle of wireframe.
    mWireState = new0 WireState();
    mRenderer->SetOverrideWireState(mWireState);

    // The biped has materials assigned to its triangle meshes, so they need
    // lighting.
    mLight = new0 Light(Light::LT_DIRECTIONAL);
    mLight->Ambient = Float4(0.5f, 0.5f, 0.5f, 1.0f);
    mLight->Diffuse = mLight->Ambient;
    mLight->Specular = Float4(0.0f, 0.0f, 0.0f, 1.0f);
    mLight->Constant = 0.0f;
    mLight->Linear = 0.0f;
    mLight->Quadratic = 0.0f;
    mLight->Intensity = 1.0f;
    mLight->DVector = mCamera->GetDVector();

    Node* biped = GetNode("Biped");
    Node* pelvis = GetNode("Pelvis");
    Node* spine = GetNode("Spine");
    Node* spine1 = GetNode("Spine1");
    Node* spine2 = GetNode("Spine2");
    Node* spine3 = GetNode("Spine3");
    Node* neck = GetNode("Neck");
    Node* head = GetNode("Head");
    Node* leftClavicle = GetNode("L_Clavicle");
    Node* leftUpperArm = GetNode("L_UpperArm");
    Node* leftForeArm = GetNode("L_Forearm");
    Node* leftHand = GetNode("L_Hand");
    Node* rightClavicle = GetNode("R_Clavicle");
    Node* rightUpperArm = GetNode("R_UpperArm");
    Node* rightForeArm = GetNode("R_Forearm");
    Node* rightHand = GetNode("R_Hand");
    Node* leftThigh = GetNode("L_Thigh");
    Node* leftCalf = GetNode("L_Calf");
    Node* leftFoot = GetNode("L_Foot");
    Node* leftToe = GetNode("L_Toe");
    Node* rightThigh = GetNode("R_Thigh");
    Node* rightCalf = GetNode("R_Calf");
    Node* rightFoot = GetNode("R_Foot");
    Node* rightToe = GetNode("R_Toe");

    biped->AttachChild(pelvis);
        pelvis->AttachChild(spine);
            spine->AttachChild(spine1);
                spine1->AttachChild(spine2);
                    spine2->AttachChild(spine3);
                        spine3->AttachChild(neck);
                            neck->AttachChild(head);
                                // head->AttachChild(hair);
                            neck->AttachChild(leftClavicle);
                                leftClavicle->AttachChild(leftUpperArm);
                                    leftUpperArm->AttachChild(leftForeArm);
                                        leftForeArm->AttachChild(leftHand);
                                    // leftUpperArm->AttachChild(leftArm);
                            neck->AttachChild(rightClavicle);
                                rightClavicle->AttachChild(rightUpperArm);
                                    rightUpperArm->AttachChild(rightForeArm);
                                        rightForeArm->AttachChild(rightHand);
                                    // rightUpperArm->AttachChild(rightArm);
                        // spine3->AttachChild(face);
        pelvis->AttachChild(leftThigh);
            leftThigh->AttachChild(leftCalf);
                leftCalf->AttachChild(leftFoot);
                    leftFoot->AttachChild(leftToe);
                // leftCalf->AttachChild(leftShoe);
            // leftThigh->AttachChild(leftLeg);
            // leftThigh->AttachChild(leftAngle);
        pelvis->AttachChild(rightThigh);
            rightThigh->AttachChild(rightCalf);
                rightCalf->AttachChild(rightFoot);
                    rightFoot->AttachChild(rightToe);
                // rightCalf->AttachChild(rightShoe);
            // rightThigh->AttachChild(rightLeg);
            // rightThigh->AttachChild(rightAnkle);
        // pelvis->AttachChild(shirt);
        // pelvis->AttachChild(pants);


    // The vertex format is shared among all the triangle meshes.
    mVFormat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_NORMAL, VertexFormat::AT_FLOAT3, 0);

    // The TriMesh objects must be created after the Node tree is built,
    // because the TriMesh objects have to find the "bones" that correspond
    // to them.
    TriMesh* hair = GetMesh("Hair",biped);
    TriMesh* leftArm = GetMesh("L_Arm",biped);
    TriMesh* rightArm = GetMesh("R_Arm",biped);
    TriMesh* face = GetMesh("Face",biped);
    TriMesh* leftShoe = GetMesh("L_Shoe",biped);
    TriMesh* leftLeg = GetMesh("L_Leg",biped);
    TriMesh* leftAngle = GetMesh("L_Ankle",biped);
    TriMesh* rightShoe = GetMesh("R_Shoe",biped);
    TriMesh* rightLeg = GetMesh("R_Leg",biped);
    TriMesh* rightAnkle = GetMesh("R_Ankle",biped);
    TriMesh* shirt = GetMesh("Shirt",biped);
    TriMesh* pants = GetMesh("Pants",biped);

    head->AttachChild(hair);
    leftUpperArm->AttachChild(leftArm);
    rightUpperArm->AttachChild(rightArm);
    spine3->AttachChild(face);
    leftCalf->AttachChild(leftShoe);
    leftThigh->AttachChild(leftLeg);
    leftThigh->AttachChild(leftAngle);
    rightCalf->AttachChild(rightShoe);
    rightThigh->AttachChild(rightLeg);
    rightThigh->AttachChild(rightAnkle);
    pelvis->AttachChild(shirt);
    pelvis->AttachChild(pants);

    mScene = new0 Node();
    mScene->LocalTransform.SetRotate(HMatrix(AVector::UNIT_Z,
        0.25f*Mathf::PI));
    mScene->AttachChild(biped);
    mScene->Update();

#if 0
    // For regenerating the biped WMOF whenever engine streaming changes.
    OutStream target;
    target.Insert(mScene);
    target.Save("SkinnedBipedPN.wmof");
#endif
}