BearishSun 9 роки тому
батько
коміт
61a7c5ef2d

+ 38 - 6
Source/BansheeCore/Include/BsMesh.h

@@ -216,7 +216,19 @@ namespace BansheeEngine
 		 *								vertex descriptor and index type properties are ignored and are read from provided
 		 *								vertex descriptor and index type properties are ignored and are read from provided
 		 *								mesh data instead.
 		 *								mesh data instead.
 		 */
 		 */
-		static HMesh create(const SPtr<MeshData>& initialData, const MESH_DESC& desc = MESH_DESC::DEFAULT);
+		static HMesh create(const SPtr<MeshData>& initialData, const MESH_DESC& desc);
+
+		/**
+		 * Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described
+		 * by the mesh data exactly. Mesh will have no sub-meshes.
+		 *
+		 * @param[in]	initialData		Vertex and index data to initialize the mesh with.
+		 * @param[in]	usage			Optimizes performance depending on planned usage of the mesh.
+		 * @param[in]	drawOp			Determines how should the provided indices be interpreted by the pipeline. Default 
+		 *								option is a triangle strip, where three indices represent a single triangle.
+		 */
+		static HMesh create(const SPtr<MeshData>& initialData, int usage = MU_STATIC, 
+			DrawOperationType drawOp = DOT_TRIANGLE_LIST);
 
 
 		/** @name Internal
 		/** @name Internal
 		 *  @{
 		 *  @{
@@ -230,11 +242,19 @@ namespace BansheeEngine
 		static SPtr<Mesh> _createPtr(const MESH_DESC& desc);
 		static SPtr<Mesh> _createPtr(const MESH_DESC& desc);
 
 
 		/**
 		/**
-		 * @copydoc	create(const SPtr<MeshData>&, int, DrawOperationType, const SPtr<Skeleton>&)
+		 * @copydoc	create(const SPtr<MeshData>&, const MESH_DESC&)
+		 *
+		 * @note	Internal method. Use create() for normal use.
+		 */
+		static SPtr<Mesh> _createPtr(const SPtr<MeshData>& initialData, const MESH_DESC& desc);
+
+		/**
+		 * @copydoc	create(const SPtr<MeshData>&, int, DrawOperationType)
 		 *
 		 *
 		 * @note	Internal method. Use create() for normal use.
 		 * @note	Internal method. Use create() for normal use.
 		 */
 		 */
-		static SPtr<Mesh> _createPtr(const SPtr<MeshData>& initialData, const MESH_DESC& desc = MESH_DESC::DEFAULT);
+		static SPtr<Mesh> _createPtr(const SPtr<MeshData>& initialData, int usage = MU_STATIC,
+			DrawOperationType drawOp = DOT_TRIANGLE_LIST);
 
 
 		/**
 		/**
 		 * Creates a new empty and uninitialized mesh. You will need to manually initialize the mesh before using it.
 		 * Creates a new empty and uninitialized mesh. You will need to manually initialize the mesh before using it.
@@ -294,7 +314,7 @@ namespace BansheeEngine
 		virtual void writeSubresource(UINT32 subresourceIdx, const MeshData& data, bool discardEntireBuffer, bool updateBounds = true);
 		virtual void writeSubresource(UINT32 subresourceIdx, const MeshData& data, bool discardEntireBuffer, bool updateBounds = true);
 
 
 		/**
 		/**
-		 * Reads a part of the current resource into the provided @p data parameter.	Data buffer needs to be pre-allocated.
+		 * Reads a part of the current resource into the provided @p data parameter. Data buffer needs to be pre-allocated.
 		 *
 		 *
 		 * @param[in]	subresourceIdx		Index of the subresource to update, if the mesh has more than one.
 		 * @param[in]	subresourceIdx		Index of the subresource to update, if the mesh has more than one.
 		 * @param[out]	data				Buffer that will receive the data. Should be allocated with 
 		 * @param[out]	data				Buffer that will receive the data. Should be allocated with 
@@ -329,14 +349,26 @@ namespace BansheeEngine
 
 
 		/**
 		/**
 		 * Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described
 		 * Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described
-		 * by the mesh data exactly. Mesh will have no sub-meshes.
+		 * by the mesh data exactly. 
 		 *
 		 *
 		 * @param[in]	initialData		Vertex and index data to initialize the mesh with.
 		 * @param[in]	initialData		Vertex and index data to initialize the mesh with.
 		 * @param[in]	desc			Descriptor containing the properties of the mesh to create. Vertex and index count,
 		 * @param[in]	desc			Descriptor containing the properties of the mesh to create. Vertex and index count,
 		 *								vertex descriptor and index type properties are ignored and are read from provided
 		 *								vertex descriptor and index type properties are ignored and are read from provided
 		 *								mesh data instead.
 		 *								mesh data instead.
 		 */
 		 */
-		static SPtr<MeshCore> create(const SPtr<MeshData>& initialData, const MESH_DESC& desc = MESH_DESC::DEFAULT);
+		static SPtr<MeshCore> create(const SPtr<MeshData>& initialData, const MESH_DESC& desc);
+
+		/**
+		 * Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described
+		 * by the mesh data exactly. Mesh will have no sub-meshes.
+		 *
+		 * @param[in]	initialData		Vertex and index data to initialize the mesh with.
+		 * @param[in]	usage			Optimizes performance depending on planned usage of the mesh.
+		 * @param[in]	drawOp			Determines how should the provided indices be interpreted by the pipeline. Default 
+		 *								option is a triangle strip, where three indices represent a single triangle.
+		 */
+		static SPtr<MeshCore> create(const SPtr<MeshData>& initialData, int usage = MU_STATIC,
+			DrawOperationType drawOp = DOT_TRIANGLE_LIST);
 
 
 	protected:
 	protected:
 		friend class Mesh;
 		friend class Mesh;

+ 37 - 0
Source/BansheeCore/Source/BsMesh.cpp

@@ -341,6 +341,24 @@ namespace BansheeEngine
 		return mesh;
 		return mesh;
 	}
 	}
 
 
+	SPtr<MeshCore> MeshCore::create(const SPtr<MeshData>& initialMeshData, int usage, DrawOperationType drawOp)
+	{
+		MESH_DESC desc;
+		desc.numVertices = initialMeshData->getNumVertices();
+		desc.numIndices = initialMeshData->getNumIndices();
+		desc.vertexDesc = initialMeshData->getVertexDesc();
+		desc.indexType = initialMeshData->getIndexType();
+		desc.subMeshes.push_back(SubMesh(0, initialMeshData->getNumIndices(), drawOp));
+		desc.usage = usage;
+
+		SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(initialMeshData, desc));
+
+		mesh->_setThisPtr(mesh);
+		mesh->initialize();
+
+		return mesh;
+	}
+
 	Mesh::Mesh(const MESH_DESC& desc)
 	Mesh::Mesh(const MESH_DESC& desc)
 		:MeshBase(desc.numVertices, desc.numIndices, desc.subMeshes), mVertexDesc(desc.vertexDesc), mUsage(desc.usage),
 		:MeshBase(desc.numVertices, desc.numIndices, desc.subMeshes), mVertexDesc(desc.vertexDesc), mUsage(desc.usage),
 		mIndexType(desc.indexType), mSkeleton(desc.skeleton), mMorphShapes(desc.morphShapes)
 		mIndexType(desc.indexType), mSkeleton(desc.skeleton), mMorphShapes(desc.morphShapes)
@@ -567,6 +585,12 @@ namespace BansheeEngine
 		return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
 		return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
 	}
 	}
 
 
+	HMesh Mesh::create(const SPtr<MeshData>& initialMeshData, int usage, DrawOperationType drawOp)
+	{
+		SPtr<Mesh> meshPtr = _createPtr(initialMeshData, usage, drawOp);
+		return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
+	}
+
 	SPtr<Mesh> Mesh::_createPtr(const MESH_DESC& desc)
 	SPtr<Mesh> Mesh::_createPtr(const MESH_DESC& desc)
 	{
 	{
 		SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh(desc));
 		SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh(desc));
@@ -585,6 +609,19 @@ namespace BansheeEngine
 		return mesh;
 		return mesh;
 	}
 	}
 
 
+	SPtr<Mesh> Mesh::_createPtr(const SPtr<MeshData>& initialMeshData, int usage, DrawOperationType drawOp)
+	{
+		MESH_DESC desc;
+		desc.usage = usage;
+		desc.subMeshes.push_back(SubMesh(0, initialMeshData->getNumIndices(), drawOp));
+
+		SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh(initialMeshData, desc));
+		mesh->_setThisPtr(mesh);
+		mesh->initialize();
+
+		return mesh;
+	}
+
 	SPtr<Mesh> Mesh::createEmpty()
 	SPtr<Mesh> Mesh::createEmpty()
 	{
 	{
 		SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh());
 		SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh());