[DEV] better physic properties management

This commit is contained in:
Edouard DUPIN 2013-08-12 21:55:05 +02:00
parent 3f2ba7907f
commit 5279f00379
11 changed files with 100 additions and 42 deletions

View File

@ -208,9 +208,9 @@ class ExportEMF(bpy.types.Operator, ExportHelper):
) )
collision_object_name = StringProperty( collision_object_name = StringProperty(
name="Collision root name", name="Collision root name (strat with)",
description="The top-level name that will contain the physics shapes", description="The top-level name that will contain the physics shapes",
default="physic" default="phys"
) )
axis_forward = EnumProperty( axis_forward = EnumProperty(

View File

@ -64,7 +64,7 @@ def out_quaternion_z_up( q ):
return "%g %g %g %g" % ( q.w, q.x, q.y, q.z ) return "%g %g %g %g" % ( q.w, q.x, q.y, q.z )
def getPhysicsShape(obj, use_y_up=True): def getPhysicsShape(obj, mainObjScale, use_y_up=True):
shape = "" shape = ""
props = { } props = { }
name = obj.name.lower() name = obj.name.lower()
@ -87,7 +87,7 @@ def getPhysicsShape(obj, use_y_up=True):
# SPHERE # SPHERE
elif name.startswith('sph'): elif name.startswith('sph'):
shape = "Sphere" shape = "Sphere"
props["radius"] = obj.scale.x props["radius"] = obj.scale.x * mainObjScale.x
# CONE # CONE
elif name.startswith('cone'): elif name.startswith('cone'):
shape = "Cone" shape = "Cone"
@ -130,7 +130,7 @@ def getPhysicsShape(obj, use_y_up=True):
return (shape, props) return (shape, props)
def writeCollisionShape(object, file): def writeCollisionShape(object, file, mainObjScale):
if len(getChildren(object))==0: if len(getChildren(object))==0:
# no phisical shape ... # no phisical shape ...
return return
@ -140,7 +140,7 @@ def writeCollisionShape(object, file):
print(" element='%s' type '%s'" % (subObj.name,str(subObj.type))) print(" element='%s' type '%s'" % (subObj.name,str(subObj.type)))
if subObj.type != 'MESH': if subObj.type != 'MESH':
continue continue
(shape, props) = getPhysicsShape(subObj) (shape, props) = getPhysicsShape(subObj, mainObjScale)
if shape=="": if shape=="":
print("error of shape detection type ..."); print("error of shape detection type ...");
continue continue
@ -569,9 +569,9 @@ def write_file(filepath,
##################################################################### #####################################################################
for subObj in getChildren(ob_main): for subObj in getChildren(ob_main):
print(" child : '%s'" % (subObj.name)) print(" child : '%s'" % (subObj.name))
if subObj.name.lower() == EXPORT_COLLISION_NAME: if subObj.name.lower().startswith(EXPORT_COLLISION_NAME):
print(" find physics : '%s'" % (subObj.name)) print(" find physics : '%s'" % (subObj.name))
writeCollisionShape(subObj, file) writeCollisionShape(subObj, file, ob_main.scale)
##################################################################### #####################################################################
## Now we have all our materials, save them in the material section ## Now we have all our materials, save them in the material section

View File

@ -67,15 +67,10 @@ ewol::Mesh::~Mesh(void)
ewol::resource::Release(m_verticesVBO); ewol::resource::Release(m_verticesVBO);
} }
//#define DISPLAY_NB_VERTEX_DISPLAYED
void ewol::Mesh::Draw(mat4& positionMatrix) void ewol::Mesh::Draw(mat4& positionMatrix)
{ {
//EWOL_DEBUG("Request Draw : " << m_listFaces.GetValue(0).m_index.Size() << " elements");
/*
if (m_listIndexFaces.Size()<=0) {
return;
}
*/
if (m_GLprogram==NULL) { if (m_GLprogram==NULL) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
@ -97,8 +92,9 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
m_GLprogram->SendAttributePointer(m_GLNormal, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES_NORMAL); m_GLprogram->SendAttributePointer(m_GLNormal, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES_NORMAL);
// draw lights : // draw lights :
m_light.Draw(m_GLprogram); m_light.Draw(m_GLprogram);
#ifdef DISPLAY_NB_VERTEX_DISPLAYED
int32_t nbElementDraw = 0; int32_t nbElementDraw = 0;
#endif
for (esize_t kkk=0; kkk<m_listFaces.Size(); kkk++) { for (esize_t kkk=0; kkk<m_listFaces.Size(); kkk++) {
if (false == m_materials.Exist(m_listFaces.GetKey(kkk))) { if (false == m_materials.Exist(m_listFaces.GetKey(kkk))) {
EWOL_WARNING("missing materials : '" << m_listFaces.GetKey(kkk) << "'"); EWOL_WARNING("missing materials : '" << m_listFaces.GetKey(kkk) << "'");
@ -106,9 +102,13 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
} }
m_materials[m_listFaces.GetKey(kkk)]->Draw(m_GLprogram, m_GLMaterial); m_materials[m_listFaces.GetKey(kkk)]->Draw(m_GLprogram, m_GLMaterial);
ewol::openGL::DrawElements(GL_TRIANGLES, m_listFaces.GetValue(kkk).m_index); ewol::openGL::DrawElements(GL_TRIANGLES, m_listFaces.GetValue(kkk).m_index);
#ifdef DISPLAY_NB_VERTEX_DISPLAYED
nbElementDraw += m_listFaces.GetValue(kkk).m_index.Size(); nbElementDraw += m_listFaces.GetValue(kkk).m_index.Size();
#endif
} }
EWOL_DEBUG("Request Draw : " << m_listFaces.Size() << ":" << nbElementDraw << " elements [" << m_name << "]"); #ifdef DISPLAY_NB_VERTEX_DISPLAYED
EWOL_DEBUG("Request Draw : " << m_listFaces.Size() << ":" << nbElementDraw << " elements [" << m_name << "]");
#endif
m_GLprogram->UnUse(); m_GLprogram->UnUse();
ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST);
// TODO : UNDERSTAND why ... it is needed // TODO : UNDERSTAND why ... it is needed
@ -116,12 +116,6 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
} }
void ewol::Mesh::Draw2(mat4& positionMatrix) void ewol::Mesh::Draw2(mat4& positionMatrix)
{ {
//
/*
if (m_listIndexFaces.Size()<=0) {
return;
}
*/
if (m_GLprogram==NULL) { if (m_GLprogram==NULL) {
EWOL_ERROR("No shader ..."); EWOL_ERROR("No shader ...");
return; return;
@ -143,7 +137,9 @@ void ewol::Mesh::Draw2(mat4& positionMatrix)
m_light.Draw(m_GLprogram); m_light.Draw(m_GLprogram);
// draw materials : // draw materials :
int32_t nbElementDraw = 0; #ifdef DISPLAY_NB_VERTEX_DISPLAYED
int32_t nbElementDraw = 0;
#endif
for (esize_t kkk=0; kkk<m_listFaces.Size(); kkk++) { for (esize_t kkk=0; kkk<m_listFaces.Size(); kkk++) {
if (false == m_materials.Exist(m_listFaces.GetKey(kkk))) { if (false == m_materials.Exist(m_listFaces.GetKey(kkk))) {
EWOL_WARNING("missing materials : '" << m_listFaces.GetKey(kkk) << "'"); EWOL_WARNING("missing materials : '" << m_listFaces.GetKey(kkk) << "'");
@ -151,9 +147,13 @@ void ewol::Mesh::Draw2(mat4& positionMatrix)
} }
m_materials[m_listFaces.GetKey(kkk)]->Draw(m_GLprogram, m_GLMaterial); m_materials[m_listFaces.GetKey(kkk)]->Draw(m_GLprogram, m_GLMaterial);
ewol::openGL::DrawElements(GL_TRIANGLES, m_listFaces.GetValue(kkk).m_index); ewol::openGL::DrawElements(GL_TRIANGLES, m_listFaces.GetValue(kkk).m_index);
nbElementDraw += m_listFaces.GetValue(kkk).m_index.Size(); #ifdef DISPLAY_NB_VERTEX_DISPLAYED
nbElementDraw += m_listFaces.GetValue(kkk).m_index.Size();
#endif
} }
EWOL_DEBUG("Request Draw : " << m_listFaces.Size() << ":" << nbElementDraw << " elements [" << m_name << "]"); #ifdef DISPLAY_NB_VERTEX_DISPLAYED
EWOL_DEBUG("Request Draw : " << m_listFaces.Size() << ":" << nbElementDraw << " elements [" << m_name << "]");
#endif
m_GLprogram->UnUse(); m_GLprogram->UnUse();
ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST);
// TODO : UNDERSTAND why ... it is needed // TODO : UNDERSTAND why ... it is needed
@ -862,7 +862,7 @@ bool ewol::Mesh::LoadEMF(const etk::UString& _fileName)
continue; continue;
} }
m_physics.PushBack(physics); m_physics.PushBack(physics);
EWOL_DEBUG(" " << inputDataLine); EWOL_DEBUG(" " << m_physics.Size() << " " << inputDataLine);
currentMode = EMFModuleMeshPhysicsNamed; currentMode = EMFModuleMeshPhysicsNamed;
} else if (currentMode == EMFModuleMeshPhysicsNamed) { } else if (currentMode == EMFModuleMeshPhysicsNamed) {
if (physics == NULL) { if (physics == NULL) {

View File

@ -103,7 +103,7 @@ namespace ewol
etk::Vector<vec3> m_listVertexNormal; //!< List of all Face normal, when calculated etk::Vector<vec3> m_listVertexNormal; //!< List of all Face normal, when calculated
etk::Hash<FaceIndexing> m_listFaces; //!< List of all Face for the mesh etk::Hash<FaceIndexing> m_listFaces; //!< List of all Face for the mesh
etk::Hash<ewol::Material*> m_materials; etk::Hash<ewol::Material*> m_materials;
etk::Vector<ewol::PhysicsShape*> m_physics; //!< collision shape module ... etk::Vector<ewol::PhysicsShape*> m_physics; //!< collision shape module ... (independent of bullet lib)
protected: protected:
ewol::VirtualBufferObject* m_verticesVBO; ewol::VirtualBufferObject* m_verticesVBO;
public: public:
@ -113,15 +113,9 @@ namespace ewol
virtual void Draw(mat4& positionMatrix); virtual void Draw(mat4& positionMatrix);
virtual void Draw2(mat4& positionMatrix); virtual void Draw2(mat4& positionMatrix);
void GenerateVBO(void); void GenerateVBO(void);
public:
// some addition basic funtion that permit to create or overwrite some caracterstics :
void SetTexture(const etk::UString& myTexture);
private: private:
void CalculateNormaleFace(void); void CalculateNormaleFace(void);
void CalculateNormaleEdge(void); void CalculateNormaleEdge(void);
/*
* Element modification area :
*/
public : public :
void CreateViewBox(const etk::UString& _materialName,float _size=1.0); void CreateViewBox(const etk::UString& _materialName,float _size=1.0);
private: private:
@ -129,6 +123,9 @@ namespace ewol
bool LoadEMF(const etk::UString& _fileName); bool LoadEMF(const etk::UString& _fileName);
public: public:
void AddMaterial(const etk::UString& _name, ewol::Material* _data); void AddMaterial(const etk::UString& _name, ewol::Material* _data);
public:
const etk::Vector<ewol::PhysicsShape*>& GetPhysicalProperties(void) const { return m_physics; };
}; };
}; };

View File

@ -26,7 +26,12 @@ namespace ewol
public: public:
virtual type_te GetType(void) { return ewol::PhysicsShape::box; }; virtual type_te GetType(void) { return ewol::PhysicsShape::box; };
private: private:
vec3 m_size; vec3 m_size; // Box size property in X, Y and Z
public:
const vec3& GetSize(void) const { return m_size; };
public:
virtual const PhysicsBox* ToBox(void) const { return this; };
virtual PhysicsBox* ToBox(void) { return this; };
}; };
}; };

View File

@ -27,8 +27,16 @@ namespace ewol
public: public:
virtual type_te GetType(void) { return ewol::PhysicsShape::capsule; }; virtual type_te GetType(void) { return ewol::PhysicsShape::capsule; };
private: private:
float m_radius; // props["radius"] = obj.scale.x float m_radius;
float m_height; // props["height"] = obj.scale.z public:
float GetRadius(void) const { return m_radius; };
private:
float m_height;
public:
float GetHeight(void) const { return m_height; };
public:
virtual const PhysicsCapsule* ToCapsule(void) const { return this; };
virtual PhysicsCapsule* ToCapsule(void) { return this; };
}; };
}; };

View File

@ -27,8 +27,16 @@ namespace ewol
public: public:
virtual type_te GetType(void) { return ewol::PhysicsShape::cone; }; virtual type_te GetType(void) { return ewol::PhysicsShape::cone; };
private: private:
float m_radius; // props["radius"] = obj.scale.x float m_radius;
float m_height; // props["height"] = obj.scale.z * 2.0 public:
float GetRadius(void) const { return m_radius; };
private:
float m_height;
public:
float GetHeight(void) const { return m_height; };
public:
virtual const PhysicsCone* ToCone(void) const { return this; };
virtual PhysicsCone* ToCone(void) { return this; };
}; };
}; };

View File

@ -28,6 +28,9 @@ namespace ewol
virtual type_te GetType(void) { return ewol::PhysicsShape::convexHull; }; virtual type_te GetType(void) { return ewol::PhysicsShape::convexHull; };
private: private:
vec3 m_scale; vec3 m_scale;
public:
vec3 GetScale(void) const { return m_scale; };
private:
etk::Vector<vec3> m_points; etk::Vector<vec3> m_points;
/* /*
mesh = obj.to_mesh( bpy.context.scene, True, 'PREVIEW' ) mesh = obj.to_mesh( bpy.context.scene, True, 'PREVIEW' )
@ -36,6 +39,9 @@ namespace ewol
props["points"] += "" + out_point3( v.co ) + "|" props["points"] += "" + out_point3( v.co ) + "|"
props["points"] = props["points"].rstrip("|") props["points"] = props["points"].rstrip("|")
*/ */
public:
virtual const PhysicsConvexHull* ToConvexHull(void) const { return this; };
virtual PhysicsConvexHull* ToConvexHull(void) { return this; };
}; };
}; };

View File

@ -27,7 +27,12 @@ namespace ewol
public: public:
virtual type_te GetType(void) { return ewol::PhysicsShape::cylinder; }; virtual type_te GetType(void) { return ewol::PhysicsShape::cylinder; };
private: private:
vec3 m_size; //props["half-extents"] = out_scale3( scale ) vec3 m_size;
public:
vec3 GetSize(void) const { return m_size; };
public:
virtual const PhysicsCylinder* ToCylinder(void) const { return this; };
virtual PhysicsCylinder* ToCylinder(void) { return this; };
}; };
}; };

View File

@ -51,13 +51,37 @@ namespace ewol
private: private:
vec4 m_quaternion; vec4 m_quaternion;
public: public:
vec4 GetQuaternion(void) const { return m_quaternion; };
private: private:
vec3 m_origin; vec3 m_origin;
public: public:
vec3 GetOrigin(void) const { return m_origin; };
public: public:
//virtual const PhysicsBox* ToBox(void) { return ; bool IsBox(void) { return GetType()==ewol::PhysicsShape::box; };
bool IsCylinder(void) { return GetType()==ewol::PhysicsShape::cylinder; };
bool IsCapsule(void) { return GetType()==ewol::PhysicsShape::capsule; };
bool IsCone(void) { return GetType()==ewol::PhysicsShape::cone; };
bool IsConvexHull(void) { return GetType()==ewol::PhysicsShape::convexHull; };
bool IsSphere(void) { return GetType()==ewol::PhysicsShape::sphere; };
virtual const PhysicsBox* ToBox(void) const { return NULL; };
virtual PhysicsBox* ToBox(void) { return NULL; };
virtual const PhysicsCylinder* ToCylinder(void) const { return NULL; };
virtual PhysicsCylinder* ToCylinder(void) { return NULL; };
virtual const PhysicsCapsule* ToCapsule(void) const { return NULL; };
virtual PhysicsCapsule* ToCapsule(void) { return NULL; };
virtual const PhysicsCone* ToCone(void) const { return NULL; };
virtual PhysicsCone* ToCone(void) { return NULL; };
virtual const PhysicsConvexHull* ToConvexHull(void) const { return NULL; };
virtual PhysicsConvexHull* ToConvexHull(void) { return NULL; };
virtual const PhysicsSphere* ToSphere(void) const { return NULL; };
virtual PhysicsSphere* ToSphere(void) { return NULL; };
}; };
}; };

View File

@ -28,6 +28,11 @@ namespace ewol
virtual type_te GetType(void) { return ewol::PhysicsShape::sphere; }; virtual type_te GetType(void) { return ewol::PhysicsShape::sphere; };
private: private:
float m_radius; // props["radius"] = obj.scale.x float m_radius; // props["radius"] = obj.scale.x
public:
float GetRadius(void) const { return m_radius; };
private:
virtual const PhysicsSphere* ToSphere(void) const { return this; };
virtual PhysicsSphere* ToSphere(void) { return this; };
}; };
}; };