fix: Regression of new FBX importer on behalf of Noah (#2246)

* BASE COMM

* Updates on Shader and resource marshaling

* Update- cleanup

* Updates- clean up

* Updates

* Updates as by Eidren & IXLLEGACYIXL on Github PR review

* Update shader- remove commented test code

* Update: Clean up to effect class & shader

* Scale Factor moved to Importer

* Removed extra class Vec4

* Fix to update scale factor in impoter

* Normal fix on blendshapes

* Normal fix

* IMPORTER CKECIIN

* Importer

* Incorporating Kryptos feedback on PR

* Incorporating doprez feedback

* Updated .props to remove Assimp from Runtime refs

* Feedback from Jklawreszuk

* Removed workspace file, Jklawreszuk

* Feedback from IXLLEGACYIXL

* Account for default scaling

* Removed Assimp feedback Wolffy101

* Multiple Animation

* Removed test leftover code

* UI update to give option to(or not to) import animatioms

* Feedback empty spaces @Kryptos

* BlendShape+Importer

1. Handling large blendshape data (static + dynamic)
2. Upding importer for root motion animation

* PR Feedback

* PR Feedback

* Blendshape

* Root check

* Feed back implementation

* Feedback implementation @Eideren

* Feedback implementation @Eideren

* Feedback incorporated @Eideren

* Animationscale @Eideren

* Anim root data

* Animation Update

* Update aling the file to latest

* logging feeback

* Removed blendshape code of importer

* Removed blendshape code

* Fix for pipe  "|" character in name

* Invalid chars replace to _

* Invalid char fix

* Handling invalid char

* Remove data field contains blend shape

* Reverting non impacted files

* Line gap

* Rebase

* Fix of anim import node name invid chracaters

* Optimize invalid char replace code

* Fix mesh bone to sksleton for invalid char

* Fix Node naming

* Revert "Fix Node naming"

This reverts commit d8f718a1a6.

* Fix for animation only import

* Revert "Fix for animation only import"

This reverts commit 887a7c7941.

* Fix to anim not loading

* Anim importer fix

* Naming issues

* Sword fix

* debug code removal

* Line break spacings

* Null check skeletonURL

* Revert import UI Text

* Casing

* Duplicate line

* Duplicate line

* Removed Impoter.Assimp

* Shift keys

* Removed namespace

* Mannaquin bones fix

* Animation pivots

* Anim fix

* Anim Importer Debone Fix

* spacing and comm code

* Hashset for list bone name

* extra parameter

* UV coords fixed

* Spacings removaal

* more spacing

* spacing

* Fix line ending for Directory.Packages.props

* Fix spacing

* Rollback analyzer change

* Fix spacing

* Embedded texture extract from FBX

* check for null scene before texture import

* eiderens suggestions

---------

Co-authored-by: noa7 <noahwdv@gmail.com>
Co-authored-by: noa7707 <157441788+noa7707@users.noreply.github.com>
Co-authored-by: Noah7071 <157886157+Noah7071@users.noreply.github.com>
Co-authored-by: Eideren <contact@eideren.com>
This commit is contained in:
Doprez 2024-05-18 14:47:32 -06:00 коммит произвёл GitHub
Родитель a1d17845b6
Коммит b3e3c74812
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 40 добавлений и 18 удалений

Просмотреть файл

@ -102,7 +102,6 @@ namespace Stride.Importer.ThreeD
}
var scene = Initialize(inputFilename, outputFilename, importFlags, 0);
// If scene is null, something went wrong inside Assimp
if (scene == null)
{
@ -115,6 +114,8 @@ namespace Stride.Importer.ThreeD
return null;
}
ExtractEmbededTexture(scene, inputFilename);
var materialNames = new Dictionary<IntPtr, string>();
var meshNames = new Dictionary<IntPtr, string>();
var animationNames = new Dictionary<IntPtr, string>();
@ -214,6 +215,11 @@ namespace Stride.Importer.ThreeD
if (meshIndexToNodeIndex.ContainsKey(i))
{
var meshInfo = ProcessMesh(scene, scene->MMeshes[i], meshNames);
if (meshInfo == null)
{
continue;
}
foreach (var nodeIndex in meshIndexToNodeIndex[i])
{
@ -245,11 +251,6 @@ namespace Stride.Importer.ThreeD
}
}
// embedded texture - only to log the warning for now
for (uint i = 0; i < scene->MNumTextures; ++i)
{
ExtractEmbededTexture(scene->MTextures[i]);
}
return modelData;
}
@ -846,13 +847,17 @@ namespace Stride.Importer.ThreeD
}
// Build the indices data buffer
var nbIndices = 3 * mesh->MNumFaces;
byte[] indexBuffer;
var nbIndices = (int)(3 * mesh->MNumFaces);
var is32BitIndex = mesh->MNumVertices > 65535;
if (is32BitIndex)
indexBuffer = new byte[sizeof(uint) * nbIndices];
else
indexBuffer = new byte[sizeof(ushort) * nbIndices];
int arraySize = is32BitIndex ? sizeof(uint) * nbIndices : sizeof(ushort) * nbIndices;
//Mesh has no vertices
if(arraySize < 1)
{
return null;
}
byte[] indexBuffer = new byte[arraySize];
fixed (byte* indexBufferPtr = &indexBuffer[0])
{
@ -940,12 +945,29 @@ namespace Stride.Importer.ThreeD
}
}
#pragma warning disable IDE0060 // Remove unused parameter
private unsafe void ExtractEmbededTexture(Silk.NET.Assimp.Texture* texture)
#pragma warning restore IDE0060 // Remove unused parameter
private unsafe void ExtractEmbededTexture(Scene* scene, string importFieName)
{
Logger.Warning("The input file contains embeded textures. Embeded textures are not currently supported. This texture will be ignored",
new NotImplementedException("Embeded textures extraction"));
string dir = Path.GetDirectoryName(importFieName);
for (uint i = 0; i < scene->MNumTextures; ++i)
{
var texture=scene->MTextures[i];
string fullName = Path.Combine(dir,Path.GetFileName(texture->MFilename));
CreateTextureFile(texture, fullName);
}
}
private unsafe void CreateTextureFile(Silk.NET.Assimp.Texture* texture, string path)
{
var texel = texture->PcData;
var arraySize = texture->MWidth;
byte[] buffer = new byte[texture->MWidth];
fixed (byte* bufferPointer = buffer)
{
var sourcePointer = (byte*)texture->PcData;
System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(bufferPointer, sourcePointer, arraySize);
}
System.IO.File.WriteAllBytes(path, buffer);
}
private unsafe Dictionary<string, MaterialAsset> ExtractMaterials(Scene* scene, Dictionary<IntPtr, string> materialNames)
@ -1400,7 +1422,7 @@ namespace Stride.Importer.ThreeD
if (assimp.GetMaterialTexture(lMaterial, textureType, j, ref path, ref mapping, ref uvIndex, ref blend, ref textureOp, ref mapMode, ref flags) == Return.Success)
{
var relFileName = path.AsString;
var relFileName = Path.GetFileName(path.AsString);
var fileNameToUse = Path.Combine(vfsInputPath, relFileName);
textureNames.Add(fileNameToUse);
break;