gmostepanov Posted December 11, 2017 Share Posted December 11, 2017 (edited) Greetings! Woulde you explain the difference beetween two methods of class Mesh : addEmptySurface and addSurface? Thank you in advance. I have made some decomposition of Mesh's classification during couple of attempts to understand class's semantic clear enough. I hope it will userfull :) // buffers/vertex void setNumVertex(int size, int surface, int target = 0) = 0; int getNumVertex(int surface, int target = 0) const = 0; void addVertex(const Math::vec3 &vertex, int surface, int target = 0) = 0; void setVertex(int num, const Math::vec3 &vertex, int surface, int target = 0) = 0; Math::vec3 getVertex(int num, int surface, int target = 0) const = 0; // buffers/indices int removeIndices(int surface = -1) = 0; int createIndices(int surface = -1) = 0; int optimizeIndices(int flags, int surface = -1) = 0; void setNumIndices(int size, int surface) = 0; int getNumIndices(int surface) const = 0; void addIndex(int index, int surface) = 0; void setIndex(int num, int index, int surface) = 0; int getIndex(int num, int surface) const = 0; // buffers/CVertex,TVertex int getNumCVertex(int surface) const = 0; int getNumTVertex(int surface) const = 0; int remapCVertex(int surface) = 0; // buffers/CIndex void setNumCIndices(int size, int surface) = 0; int getNumCIndices(int surface) const = 0; void addCIndex(int index, int surface) = 0; void setCIndex(int num, int index, int surface) = 0; int getCIndex(int num, int surface) const = 0; // buffers/TIndex void setNumTIndices(int size, int surface) = 0; int getNumTIndices(int surface) const = 0; void addTIndex(int index, int surface) = 0; void setTIndex(int num, int index, int surface) = 0; int getTIndex(int num, int surface) const = 0; // buffers/tangents int createTangents(int surface = -1, int target = -1) = 0; int createTangents(float angle, const Vector< int > &surfaces) = 0; void setNumTangents(int size, int surface, int target = 0) = 0; int getNumTangents(int surface, int tangent = 0) const = 0; void addTangent(const Math::quat &tangent, int surface, int target = 0) = 0; void setTangent(int num, const Math::quat &tangent, int surface, int target = 0) = 0; Math::quat getTangent(int num, int surface, int target = 0) const = 0; // buffers/normals int createNormals(int surface = -1, int target = -1) = 0; int createNormals(float angle, int surface = -1, int target = -1) = 0; void setNumNormals(int size, int surface, int target = 0) = 0; int getNumNormals(int surface, int target = 0) const = 0; void addNormal(const Math::vec3 &normal, int surface, int target = 0) = 0; void setNormal(int num, const Math::vec3 &normal, int surface, int target = 0) = 0; Math::vec3 getNormal(int num, int surface, int target = 0) const = 0; // buffers/textCoords void setNumTexCoords0(int size, int surface) = 0; int getNumTexCoords0(int surface) const = 0; void addTexCoord0(const Math::vec2 &texcoord, int surface) = 0; void setTexCoord0(int num, const Math::vec2 &texcoord, int surface) = 0; Math::vec2 getTexCoord0(int num, int surface) const = 0; void setNumTexCoords1(int size, int surface) = 0; int getNumTexCoords1(int surface) const = 0; void addTexCoord1(const Math::vec2 &texcoord, int surface) = 0; void setTexCoord1(int num, const Math::vec2 &texcoord, int surface) = 0; Math::vec2 getTexCoord1(int num, int surface) const = 0; // buffers/colors void setNumColors(int size, int surface) = 0; int getNumColors(int surface) const = 0; void addColor(const Math::vec4 &color, int surface) = 0; void setColor(int num, const Math::vec4 &color, int surface) = 0; Math::vec4 getColor(int num, int surface) const = 0; // surfaces int getNumSurfaces() const = 0; int findSurface(const char *name) const = 0; void sortSurfaces() = 0; int addSurface(const char *name = 0) = 0; void setSurfaceName(int surface, const char *name) = 0; const char *getSurfaceName(int surface) const = 0; void setNumSurfaceTargets(int surface, int num) = 0; int getNumSurfaceTargets(int surface) const = 0; void setSurfaceTargetName(int surface, int target, const char *name) = 0; const char *getSurfaceTargetName(int surface, int target) const = 0; int findSurfaceTarget(int surface, const char *name) const = 0; int setSurfaceTransform(const Math::mat4 &transform, int surface = -1, int target = -1) = 0; int addMeshSurface(const char *v, const Ptr<Mesh> &mesh, int surface, int target = -1) = 0; int addMeshSurface(int v, const Ptr<Mesh> &mesh, int surface, int target = -1) = 0; int addEmptySurface(const char *name, int num_vertex, int num_indices) = 0; int addSurfaceTarget(int surface, const char *name = 0) = 0; // primitives int addBoxSurface(const char *name, const Math::vec3 &size) = 0; int addPlaneSurface(const char *name, float width, float height, float step) = 0; int addSphereSurface(const char *name, float radius, int stacks, int slices) = 0; int addCapsuleSurface(const char *name, float radius, float height, int stacks, int slices) = 0; int addCylinderSurface(const char *name, float radius, float height, int stacks, int slices) = 0; int addPrismSurface(const char *name, float size_0, float size_1, float height, int sides) = 0; int addIcosahedronSurface(const char *name, float radius) = 0; int addDodecahedronSurface(const char *name, float radius) = 0; // weights void setNumWeights(int size, int surface) = 0; int getNumWeights(int surface) const = 0; void setWeightCount(int num, int count, int surface) = 0; int getWeightCount(int num, int surface) const = 0; void setWeightBones(int num, const Math::ivec4 &bones, int surface) = 0; Math::ivec4 getWeightBones(int num, int surface) const = 0; void setWeightWeights(int num, const Math::vec4 &weights, int surface) = 0; Math::vec4 getWeightWeights(int num, int surface) const = 0; // bounds int createBounds(int surface = -1) = 0; BoundBox getBoundBox(int surface) const = 0; BoundSphere getBoundSphere(int surface) const = 0; void setBoundBox(const BoundBox & bb, int surface) = 0; void setBoundSphere(const BoundSphere & bs, int surface) = 0; // intersections int createIntersection(int surface = -1) = 0; int getIntersection(const Math::vec3 &p0, const Math::vec3 &p1, Math::vec3 * ret_point, Math::vec3 * ret_normal, int * ret_index, int surface, int target = 0) const = 0; // utils int flipYZ(int surface = -1) = 0; int flipTangent(int surface = -1) = 0; Edited December 11, 2017 by gmostepanov Link to comment
gmostepanov Posted December 11, 2017 Author Share Posted December 11, 2017 And one more question: methods of class ObjectMeshDynamic are very similar but not exactly the same. What's the reason? Link to comment
fox Posted December 11, 2017 Share Posted December 11, 2017 Hello gmostepanov, 1) The addSurface() and addEmptySurface() methods are almost the same. The only difference is that the second one additionally allocates memory for vertex and index arrays, so it is to be called when you know the numbers of vertices and indices for your surface. 2) The reason that ObjectMeshStatic and ObjectMeshDynamic are not the same is because they actually have different implementation due their specific features. They have some methods with similar names, but that’s the only thing they have in common. Thanks! Link to comment
gmostepanov Posted December 12, 2017 Author Share Posted December 12, 2017 (edited) On 11.12.2017 at 4:16 PM, fox said: 2) The reason that ObjectMeshStatic and ObjectMeshDynamic are not the same is because they actually have different implementation due their specific features. They have some methods with similar names, but that’s the only thing they have in common. This is obvious! Yes, they are different cause they do different things. With little success, when I had started to analize the interface of classes Mesh and ObjectMeshDynamic, the understanding of how to deal with they, was appeared. And now I am not looking for precise specifications, but I offer to point to complexety of API. If only you have somthing like wishlist, I would append a suggestion to redesign API with 1) simplification 2) new modern cool с++ features Edited January 17, 2018 by gmostepanov Link to comment
gmostepanov Posted December 12, 2017 Author Share Posted December 12, 2017 What's the difference between void ObjectMeshDynamic::allocateVertex(int num) and void ObjectMeshDynamic::setNumVertex(int num) ? Link to comment
fox Posted December 12, 2017 Share Posted December 12, 2017 The allocateVertex() method allocates memory, but does not change the size of the vector, that stores vertices. So when you use this method, your code when adding vertices should look like this: // allocating memory dynamic_mesh->allocateVertex(5); // adding vertices dynamic_mesh->addVertex(vec3(0.0f)); dynamic_mesh->addVertex(vec3(1.0f)); dynamic_mesh->addVertex(vec3(2.0f)); dynamic_mesh->addVertex(vec3(3.0f)); dynamic_mesh->addVertex(vec3(4.0f)); The setNumVertex() changes the size of the vector, so the same code should look as follows: // allocating memory dynamic_mesh->setNumVertex(5); // adding vertices dynamic_mesh->setVertex(0, vec3(0.0f)); dynamic_mesh->setVertex(1, vec3(1.0f)); dynamic_mesh->setVertex(2, vec3(2.0f)); dynamic_mesh->setVertex(3, vec3(3.0f)); dynamic_mesh->setVertex(4, vec3(4.0f)); Thanks! Link to comment
Recommended Posts