Skip to content

Commit

Permalink
Added Physic section exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
mycheckgithub authored and franck-ohayon-sb committed May 20, 2015
1 parent 762055a commit 6fa340d
Show file tree
Hide file tree
Showing 27 changed files with 1,616 additions and 8 deletions.
14 changes: 14 additions & 0 deletions COLLADAMaya/include/COLLADAMayaDocumentExporter.h
Expand Up @@ -34,7 +34,9 @@ namespace COLLADAMaya
class EffectTextureExporter;
class ImageExporter;
class GeometryExporter;
class PhysicsExporter;
class VisualSceneExporter;
class PhysicSceneExporter;
class AnimationExporter;
class AnimationClipExporter;
class AnimationSampleCache;
Expand Down Expand Up @@ -72,9 +74,15 @@ namespace COLLADAMaya
/** Exports the geometry. */
GeometryExporter* mGeometryExporter;

/** Exports the geometry. */
PhysicsExporter* mPhysicsExporter;

/** Exports the visual scene. */
VisualSceneExporter* mVisualSceneExporter;

/** Exports the Physic scene */
PhysicSceneExporter* mPhysicSceneExporter;

/** Exports the animations. */
AnimationExporter* mAnimationExporter;

Expand Down Expand Up @@ -201,6 +209,12 @@ namespace COLLADAMaya
*/
VisualSceneExporter* getVisualSceneExporter();

/**
* Returns a pointer to the physic scene exporter.
* @return PhysicSceneExporter* Pointer to the visual scene exporter
*/
PhysicSceneExporter* getPhysicSceneExporter();

/**
* Returns a pointer to the animation exporter.
* @return AnimationExporter* Pointer to the animation exporter
Expand Down
3 changes: 2 additions & 1 deletion COLLADAMaya/include/COLLADAMayaExportOptions.h
Expand Up @@ -61,7 +61,7 @@ namespace COLLADAMaya
/****************************/
/** Filter export */
/****************************/

static bool mExportPhysicsModels;
static bool mExportPolygonMeshes;
static bool mExportLights;
static bool mExportCameras;
Expand Down Expand Up @@ -130,6 +130,7 @@ namespace COLLADAMaya
/** Filter export */
/****************************/

static bool exportPhysicsModels();
static bool exportPolygonMeshes();
static bool exportLights();
static bool exportCameras();
Expand Down
82 changes: 82 additions & 0 deletions COLLADAMaya/include/COLLADAMayaPhysicSceneExporter.h
@@ -0,0 +1,82 @@
/*
Copyright (c) 2008-2009 NetAllied Systems GmbH
This file is part of COLLADAMaya.
Portions of the code are:
Copyright (c) 2005-2007 Feeling Software Inc.
Copyright (c) 2005-2007 Sony Computer Entertainment America
Copyright (c) 2004-2005 Alias Systems Corp.
Licensed under the MIT Open Source License,
for details please see LICENSE file or the website
http://www.opensource.org/licenses/mit-license.php
*/

#ifndef __COLLADA_MAYA_PHYSIC_SCENE_EXPORTER_H__
#define __COLLADA_MAYA_PHYSIC_SCENE_EXPORTER_H__

#include "COLLADAMayaStableHeaders.h"
#include "COLLADASWLibraryPhysicsScenes.h"
#include "COLLADASWStreamWriter.h"
#include "COLLADASWInstanceRigidBody.h"

#include "COLLADAMayaDocumentExporter.h"
#include "COLLADAMayaSceneElement.h"

#include "COLLADABUIDList.h"

#include <maya/MDagPath.h>
#include <maya/MFnTransform.h>
#include <maya/MFnMesh.h>


class DocumentExporter;

namespace COLLADAMaya
{

/**
* Exports the transform data of the visual scene.
*
* All transform components with units will be in maya's internal units
* (radians for rotations and centimeters for translations).
* We have to translate them into the working units of the current scene!
*/
class PhysicSceneExporter : public COLLADASW::LibraryPhysicsScenes
{

private:

/** The id of the current scene. */
String mSceneId;

/** Pointer to the document exporter. */
DocumentExporter* mDocumentExporter;


public:

/**
* Constructor
* @param streamWriter Pointer to the collada stream writer.
* @param documentExporter Pointer to the main document exporter.
* @param sceneId Name of the current scene to export. Has an empty string as default value.
*/
PhysicSceneExporter ( COLLADASW::StreamWriter* streamWriter,
DocumentExporter* documentExporter,
const String& sceneId = EMPTY_STRING );
/**
* Destructor.
*/
virtual ~PhysicSceneExporter() {};

/**
* Exports the visual scene with the transforms of all included elements
*/
bool exportPhysicScenes();
};

}

#endif //__COLLADA_MAYA_VISUAL_SCENE_EXPORTER_H__
130 changes: 130 additions & 0 deletions COLLADAMaya/include/COLLADAMayaPhysicsExporter.h
@@ -0,0 +1,130 @@
/*
Copyright (c) 2008-2009 NetAllied Systems GmbH
This file is part of COLLADAMaya.
Portions of the code are:
Copyright (c) 2005-2007 Feeling Software Inc.
Copyright (c) 2005-2007 Sony Computer Entertainment America
Copyright (c) 2004-2005 Alias Systems Corp.
Licensed under the MIT Open Source License,
for details please see LICENSE file or the website
http://www.opensource.org/licenses/mit-license.php
*/
#ifndef __COLLADA_MAYA_PHYSICS_EXPORTER_H__
#define __COLLADA_MAYA_PHYSICS_EXPORTER_H__

#include "COLLADAMayaStableHeaders.h"
#include "COLLADAMayaDocumentExporter.h"
#include "COLLADAMayaSceneElement.h"
#include <vector>
#include <time.h>
#include <maya/MFnMesh.h>
#include <maya/MDagPath.h>
#include "COLLADASWStreamWriter.h"
#include "COLLADASWLibraryPhysicsModels.h"
#include "COLLADABUIDList.h"


namespace COLLADAMaya
{

class DocumentExporter;
class ElementWriter;



/************************************************************************/
/* This class writes the <library_geometries>. */
/************************************************************************/
class PhysicsExporter : public COLLADASW::LibraryPhysicsModels
{

private:

/**
* The list of the unique collada ids.
*/
COLLADABU::IDList mPhysicsIdList;

/**
* Pointer to the document exporter.
*/
DocumentExporter* mDocumentExporter;

/**
* A collada id for every maya id.
*/
StringToStringMap mMayaIdColladaIdMap;


public:

typedef struct BodyTarget {
String Body;
String Target;
} BodyTarget;

typedef std::map<String, BodyTarget> RB_Map;

/* @param streamWriter The stream the output will be written to */
PhysicsExporter ( COLLADASW::StreamWriter* streamWriter, DocumentExporter* documentExporter );
virtual ~PhysicsExporter();

/** Walk through the scene graph and export all geometries. */
void exportAllPhysics();

/** closes the physics tags in the collada document */
void endExport();

/** Generate the collada id, if not done before and stores it in the scene element. */
const String generateColladaMeshId ( const MDagPath dagPath );

/** export physic element */
void exportPhysics ( SceneElement* sceneElement );

/** Returns the collada geometry id of the current physics node. */
const String& getColladaPhysicsId ( MDagPath dagPath );

// static RB_Map& getRB_Map() { return myMap; }

static RB_Map myMap;

private:

/**
* A collada id for every maya id.
*/
const String& findColladaPhysicsId ( const String& mayaPhysicsId );

/** Returns the tolerance value for double value comparison. */
const double getTolerance () const
{
return mDocumentExporter->getTolerance ();
}

/** Exports the current scene element and all it's children. */
void exportAllPhysics ( SceneElement* sceneElement, bool isVisible );

/** export physic element */
bool exportPhysicsElement(SceneElement* sceneElement);

/** Exports all physics data of the current mesh. */
bool exportPhysicModel(MDagPath& dagPath);

void createShape(MDagPath& childDagPath);

void exportDecomposedTransform();
void exportTranslation(const String name, const MPoint& translation);
void exportTranslation(const String name, const MVector& translation);
void exportRotation(const String name, const MEulerRotation& rotation);

bool mIsJoint;
bool mIsFirstRotation;
MTransformationMatrix mTransformMatrix;
MObject mTransformObject;
};
}

#endif //__COLLADA_MAYA_PHYSICS_EXPORTER_H__
10 changes: 9 additions & 1 deletion COLLADAMaya/include/COLLADAMayaSyntax.h
Expand Up @@ -50,6 +50,10 @@ namespace COLLADAMaya
/** The unique name for the visual scene node on export. */
static const String VISUAL_SCENE_NODE_ID = "VisualSceneNode";

/** The unique name for the physic scene node on export. */
static const String PHYSIC_SCENE_NODE_ID = "collada_physics_scene";


/** The standard name for the collada id attribute. */
static const String COLLADA_ID_ATTRIBUTE_NAME = "colladaId";
static const String COLLADA_EFFECT_ID_ATTRIBUTE_NAME = "colladaEffectId";
Expand Down Expand Up @@ -307,7 +311,11 @@ namespace COLLADAMaya
/** Constants for the physical scenes. */
static const char* NIMA_INTERNAL_PHYSIKS = "nimaInternalPhysics";
static const char* AGEIA_PHYSIKS_MODEL = "AgeiaPhysicsModel";

static const char* ATTR_MASS = "mass";
static const char* ATTR_DYNAMIC = "dynamic";
static const char* ATTR_INERTIA = "inertia";
static const char* ATTR_EXTENT = "extent";

/** Shader constants */
static const char* COLLADA_FX_SHADER = "colladafxShader";
static const char* COLLADA_FX_PASSES = "colladafxPasses";
Expand Down
13 changes: 13 additions & 0 deletions COLLADAMaya/scripts/.COLLADAMayaVersionInfo.h
@@ -0,0 +1,13 @@
#ifndef __COLLADAMAYA_VERSIONINFO_H__
#define __COLLADAMAYA_VERSIONINFO_H__

#include "COLLADAMayaPrerequisites.h"

namespace COLLADAMaya
{
const String CURRENT_REVISION = "3b4d80c";
const String CURRENT_PLATFORM = "x64";
const String CURRENT_CONFIGURATION = "DebugPlugin2015";
}

#endif // __COLLADAMAYA_VERSIONINFO_H__
8 changes: 6 additions & 2 deletions COLLADAMaya/scripts/COLLADAMaya.vcxproj
Expand Up @@ -1180,7 +1180,7 @@ copy "$(ProjectDir)*.mel" "%25MAYA_PATH2011_X64%25\scripts\others"
</ClCompile>
<Link>
<AdditionalOptions>/export:initializePlugin /export:uninitializePlugin %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>Foundation.lib;OpenMaya.lib;OpenMayaAnim.lib;OpenMayaRender.lib;OpenMayaUI.lib;cg.lib;cgGL.lib;OpenGL32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Foundation.lib;OpenMaya.lib;OpenMayaAnim.lib;OpenMayaRender.lib;OpenMayaUI.lib;cg.lib;cgGL.lib;OpenGL32.lib;winmm.lib;OpenMayaFX.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
<Version>1.3</Version>
<AdditionalLibraryDirectories>$(MAYA_PATH2011)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
Expand Down Expand Up @@ -1749,7 +1749,7 @@ copy "$(ProjectDir)*.mel" "%25MAYA_PATH2014_X64%25\scripts\others"
</ClCompile>
<Link>
<AdditionalOptions>/export:initializePlugin /export:uninitializePlugin %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>Foundation.lib;OpenMaya.lib;OpenMayaAnim.lib;OpenMayaRender.lib;OpenMayaUI.lib;cg.lib;cgGL.lib;OpenGL32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Foundation.lib;OpenMaya.lib;OpenMayaAnim.lib;OpenMayaRender.lib;OpenMayaUI.lib;OpenMayaFX.lib;cg.lib;cgGL.lib;OpenGL32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).mll</OutputFile>
<Version>1.3</Version>
<AdditionalLibraryDirectories>$(MAYA_PATH2015_X64)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
Expand Down Expand Up @@ -3371,6 +3371,8 @@ copy "$(ProjectDir)*.mel" "%25MAYA_PATH2012_X64%25\scripts\others"
<ClCompile Include="..\src\COLLADAMayaImportOptions.cpp" />
<ClCompile Include="..\src\COLLADAMayaLightExporter.cpp" />
<ClCompile Include="..\src\COLLADAMayaMaterialExporter.cpp" />
<ClCompile Include="..\src\COLLADAMayaPhysicSceneExporter.cpp" />
<ClCompile Include="..\src\COLLADAMayaPhysicsExporter.cpp" />
<ClCompile Include="..\src\COLLADAMayaPrecompiledHeaders.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='DebugConsole2011|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='DebugConsole2011|x64'">Create</PrecompiledHeader>
Expand Down Expand Up @@ -3461,6 +3463,8 @@ copy "$(ProjectDir)*.mel" "%25MAYA_PATH2012_X64%25\scripts\others"
<ClInclude Include="..\include\COLLADAMayaLightExporter.h" />
<ClInclude Include="..\include\COLLADAMayaMaterialExporter.h" />
<ClInclude Include="..\include\COLLADAMayaMorphController.h" />
<ClInclude Include="..\include\COLLADAMayaPhysicSceneExporter.h" />
<ClInclude Include="..\include\COLLADAMayaPhysicsExporter.h" />
<ClInclude Include="..\include\COLLADAMayaPlatform.h" />
<ClInclude Include="..\include\COLLADAMayaPolygonSource.h" />
<ClInclude Include="..\include\COLLADAMayaPrerequisites.h" />
Expand Down
10 changes: 10 additions & 0 deletions COLLADAMaya/scripts/COLLADAMaya.vcxproj.filters
Expand Up @@ -166,6 +166,11 @@
</ClCompile>
<ClCompile Include="..\src\COLLADAMayaAttributeParser.cpp">
<Filter>Source Files\Helpers</Filter>
<ClCompile Include="..\src\COLLADAMayaPhysicSceneExporter.cpp">
<Filter>Source Files\Exporters</Filter>
</ClCompile>
<ClCompile Include="..\src\COLLADAMayaPhysicsExporter.cpp">
<Filter>Source Files\Exporters</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -297,6 +302,11 @@
</ClInclude>
<ClInclude Include="..\include\COLLADAMayaAttributeParser.h">
<Filter>Header Files\Helpers</Filter>
<ClInclude Include="..\include\COLLADAMayaPhysicSceneExporter.h">
<Filter>Header Files\Exporters</Filter>
</ClInclude>
<ClInclude Include="..\include\COLLADAMayaPhysicsExporter.h">
<Filter>Header Files\Exporters</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 6fa340d

Please sign in to comment.