Merge remote-tracking branch 'origin/master' into 1.10
# Conflicts: # Source/Editor/SceneGraph/Actors/StaticModelNode.cs # Source/Engine/Graphics/Models/Mesh.cs # Source/Engine/Graphics/Models/ModelData.h
This commit is contained in:
@@ -24,6 +24,9 @@ namespace FlaxEditor.SceneGraph.Actors
|
||||
public sealed class StaticModelNode : ActorNode
|
||||
{
|
||||
private Dictionary<IntPtr, Float3[]> _vertices;
|
||||
private Vector3[] _selectionPoints;
|
||||
private Transform _selectionPointsTransform;
|
||||
private Model _selectionPointsModel;
|
||||
|
||||
/// <inheritdoc />
|
||||
public StaticModelNode(Actor actor)
|
||||
@@ -31,6 +34,16 @@ namespace FlaxEditor.SceneGraph.Actors
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnDispose()
|
||||
{
|
||||
_vertices = null;
|
||||
_selectionPoints = null;
|
||||
_selectionPointsModel = null;
|
||||
|
||||
base.OnDispose();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool OnVertexSnap(ref Ray ray, Real hitDistance, out Vector3 result)
|
||||
{
|
||||
@@ -91,6 +104,45 @@ namespace FlaxEditor.SceneGraph.Actors
|
||||
contextMenu.AddButton("Add collider", () => OnAddMeshCollider(window)).Enabled = ((StaticModel)Actor).Model != null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Vector3[] GetActorSelectionPoints()
|
||||
{
|
||||
if (Actor is StaticModel sm && sm.Model)
|
||||
{
|
||||
// Try to use cache
|
||||
var model = sm.Model;
|
||||
var transform = Actor.Transform;
|
||||
if (_selectionPoints != null &&
|
||||
_selectionPointsTransform == transform &&
|
||||
_selectionPointsModel == model)
|
||||
return _selectionPoints;
|
||||
Profiler.BeginEvent("GetActorSelectionPoints");
|
||||
|
||||
// Check collision proxy points for more accurate selection
|
||||
var vecPoints = new List<Vector3>();
|
||||
var m = model.LODs[0];
|
||||
foreach (var mesh in m.Meshes)
|
||||
{
|
||||
var points = mesh.GetCollisionProxyPoints();
|
||||
vecPoints.EnsureCapacity(vecPoints.Count + points.Length);
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
vecPoints.Add(transform.LocalToWorld(points[i]));
|
||||
}
|
||||
}
|
||||
|
||||
Profiler.EndEvent();
|
||||
if (vecPoints.Count != 0)
|
||||
{
|
||||
_selectionPoints = vecPoints.ToArray();
|
||||
_selectionPointsTransform = transform;
|
||||
_selectionPointsModel = model;
|
||||
return _selectionPoints;
|
||||
}
|
||||
}
|
||||
return base.GetActorSelectionPoints();
|
||||
}
|
||||
|
||||
private void OnAddMeshCollider(EditorWindow window)
|
||||
{
|
||||
// Allow collider to be added to evey static model selection
|
||||
|
||||
Reference in New Issue
Block a user