Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose HeightfieldColliderShape to use it in Game Studio #561

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
00ce451
[Physics] Fix HeightScale that is 1 when HeightfieldTypes.Float
EternalTamago Jul 5, 2019
bda238c
[Physics] Move HeightfieldColliderShape from "Xenko.Physics.Shapes" t…
EternalTamago Jul 16, 2019
6d1135b
[Physics] Add HeightmapAsset that is used for heightfield's initial h…
EternalTamago Jul 25, 2019
5bf2b94
[Physics] Add HeightfieldColliderShapeDesc
EternalTamago Jul 25, 2019
7fbdc44
[Navigation] Support HeightfieldColliderShape
EternalTamago Jul 25, 2019
e748186
Fix height scale for Short type
EternalTamago Aug 18, 2019
096e2eb
Add sRGB sampling property to HeightmapAsset
EternalTamago Aug 18, 2019
df8715e
Change type of InitialHeights to Heightmap
EternalTamago Nov 6, 2019
2366efd
[Navigation] Recreate collider shape only when the desc updated
EternalTamago Nov 7, 2019
aae183c
[Fix] Initialized HeightfieldColliderShapeDesc with pointless value
EternalTamago Nov 12, 2019
5f31f97
Fix attributes for InitialHeights
EternalTamago Nov 19, 2019
0d1a985
Rename HeightScaleSetting to CustomHeightScale
EternalTamago Nov 19, 2019
2726f60
[Navigation] Add a way to update dynamic shape and remove Refresh met…
EternalTamago Nov 19, 2019
c7c012a
Simplify CalculateHeightScale
EternalTamago Nov 21, 2019
95f8cd4
Rename HeightmapSize to CustomHeightmapSize
EternalTamago Nov 21, 2019
09ffef7
Clean up
EternalTamago Nov 21, 2019
c66b603
Add comment
EternalTamago Nov 23, 2019
b70ef82
[Physics] Change default HeightStickSize
EternalTamago Nov 28, 2019
0e8a48c
[Physics] Fix a bug that tries to update disposed collider shape's de…
EternalTamago Nov 28, 2019
7c16ae2
[Physics] Change default value for IsSRgb
EternalTamago Nov 28, 2019
6a4100b
[Physics] Change types of Floats, Shorts and Bytes from List<T> to ar…
EternalTamago Dec 2, 2019
76fcf85
Revert "[Physics] Fix HeightScale that is 1 when HeightfieldTypes.Float"
EternalTamago Dec 2, 2019
6c25560
Lock height arrays for using them on another thread
EternalTamago Dec 6, 2019
c574fbe
Fix to detect heightfield updated by HeightmapAsset
EternalTamago Dec 7, 2019
fe8bae6
Remove unnecessary using
EternalTamago Dec 7, 2019
34283a3
Change names of HeightfieldType and Type to HeightType
EternalTamago Dec 7, 2019
e961232
Change Width and Length of Heightmap to Size
EternalTamago Dec 7, 2019
1c2916b
Add default value to Size of CustomHeightmapSize
EternalTamago Dec 7, 2019
619d647
Change type of InitialHeights to IInitialHeightData
EternalTamago Dec 10, 2019
1f3f186
Update to check HeightStickSize and Heightmap size
EternalTamago Dec 10, 2019
7c3e32c
Rename EnableAlwaysUpdateDynamicShape to AlwaysUpdateDynamicShape
EternalTamago Dec 12, 2019
be252c8
Add Component property to StaticColliderCacheSettings
EternalTamago Dec 12, 2019
69a7222
Overloading GetStaticColliderCacheSettings to get all cache settings
EternalTamago Dec 12, 2019
ed77c0c
Fix the check whether collider shape needs the recreating at rebuildi…
EternalTamago Dec 15, 2019
330c203
Cosmetic change
EternalTamago Dec 18, 2019
1034df7
Add IsRecenteringOffsetted that adds extra offset to local offset
EternalTamago Dec 18, 2019
b83945e
Change Size property of HeightmapAsset to Resizing property
EternalTamago Dec 19, 2019
4e940de
Change type of HeightScale of desc to IHeightScale
EternalTamago Dec 19, 2019
f7e3257
Renew Heightfield desc and Heightmap asset
EternalTamago Jan 12, 2020
4a4fdd5
Add AlwaysUpdateNaviMeshCache to StaticColliderComponent to be able t…
EternalTamago Feb 25, 2020
d5453a5
Remove StaticColliderCacheSettings and things related to it
EternalTamago Feb 25, 2020
fea9606
Rename interfaces and classes related to heightfield and heightmap to…
EternalTamago Feb 25, 2020
e04e0dd
Rename properties related to heightfield and heightmap to be suitable…
EternalTamago Feb 25, 2020
d91701f
Add CopyTo<T> to IHeightStickArraySource
EternalTamago Feb 25, 2020
570674d
Use CopyTo<T> to copy the source to the height stick array
EternalTamago Feb 25, 2020
82157e9
Change ShouldCenterHeightZero to HeightfieldCenteringParameters
EternalTamago Feb 25, 2020
9d35c5c
Update display names
EternalTamago Feb 25, 2020
43e6da6
Remove Floats/Shorts/Bytes properties from IHeightStickArraySource
EternalTamago Feb 25, 2020
90ed271
Change Heightmap, HeightmapAsset and Heightfield desc
EternalTamago Mar 2, 2020
eae799b
Remove FillHeights method from HeightfieldColliderShapeDesc
EternalTamago Mar 8, 2020
14e9a20
Add comments
EternalTamago Mar 8, 2020
f80f2d7
Change CustomHeightScale to use fraction
EternalTamago Mar 14, 2020
6c2fbbd
Fix comment
EternalTamago Mar 30, 2020
e841561
Merge remote-tracking branch 'origin/master' into pr561
xen2 Apr 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,95 @@
// 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.Assets.Physics;
using Xenko.Assets.Presentation.Preview.Views;
using Xenko.Core.Mathematics;
using Xenko.Editor.Preview;
using Xenko.Graphics;
using Xenko.Physics;

namespace Xenko.Assets.Presentation.Preview
{
[AssetPreview(typeof(HeightmapAsset), typeof(HeightmapPreviewView))]
public class HeightmapPreview : PreviewFromSpriteBatch<HeightmapAsset>
{
private Heightmap heightmap;
private Texture heightmapTexture;
private BlendStateDescription adequateBlendState;

public int Width => heightmap?.Width ?? 0;
public int Length => heightmap?.Length ?? 0;

/// <summary>
/// Gets or sets a callback that will be invoked when the texture is loaded.
/// </summary>
public Action NotifyHeightmapLoaded { get; set; }

protected override Vector2 SpriteSize
{
get
{
if (heightmapTexture == null)
return base.SpriteSize;

return new Vector2(heightmapTexture.Width, heightmapTexture.Height);
}
}

protected virtual Vector2 ImageCenter
{
get
{
if (heightmapTexture == null)
return Vector2.Zero;

var imageSize = new Vector2(heightmapTexture.Width, heightmapTexture.Height);

return imageSize / 2f;
}
}

protected override void LoadContent()
{
heightmap = LoadAsset<Heightmap>(AssetItem.Location);

heightmapTexture = heightmap?.CreateTexture(Game.GraphicsDevice);

adequateBlendState = BlendStates.Opaque;

NotifyHeightmapLoaded?.Invoke();

// Always use LDR
RenderingMode = RenderingMode.LDR;
}

protected override void UnloadContent()
{
if (heightmapTexture != null)
{
heightmapTexture.Dispose();
heightmapTexture = null;
}

if (heightmap != null)
{
UnloadAsset(heightmap);
heightmap = null;
}
}

protected override void RenderSprite()
{
if (heightmapTexture == null)
return;

var origin = ImageCenter - SpriteOffsets;
var region = new RectangleF(0, 0, heightmapTexture.Width, heightmapTexture.Height);
var orientation = ImageOrientation.AsIs;

SpriteBatch.Begin(Game.GraphicsContext, SpriteSortMode.Texture, adequateBlendState);
SpriteBatch.Draw(heightmapTexture, WindowSize / 2, region, Color.White, 0, origin, SpriteScale, SpriteEffects.None, orientation, swizzle: SwizzleMode.RRR1);
SpriteBatch.End();
}
}
}
@@ -0,0 +1,15 @@
// 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.Windows;
using Xenko.Editor.Preview.View;

namespace Xenko.Assets.Presentation.Preview.Views
{
public class HeightmapPreviewView : XenkoPreviewView
{
static HeightmapPreviewView()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(HeightmapPreviewView), new FrameworkPropertyMetadata(typeof(HeightmapPreviewView)));
}
}
}
@@ -0,0 +1,10 @@
!TemplateAssetFactory
Id: 1D3C9128-C94B-413B-9ABB-80ADDD372F61
AssetTypeName: ColliderShapeAsset
Name: Heightfield
Scope: Asset
Description: A heightfield collider
Group: Physics
Icon: ..\.xktpl\ColliderPlane.png
DefaultOutputName: ColliderHeightfield
FactoryTypeName: ColliderShapeHeightfieldFactory
@@ -0,0 +1,12 @@
!TemplateAssetFactory
Id: 127EC64F-6E15-4964-98F4-DB735B39AE09
AssetTypeName: HeightmapAsset
Name: Heightmap
Scope: Asset
Description: A heightmap for heightfield
Group: Physics
Order: 100
Icon: ..\.xktpl\TextureGray.png
DefaultOutputName: Heightmap
FactoryTypeName: HeightmapFactory
ImportSource: true
@@ -0,0 +1,45 @@
// 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 System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xenko.Assets.Textures;
using Xenko.Core;
using Xenko.Core.Assets.Editor.Settings;
using Xenko.Core.Assets.IO;
using Xenko.Core.Assets.Templates;
using Xenko.Core.IO;
using Xenko.Core.Reflection;

namespace Xenko.Assets.Presentation.Templates
{
public class HeightmapFactoryTemplateGenerator : AssetFromFileTemplateGenerator
{
public new static readonly HeightmapFactoryTemplateGenerator Default = new HeightmapFactoryTemplateGenerator();

public static readonly Guid TemplateId = new Guid("127EC64F-6E15-4964-98F4-DB735B39AE09");

public override bool IsSupportingTemplate(TemplateDescription templateDescription)
{
if (templateDescription == null) throw new ArgumentNullException(nameof(templateDescription));
return templateDescription.Id == TemplateId;
}

protected override async Task<IEnumerable<UFile>> BrowseForSourceFiles(TemplateAssetDescription description, bool allowMultiSelection)
{
var assetType = description.GetAssetType();
var assetTypeName = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute<DisplayAttribute>(assetType)?.Name ?? assetType.Name;
var extensions = new FileExtensionCollection($"Source files for {assetTypeName}", TextureImporter.FileExtensions);
var result = await BrowseForFiles(extensions, allowMultiSelection, true, InternalSettings.FileDialogLastImportDirectory.GetValue());
if (result != null)
{
var list = result.ToList();
InternalSettings.FileDialogLastImportDirectory.SetValue(list.First());
InternalSettings.Save();
return list;
}
return null;
}
}
}
Expand Up @@ -16,6 +16,7 @@ public static void Register()
TemplateManager.Register(AssetFactoryTemplateGenerator.Default);
TemplateManager.Register(AssetFromFileTemplateGenerator.Default);
// Specific asset templates must be registered after AssetFactoryTemplateGenerator
TemplateManager.Register(HeightmapFactoryTemplateGenerator.Default);
TemplateManager.Register(ColliderShapeHullFactoryTemplateGenerator.Default);
TemplateManager.Register(ProceduralModelFactoryTemplateGenerator.Default);
TemplateManager.Register(SkyboxFactoryTemplateGenerator.Default);
Expand Down
57 changes: 57 additions & 0 deletions sources/editor/Xenko.Assets.Presentation/Themes/Generic.xaml
Expand Up @@ -397,4 +397,61 @@
</Setter.Value>
</Setter>
</Style>

<Style TargetType="{x:Type views:HeightmapPreviewView}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type views:HeightmapPreviewView}">
<DockPanel d:DataContext="{d:DesignInstance viewModel:HeightmapPreviewViewModel}">
<Grid Background="{StaticResource NormalBrush}" DockPanel.Dock="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
<Button Command="{Binding PreviewZoomOutCommand}" Background="Transparent" Margin="2">
<Image Source="{StaticResource ImageZoomOut}" RenderOptions.BitmapScalingMode="NearestNeighbor" Width="16" Height="16" />
</Button>
<Button Command="{Binding PreviewZoomInCommand}" Background="Transparent" Margin="2">
<Image Source="{StaticResource ImageZoomIn}" RenderOptions.BitmapScalingMode="NearestNeighbor" Width="16" Height="16" />
</Button>
<Button Command="{Binding PreviewScaleToRealSizeCommand}" Background="Transparent" Margin="2">
<Image Source="{StaticResource ImageScaleOnRealSize}" RenderOptions.BitmapScalingMode="NearestNeighbor" Width="16" Height="16" />
</Button>
<Button Command="{Binding PreviewFitOnScreenCommand}" Background="Transparent" Margin="2">
<Image Source="{StaticResource ImageFitOnScreen}" RenderOptions.BitmapScalingMode="NearestNeighbor" Width="16" Height="16" />
</Button>
</StackPanel>
</DockPanel>
</Grid>
<StatusBar DockPanel.Dock="Bottom" Visibility="{Binding Session, Converter={xk:Chained {xk:ObjectToBool}, {xk:VisibleOrCollapsed}}}">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="0">
<TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding SpriteScale, StringFormat={}{0:P}}"/>
</StatusBarItem>
<Separator Grid.Column="1"/>
<StatusBarItem Grid.Column="2">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding PreviewHeightmapWidth, StringFormat={xk:Localize W: {0}}}"/>
<TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding PreviewHeightmapLength, StringFormat={xk:Localize L: {0}}}"/>
</StackPanel>
</StatusBarItem>
</StatusBar>

<ContentPresenter x:Name="PART_XenkoView"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@@ -0,0 +1,87 @@
// 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.Collections.Generic;
using Xenko.Assets.Physics;
using Xenko.Core.Assets;
using Xenko.Core.Assets.Compiler;
using Xenko.Core.Mathematics;
using Xenko.Core.Serialization.Contents;
using Xenko.Editor.Thumbnails;
using Xenko.Graphics;
using Xenko.Physics;
using Xenko.Rendering;

namespace Xenko.Assets.Presentation.Thumbnails
{
[AssetCompiler(typeof(HeightmapAsset), typeof(ThumbnailCompilationContext))]
public class HeightmapThumbnailCompiler : ThumbnailCompilerBase<HeightmapAsset>
{
public HeightmapThumbnailCompiler()
{
IsStatic = false;
Priority = 10050;
}

public override IEnumerable<ObjectUrl> GetInputFiles(AssetItem assetItem)
{
var asset = (HeightmapAsset)assetItem.Asset;
var url = asset.Source.FullPath;
if (!string.IsNullOrEmpty(url))
{
yield return new ObjectUrl(UrlType.File, url);
}
}

protected override void CompileThumbnail(ThumbnailCompilerContext context, string thumbnailStorageUrl, AssetItem assetItem, Package originalPackage, AssetCompilerResult result)
{
result.BuildSteps.Add(new ThumbnailBuildStep(new HeightmapThumbnailCommand(context, assetItem, originalPackage, thumbnailStorageUrl,
new ThumbnailCommandParameters(assetItem.Asset, thumbnailStorageUrl, context.ThumbnailResolution))
{ InputFilesGetter = () => GetInputFiles(assetItem) }));
}

/// <summary>
/// Command used to build the thumbnail of the texture in the storage
/// </summary>
public class HeightmapThumbnailCommand : ThumbnailFromSpriteBatchCommand<Heightmap>
{
private Texture texture;

public HeightmapThumbnailCommand(ThumbnailCompilerContext context, AssetItem assetItem, IAssetFinder assetFinder, string url, ThumbnailCommandParameters parameters)
: base(context, assetItem, assetFinder, url, parameters)
{
parameters.ColorSpace = ColorSpace.Linear;
}

protected override void PreloadAsset()
{
base.PreloadAsset();

texture = LoadedAsset?.CreateTexture(GraphicsDevice);
}

protected override void UnloadAsset()
{
if (texture != null)
{
texture.Dispose();
texture = null;
}

base.UnloadAsset();
}

protected override void RenderSprites(RenderDrawContext context)
{
if (LoadedAsset == null)
return;

if (texture != null)
{
var destinationRectangle = new RectangleF(0, 0, Parameters.ThumbnailSize.X, Parameters.ThumbnailSize.Y);

SpriteBatch.Draw(texture, destinationRectangle, new RectangleF(0, 0, texture.Width, texture.Height), Color.White, 0f, new Vector2(0, 0), SpriteEffects.None, swizzle: SwizzleMode.RRR1);
}
}
}
}
}
@@ -0,0 +1,40 @@
// 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 Xenko.Assets.Presentation.Preview;
using Xenko.Core.Assets.Editor.ViewModel;
using Xenko.Editor.Preview;
using Xenko.Editor.Preview.ViewModel;

namespace Xenko.Assets.Presentation.ViewModel.Preview
{
[AssetPreviewViewModel(typeof(HeightmapPreview))]
public class HeightmapPreviewViewModel : TextureBasePreviewViewModel
{
private HeightmapPreview heightmapPreview;
private int previewHeightmapLength;
private int previewHeightmapWidth;

public HeightmapPreviewViewModel(SessionViewModel session)
: base(session)
{
}

public int PreviewHeightmapLength { get { return previewHeightmapLength; } private set { SetValue(ref previewHeightmapLength, value); } }

public int PreviewHeightmapWidth { get { return previewHeightmapWidth; } private set { SetValue(ref previewHeightmapWidth, value); } }

public override void AttachPreview(IAssetPreview preview)
{
heightmapPreview = (HeightmapPreview)preview;
heightmapPreview.NotifyHeightmapLoaded += UpdateHeightmapInfo;
UpdateHeightmapInfo();
AttachPreviewTexture(preview);
}

private void UpdateHeightmapInfo()
{
PreviewHeightmapWidth = heightmapPreview.Width;
PreviewHeightmapLength = heightmapPreview.Length;
}
}
}
Expand Up @@ -52,6 +52,8 @@ TemplateFolders:
- !file Templates/Assets/Physics/ColliderShapePlane.xktpl
- !file Templates/Assets/Physics/ColliderShapeSphere.xktpl
- !file Templates/Assets/Physics/ColliderShapeCone.xktpl
- !file Templates/Assets/Physics/ColliderShapeHeightfield.xktpl
- !file Templates/Assets/Physics/Heightmap.xktpl
- !file Templates/Assets/Scenes/DefaultPrefab.xktpl
- !file Templates/Assets/Scenes/DefaultNavigationMesh.xktpl
- !file Templates/Assets/Scenes/DefaultScene.xktpl
Expand Down