Skip to content
Permalink
Browse files

Merge branch 'master-3.0'

  • Loading branch information
xen2 committed Feb 5, 2019
2 parents 0dcbaaf + f54e706 commit 2592f84d7b074da875cf0e2350f1a8d592c9d9bd
@@ -9,16 +9,20 @@
using System.ComponentModel;
using System.Linq;
using Xenko.Core.Annotations;
using Xenko.Core.Yaml;
using Xenko.Core.Yaml.Serialization;

namespace Xenko.Assets.Physics
{
[DataContract("ColliderShapeAsset")]
[AssetDescription(FileExtension)]
[AssetContentType(typeof(PhysicsColliderShape))]
[AssetUpgrader(XenkoConfig.PackageName, "2.0.0.0", "3.0.0.0", typeof(ConvexHullDecompositionParametersUpgrader))]
[AssetFormatVersion(XenkoConfig.PackageName, CurrentVersion, "2.0.0.0")]
[AssetUpgrader(XenkoConfig.PackageName, "2.0.0.0", "3.0.0.0", typeof(ConvexHullGeneratorUpgrader))]
public partial class ColliderShapeAsset : Asset
{
private const string CurrentVersion = "2.0.0.0";
private const string CurrentVersion = "3.0.0.0";

public const string FileExtension = ".xkphy;pdxphy";

@@ -29,5 +33,62 @@ public partial class ColliderShapeAsset : Asset
[Category]
[MemberCollection(CanReorderItems = true, NotNullItems = true)]
public List<IAssetColliderShapeDesc> ColliderShapes { get; } = new List<IAssetColliderShapeDesc>();

private class ConvexHullDecompositionParametersUpgrader : AssetUpgraderBase
{
protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
{
foreach (dynamic item in asset.ColliderShapes)
{
dynamic shape = item.Value;
if (shape.Node.Tag == "!ConvexHullColliderShapeDesc")
{
dynamic decomposition = shape.Decomposition = new DynamicYamlMapping(new YamlMappingNode());

if (shape.ContainsChild("SimpleWrap"))
{
decomposition.Enabled = shape.SimpleWrap.ToString().ToLowerInvariant().Equals("false");
}
if (shape.ContainsChild("Depth"))
{
decomposition.Depth = shape.Depth;
}
if (shape.ContainsChild("PosSampling"))
{
decomposition.PosSampling = shape.PosSampling;
}
if (shape.ContainsChild("AngleSampling"))
{
decomposition.AngleSampling = shape.AngleSampling;
}
if (shape.ContainsChild("PosRefine"))
{
decomposition.PosRefine = shape.PosRefine;
}
if (shape.ContainsChild("AngleRefine"))
{
decomposition.AngleRefine = shape.AngleRefine;
}
if (shape.ContainsChild("Alpha"))
{
decomposition.Alpha = shape.Alpha;
}
if (shape.ContainsChild("Threshold"))
{
decomposition.Threshold = shape.Threshold;
}

shape.RemoveChild("SimpleWrap");
shape.RemoveChild("Depth");
shape.RemoveChild("PosSampling");
shape.RemoveChild("AngleSampling");
shape.RemoveChild("PosRefine");
shape.RemoveChild("AngleRefine");
shape.RemoveChild("Alpha");
shape.RemoveChild("Threshold");
}
}
}
}
}
}
@@ -109,13 +109,7 @@ protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandC
Scaling = convexHullDesc.Scaling,
LocalOffset = convexHullDesc.LocalOffset,
LocalRotation = convexHullDesc.LocalRotation,
Depth = convexHullDesc.Depth,
PosSampling = convexHullDesc.PosSampling,
AngleSampling = convexHullDesc.AngleSampling,
PosRefine = convexHullDesc.PosRefine,
AngleRefine = convexHullDesc.AngleRefine,
Alpha = convexHullDesc.Alpha,
Threshold = convexHullDesc.Threshold,
Decomposition = convexHullDesc.Decomposition,
};

// Replace shape in final result with cloned description
@@ -270,14 +264,14 @@ protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandC
IndicesCount = (uint)combinedIndices.Count,
Vertexes = combinedVerts.ToArray(),
Indices = combinedIndices.ToArray(),
Depth = convexHullDesc.Depth,
PosSampling = convexHullDesc.PosSampling,
PosRefine = convexHullDesc.PosRefine,
AngleSampling = convexHullDesc.AngleSampling,
AngleRefine = convexHullDesc.AngleRefine,
Alpha = convexHullDesc.Alpha,
Threshold = convexHullDesc.Threshold,
SimpleHull = convexHullDesc.SimpleWrap
Depth = convexHullDesc.Decomposition.Depth,
PosSampling = convexHullDesc.Decomposition.PosSampling,
PosRefine = convexHullDesc.Decomposition.PosRefine,
AngleSampling = convexHullDesc.Decomposition.AngleSampling,
AngleRefine = convexHullDesc.Decomposition.AngleRefine,
Alpha = convexHullDesc.Decomposition.Alpha,
Threshold = convexHullDesc.Decomposition.Threshold,
SimpleHull = !convexHullDesc.Decomposition.Enabled,
};

var convexHullMesh = new ConvexHullMesh();
@@ -22,6 +22,8 @@ public partial class XenkoPackageUpgrader
private static string RemoveSiliconStudioNamespaces(string content)
{
// Namespaces
content = content.Replace("SiliconStudio.Xenko.Rendering.Composers", "SiliconStudio.Xenko.Rendering.Compositing");
content = content.Replace("SiliconStudio.Core.Serialization.Assets", "SiliconStudio.Core.Serialization.Contents");
content = content.Replace("SiliconStudio.Core", "Xenko.Core");
content = content.Replace("SiliconStudio.Xenko", "Xenko");
content = content.Replace("SiliconStudio.Common", "Xenko.Common");
@@ -0,0 +1,81 @@
// Copyright (c) Xenko contributors (https://xenko.com)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using System;
using Xenko.Core;
using Xenko.Core.Serialization.Contents;

namespace Xenko.Physics
{
[ContentSerializer(typeof(DataContentSerializer<ConvexHullDecompositionParameters>))]
[DataContract("DecompositionParameters")]
[Display("DecompositionParameters")]
public class ConvexHullDecompositionParameters
{
/// <userdoc>
/// If this is unchecked the following parameters are totally ignored, as only a simple convex hull of the whole model will be generated.
/// </userdoc>
public bool Enabled { get; set; }

/// <userdoc>
/// Control how many sub convex hulls will be created, more depth will result in a more complex decomposition.
/// </userdoc>
[DataMember(60)]
public int Depth { get; set; } = 10;

/// <userdoc>
/// How many position samples to internally compute clipping planes ( the higher the more complex ).
/// </userdoc>
[DataMember(70)]
public int PosSampling { get; set; } = 10;

/// <userdoc>
/// How many angle samples to internally compute clipping planes ( the higher the more complex ), nested with position samples, for each position sample it will compute the amount defined here.
/// </userdoc>
[DataMember(80)]
public int AngleSampling { get; set; } = 10;

/// <userdoc>
/// If higher then 0 the computation will try to further improve the shape position sampling (this will slow down the process).
/// </userdoc>
[DataMember(90)]
public int PosRefine { get; set; } = 5;

/// <userdoc>
/// If higher then 0 the computation will try to further improve the shape angle sampling (this will slow down the process).
/// </userdoc>
[DataMember(100)]
public int AngleRefine { get; set; } = 5;

/// <userdoc>
/// Applied to the concavity during crippling plane approximation.
/// </userdoc>
[DataMember(110)]
public float Alpha { get; set; } = 0.01f;

/// <userdoc>
/// Threshold of concavity, rising this will make the shape simpler.
/// </userdoc>
[DataMember(120)]
public float Threshold { get; set; } = 0.01f;

public bool Match(object obj)
{
var other = obj as ConvexHullDecompositionParameters;

if (other == null)
{
return false;
}

return other.Enabled == Enabled &&
other.Depth == Depth &&
other.PosSampling == PosSampling &&
other.AngleSampling == AngleSampling &&
other.PosRefine == PosRefine &&
other.AngleRefine == AngleRefine &&
Math.Abs(other.Alpha - Alpha) < float.Epsilon &&
Math.Abs(other.Threshold - Threshold) < float.Epsilon;
}
}
}
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Xenko.Core;
using Xenko.Core.Annotations;
using Xenko.Core.Mathematics;
using Xenko.Core.Serialization.Contents;
using Xenko.Rendering;
@@ -42,67 +43,18 @@ public class ConvexHullColliderShapeDesc : IAssetColliderShapeDesc
[DataMember(32)]
public Quaternion LocalRotation = Quaternion.Identity;

/// <userdoc>
/// If this is checked the following parameters are totally ignored, as only a simple convex hull of the whole model will be generated.
/// </userdoc>
[DataMember(40)]
[Display(Browsable = false)]
public bool SimpleWrap = true;

/// <userdoc>
/// The scaling of the generated convex hull.
/// </userdoc>
[DataMember(45)]
public Vector3 Scaling = Vector3.One;

/// <userdoc>
/// Control how many sub convex hulls will be created, more depth will result in a more complex decomposition.
/// If this is checked the following parameters are totally ignored, as only a simple convex hull of the whole model will be generated.
/// </userdoc>
[DataMember(50)]
[Display(Browsable = false)]
public int Depth = 10;

/// <userdoc>
/// How many position samples to internally compute clipping planes ( the higher the more complex ).
/// </userdoc>
[DataMember(60)]
[Display(Browsable = false)]
public int PosSampling = 10;

/// <userdoc>
/// How many angle samples to internally compute clipping planes ( the higher the more complex ), nested with position samples, for each position sample it will compute the amount defined here.
/// </userdoc>
[DataMember(70)]
[Display(Browsable = false)]
public int AngleSampling = 10;

/// <userdoc>
/// If higher then 0 the computation will try to further improve the shape position sampling (this will slow down the process).
/// </userdoc>
[DataMember(80)]
[Display(Browsable = false)]
public int PosRefine = 5;

/// <userdoc>
/// If higher then 0 the computation will try to further improve the shape angle sampling (this will slow down the process).
/// </userdoc>
[DataMember(90)]
[Display(Browsable = false)]
public int AngleRefine = 5;

/// <userdoc>
/// Applied to the concavity during crippling plane approximation.
/// </userdoc>
[DataMember(100)]
[Display(Browsable = false)]
public float Alpha = 0.01f;

/// <userdoc>
/// Threshold of concavity, rising this will make the shape simpler.
/// </userdoc>
[DataMember(110)]
[Display(Browsable = false)]
public float Threshold = 0.01f;
[NotNull]
public ConvexHullDecompositionParameters Decomposition { get; set; } = new ConvexHullDecompositionParameters();

public bool Match(object obj)
{
@@ -114,15 +66,8 @@ public bool Match(object obj)
return false;

return other.Model == Model &&
other.SimpleWrap == SimpleWrap &&
other.Scaling == Scaling &&
other.Depth == Depth &&
other.PosSampling == PosSampling &&
other.AngleSampling == AngleSampling &&
other.PosRefine == PosRefine &&
other.AngleRefine == AngleRefine &&
Math.Abs(other.Alpha - Alpha) < float.Epsilon &&
Math.Abs(other.Threshold - Threshold) < float.Epsilon;
other.Decomposition.Match(Decomposition);
}
}
}

0 comments on commit 2592f84

Please sign in to comment.
You can’t perform that action at this time.