Add support for masking Material Slots when cooking Collision Data
This commit is contained in:
@@ -133,20 +133,22 @@ namespace
|
||||
|
||||
bool Mesh::UpdateMesh(uint32 vertexCount, uint32 triangleCount, VB0ElementType* vb0, VB1ElementType* vb1, VB2ElementType* vb2, void* ib, bool use16BitIndices)
|
||||
{
|
||||
auto model = (Model*)_model;
|
||||
|
||||
Unload();
|
||||
|
||||
// Setup GPU resources
|
||||
_model->LODs[_lodIndex]._verticesCount -= _vertices;
|
||||
model->LODs[_lodIndex]._verticesCount -= _vertices;
|
||||
const bool failed = Load(vertexCount, triangleCount, vb0, vb1, vb2, ib, use16BitIndices);
|
||||
if (!failed)
|
||||
{
|
||||
_model->LODs[_lodIndex]._verticesCount += _vertices;
|
||||
model->LODs[_lodIndex]._verticesCount += _vertices;
|
||||
|
||||
// Calculate mesh bounds
|
||||
SetBounds(BoundingBox::FromPoints((Vector3*)vb0, vertexCount));
|
||||
|
||||
// Send event (actors using this model can update bounds, etc.)
|
||||
_model->onLoaded();
|
||||
model->onLoaded();
|
||||
}
|
||||
|
||||
return failed;
|
||||
@@ -214,17 +216,6 @@ Mesh::~Mesh()
|
||||
SAFE_DELETE_GPU_RESOURCE(_indexBuffer);
|
||||
}
|
||||
|
||||
void Mesh::SetMaterialSlotIndex(int32 value)
|
||||
{
|
||||
if (value < 0 || value >= _model->MaterialSlots.Count())
|
||||
{
|
||||
LOG(Warning, "Cannot set mesh material slot to {0} while model has {1} slots.", value, _model->MaterialSlots.Count());
|
||||
return;
|
||||
}
|
||||
|
||||
_materialSlotIndex = value;
|
||||
}
|
||||
|
||||
bool Mesh::Load(uint32 vertices, uint32 triangles, void* vb0, void* vb1, void* vb2, void* ib, bool use16BitIndexBuffer)
|
||||
{
|
||||
// Cache data
|
||||
@@ -443,7 +434,7 @@ void Mesh::Draw(const RenderContext& renderContext, const DrawInfo& info, float
|
||||
// TODO: cache vertexOffset within the model LOD per-mesh
|
||||
uint32 vertexOffset = 0;
|
||||
for (int32 meshIndex = 0; meshIndex < _index; meshIndex++)
|
||||
vertexOffset += _model->LODs[_lodIndex].Meshes[meshIndex].GetVertexCount();
|
||||
vertexOffset += ((Model*)_model)->LODs[_lodIndex].Meshes[meshIndex].GetVertexCount();
|
||||
drawCall.Geometry.VertexBuffers[2] = info.VertexColors[_lodIndex];
|
||||
drawCall.Geometry.VertexBuffersOffsets[2] = vertexOffset * sizeof(VB2ElementType);
|
||||
}
|
||||
|
||||
@@ -22,10 +22,8 @@ API_CLASS(NoSpawn) class FLAXENGINE_API Mesh : public MeshBase
|
||||
DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(Mesh, MeshBase);
|
||||
protected:
|
||||
|
||||
Model* _model;
|
||||
int32 _index;
|
||||
int32 _lodIndex;
|
||||
int32 _materialSlotIndex;
|
||||
bool _hasLightmapUVs;
|
||||
GPUBuffer* _vertexBuffers[3];
|
||||
GPUBuffer* _indexBuffer;
|
||||
@@ -55,7 +53,7 @@ public:
|
||||
/// </summary>
|
||||
FORCE_INLINE Model* GetModel() const
|
||||
{
|
||||
return _model;
|
||||
return (Model*)_model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,19 +72,6 @@ public:
|
||||
return _index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the material slot to use during this mesh rendering.
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE int32 GetMaterialSlotIndex() const
|
||||
{
|
||||
return _materialSlotIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the index of the material slot to use during this mesh rendering.
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetMaterialSlotIndex(int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index buffer.
|
||||
/// </summary>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Engine/Scripting/ScriptingObject.h"
|
||||
|
||||
class Task;
|
||||
class ModelBase;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for model resources meshes.
|
||||
@@ -18,11 +19,13 @@ API_CLASS(Abstract, NoSpawn) class FLAXENGINE_API MeshBase : public PersistentSc
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(MeshBase);
|
||||
protected:
|
||||
|
||||
ModelBase* _model;
|
||||
bool _use16BitIndexBuffer;
|
||||
BoundingBox _box;
|
||||
BoundingSphere _sphere;
|
||||
uint32 _vertices;
|
||||
uint32 _triangles;
|
||||
int32 _materialSlotIndex;
|
||||
|
||||
explicit MeshBase(const SpawnParams& params)
|
||||
: PersistentScriptingObject(params)
|
||||
@@ -31,6 +34,14 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Gets the model owning this mesh.
|
||||
/// </summary>
|
||||
FORCE_INLINE ModelBase* GetModelBase() const
|
||||
{
|
||||
return _model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the triangle count.
|
||||
/// </summary>
|
||||
@@ -76,6 +87,19 @@ public:
|
||||
return _use16BitIndexBuffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the material slot to use during this mesh rendering.
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE int32 GetMaterialSlotIndex() const
|
||||
{
|
||||
return _materialSlotIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the index of the material slot to use during this mesh rendering.
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetMaterialSlotIndex(int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the mesh bounds.
|
||||
/// </summary>
|
||||
|
||||
@@ -34,17 +34,6 @@ SkinnedMesh::~SkinnedMesh()
|
||||
SAFE_DELETE_GPU_RESOURCE(_indexBuffer);
|
||||
}
|
||||
|
||||
void SkinnedMesh::SetMaterialSlotIndex(int32 value)
|
||||
{
|
||||
if (value < 0 || value >= _model->MaterialSlots.Count())
|
||||
{
|
||||
LOG(Warning, "Cannot set mesh material slot to {0} while model has {1} slots.", value, _model->MaterialSlots.Count());
|
||||
return;
|
||||
}
|
||||
|
||||
_materialSlotIndex = value;
|
||||
}
|
||||
|
||||
bool SkinnedMesh::Load(uint32 vertices, uint32 triangles, void* vb0, void* ib, bool use16BitIndexBuffer)
|
||||
{
|
||||
// Cache data
|
||||
@@ -101,6 +90,8 @@ void SkinnedMesh::Unload()
|
||||
|
||||
bool SkinnedMesh::UpdateMesh(uint32 vertexCount, uint32 triangleCount, VB0SkinnedElementType* vb, void* ib, bool use16BitIndices)
|
||||
{
|
||||
auto model = (SkinnedModel*)_model;
|
||||
|
||||
// Setup GPU resources
|
||||
const bool failed = Load(vertexCount, triangleCount, vb, ib, use16BitIndices);
|
||||
if (!failed)
|
||||
@@ -109,7 +100,7 @@ bool SkinnedMesh::UpdateMesh(uint32 vertexCount, uint32 triangleCount, VB0Skinne
|
||||
SetBounds(BoundingBox::FromPoints((Vector3*)vb, vertexCount));
|
||||
|
||||
// Send event (actors using this model can update bounds, etc.)
|
||||
_model->onLoaded();
|
||||
model->onLoaded();
|
||||
}
|
||||
|
||||
return failed;
|
||||
|
||||
@@ -19,10 +19,8 @@ API_CLASS(NoSpawn) class FLAXENGINE_API SkinnedMesh : public MeshBase
|
||||
DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(SkinnedMesh, MeshBase);
|
||||
protected:
|
||||
|
||||
SkinnedModel* _model;
|
||||
int32 _index;
|
||||
int32 _lodIndex;
|
||||
int32 _materialSlotIndex;
|
||||
GPUBuffer* _vertexBuffer;
|
||||
GPUBuffer* _indexBuffer;
|
||||
mutable Array<byte> _cachedIndexBuffer;
|
||||
@@ -33,7 +31,7 @@ public:
|
||||
SkinnedMesh(const SkinnedMesh& other)
|
||||
: SkinnedMesh()
|
||||
{
|
||||
#if !!BUILD_RELEASE
|
||||
#if !BUILD_RELEASE
|
||||
CRASH; // Not used
|
||||
#endif
|
||||
}
|
||||
@@ -51,7 +49,7 @@ public:
|
||||
/// <returns>The skinned model</returns>
|
||||
FORCE_INLINE SkinnedModel* GetSkinnedModel() const
|
||||
{
|
||||
return _model;
|
||||
return (SkinnedModel*)_model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,21 +61,6 @@ public:
|
||||
return _index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the material slot index.
|
||||
/// </summary>
|
||||
/// <returns>The material slot index</returns>
|
||||
API_PROPERTY() FORCE_INLINE int32 GetMaterialSlotIndex() const
|
||||
{
|
||||
return _materialSlotIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the index of the material slot index.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
API_PROPERTY() void SetMaterialSlotIndex(int32 value);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this mesh is initialized (has vertex and index buffers initialized).
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user