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

Change Assimp to Silk.NET.Assimp implementation #1719

Merged
merged 12 commits into from
Aug 18, 2023

Conversation

Jklawreszuk
Copy link
Collaborator

PR Details

This PR completes johang88 attempt to migrate from native C++ Assimp code to Silk.NET bindings (link to his PR).

Changes

  • I checked previous code and can tell it's a 1-1 recreation of the native MeshConverter. However ProcessMeshMaterial() was incomplete so I wrote missing part.
  • Also, my PR includes small changes that simplify MeshConverter and changes proposed by other contributors (those I could understand)

Overall, I have not noticed any regression or difference in the import of objects, but I would be happy to hear any feedback :)

Once, merged, I believe it will unlock the possibility of further development of the asset compiler for platforms other than Windows and work on glTF.

Related Issue

#1394
#360

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • Breaking change (fix or feature that would cause existing functionality to change).

Copy link
Contributor

@Ethereal77 Ethereal77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. Hopefully we can also get rid of the C++ FBX importer in the near future.

I've commented some things to fix, and other things that should be good to note for future enhancements or refactorings.

@@ -0,0 +1,294 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remember to add the copyright header to new files, the one that doesn't mention "Silicon Studio".

public static readonly Operation[] ConvertAssimpStackOperationCppToCs = new Operation[]
{
Operation.Add, //aiStackOperation_Add
Operation.Add3ds, //aiStackOperation_Add3ds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed weird. I guess github wrongly displays this file because when you open file everything is correct

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the indentation is not normalized between tabs and spaces? I tend to favor spaces because this very reason.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this file had mixed tabs, Thanks!

sources/tools/Stride.Importer.Assimp/MeshConverter.cs Outdated Show resolved Hide resolved
Comment on lines +991 to +994
//else if (hasBaseValue)
//{
// computeColorNode = gcnew MaterialFloatComputeNode(baseValue);
//}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's commented C++/CLI code, since C# doesn't have a gcnew keyword. gcnew is specific to C++/CLI and C++/CX.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gcnew in C++/CLI is just the new keyword in C#, i.e. instantiating a new instance managed by the Garbage Collector.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this is a C# file, so there's no use for it. Maybe used as some sort of reference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now I'm not very versed in the material system. Maybe @tebjan knows better, but if there is a MaterialFloatComputeNode (or there were one) that maybe is a IComputeValue (does that type still exist?) it is/was useful somehow.
Or maybe it is merged into ComputeColor at this point and we should just create a regular ComputeColor with a single scalar value?
Anyway, that else if (hasBaseValue) indicates there was an use for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code is from cpp MeshConverter. Out of curiosity, I cloned the xenko 1.4 source code and the code was still commented out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then must be a half-implemented feature, or a remnant from some old code. As I said, I'm not very knowledgeable about the material system, so don't know what would be the uses of that even if it sounds useful somehow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found original commit. Maybe It will be usefull for someone in the future: https://github.com/SiliconStudio/xenko//commit/d5ee29ea8efeceaa6eaf777ff903e4514f28c6f7

Comment on lines +1017 to +1018
// TODO TEMP: Set a default diffuse model
finalMaterial.Attributes.DiffuseModel = new MaterialDiffuseLambertModelFeature();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a default fixed Lambertian diffuse model?

Comment on lines +1028 to +1035
// TODO TEMP: Set a default specular model
var specularModel = new MaterialSpecularMicrofacetModelFeature
{
Fresnel = new MaterialSpecularMicrofacetFresnelSchlick(),
Visibility = new MaterialSpecularMicrofacetVisibilityImplicit(),
NormalDistribution = new MaterialSpecularMicrofacetNormalDistributionBlinnPhong()
};
finalMaterial.Attributes.SpecularModel = specularModel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a default fixed Blinn-Phong specular model?

}
else if (textureType == TextureType.TextureTypeEmissive)
{
// TODO: Add support
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to support all these texture map types, as they are pretty much standard today for PBR workflows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fully agree, importing textures with the model would be great.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there is already an issue for this: #473

@NicusorN5
Copy link
Contributor

Question: should this be marked as a draft? There's lots of TO-DOs.

@Ethereal77
Copy link
Contributor

I think if you add [WIP] to the title it is enough. But don't know.

@Jklawreszuk
Copy link
Collaborator Author

Thanks for all the feedback ^_^. Yea, I'll set to WIP PR for a while, but I hope to fix all the issues soon™

@Jklawreszuk Jklawreszuk changed the title Change Assimp to Silk.NET.Assimp implementation [WIP] Change Assimp to Silk.NET.Assimp implementation Aug 7, 2023
@VaclavElias
Copy link
Contributor

Regarding the spaces, https://github.com/stride3d/stride/blob/master/.editorconfig is present, but not sure if it is in the right location?

@Ethereal77
Copy link
Contributor

To avoid this kind of problems with tabs and spaces I like to use this extension from Microsoft Labs. Highly recommended.

@tebjan
Copy link
Member

tebjan commented Aug 7, 2023

There is a link on top of this page that says "Convert to draft". But I would split the PR, first establish feature parity with the existing importer and only after that is merged, add additional features in a second PR.

But the workflow decision is of course up to the dev.

@Ethereal77
Copy link
Contributor

Yeah, of course. My review is only suggestions to point to typos, indentation, comments, etc. Then comments about what we should aim for in a future PR.

@Doprez
Copy link
Contributor

Doprez commented Aug 7, 2023

Question: should this be marked as a draft? There's lots of TO-DOs.

Although I havent cross referenced anything myself, there were a bunch of TO-DOs in the C++ files as well.

@Jklawreszuk Jklawreszuk closed this Aug 7, 2023
@Jklawreszuk Jklawreszuk changed the title [WIP] Change Assimp to Silk.NET.Assimp implementation Change Assimp to Silk.NET.Assimp implementation Aug 7, 2023
@Ethereal77
Copy link
Contributor

Why have you closed the PR?

@Jklawreszuk
Copy link
Collaborator Author

I am sorry, I force pushed the wrong branch on the remote by mistake and PR was automaticaly closed 😢
At least I have a lesson to avoid that.

@Jklawreszuk Jklawreszuk reopened this Aug 7, 2023
@Jklawreszuk
Copy link
Collaborator Author

Alright, so I refactored and moved the classes to separate files and applied all the review suggestions I could.
I think my changes are ready to be reviewed again.

Copy link
Contributor

@Ethereal77 Ethereal77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Some more comments. I hope you don't hate me too much for some of these ones 😁.
The indentation one about tabs vs spaces is just a hassle. I favor spaces because render the same in every editor (unlike tabs, which render depending on editor/user config). But I understand it is a matter of preference.
As Stride has no coding style guidelines defined formally anywhere apart from imitating what you can find in other files or the rules of .editorconfig, it's up to you.
I don't want to be an indentation nazi 😀.

/// <summary>
/// Enumeration of the new Assimp's flags.
/// </summary>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hate me, but... blank line between XMLdoc and type definition 😁

@@ -0,0 +1,19 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are new files, the header should be the one that doesn't mention Silicon Studio.
Look at this file for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...I am not sure about that. Because I originaly separated classes/enums from this file:
https://github.com/stride3d/stride/blob/master/sources/tools/Stride.Assimp/MaterialStack.cs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it comes from another file with a license header, forget about my comment then. For other files with no header or for new files, however, use the "simple" one.

@@ -0,0 +1,16 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header. See above.

/// <summary>
/// Enumeration of the different types of node in the new Assimp's material stack.
/// </summary>
public enum StackType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not a more appropriate name for this StackElementType? It defines not the type of the material stack, but the type of an element in such stack.

return currentComposition;
}

public static ComputeTextureColor GenerateMaterialTextureNode(string vfsOutputPath, string sourceTextureFile, uint textureUVSetIndex, Vector2 textureUVscaling, TextureAddressMode addressModeU, TextureAddressMode addressModeV, Logger logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long line of arguments. See above.


namespace Stride.Importer.Assimp
{
public class MeshConverter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that you have normalized spaces to tabs? I ask because it seems Stride has favored the C# standard of using always indentation of 4 spaces.

}
}

public unsafe Model Convert(string inptuFilename, string outputFilename, bool deduplicateMaterials)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still typo in inptuFilename.

Logger = logger ?? GlobalLogger.GetLogger("Import Assimp");
}

private void ResetConvertionData()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be named ResetConversionData?

{
var animationCurve = new AnimationCurve<Vector3>();

// Switch to cubic implicit interpolation mode for Vector3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indentation.

@Jklawreszuk
Copy link
Collaborator Author

Jklawreszuk commented Aug 15, 2023

Ok. Some more comments. I hope you don't hate me too much for some of these ones 😁.

@Ethereal77 Not at all. That's the purpose of code review, to make sure everything is alright 😅
Thanks again for all suggestions. I think that's the good point to have identation consistency, so I changed for every file to space instead of tabs. Would be also nice to take care of .editorconfig file in future. Other than that I think my changes can be reviewed again (I hope didn't miss anything 😂)

@VaclavElias
Copy link
Contributor

Nice attitude 🙂

Copy link
Contributor

@Ethereal77 Ethereal77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
This is a first good step towards a more developed content pipeline for Stride.

namespace Stride.Importer.Assimp.Material
{
/// <summary>
/// Enumeration of the new Assimp's flags.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better explanation of this types would be nice.
It's ok however if you are not very familiar with graphics and/or meshes/Assimp. That is something that can be later expanded in a PR to improve documentation I think.

@Jklawreszuk
Copy link
Collaborator Author

If there are no objections, I think changes are ready to merge 😊

@Eideren
Copy link
Collaborator

Eideren commented Aug 18, 2023

Thanks a bunch for taking the time to look at this @Ethereal77, and @NicusorN5 for providing additional insight !

I'm guessing this one will be taken care of in another issue/pr @Jklawreszuk ?
https://github.com/stride3d/stride/pull/1719/files#r1285751424

@Eideren Eideren merged commit 7b84fed into stride3d:master Aug 18, 2023
1 check passed
@Eideren
Copy link
Collaborator

Eideren commented Aug 18, 2023

And of course, thank you for going through this stuff @Jklawreszuk

@Jklawreszuk Jklawreszuk deleted the SilkAssimp branch August 18, 2023 23:29
@Jklawreszuk
Copy link
Collaborator Author

Thanks a bunch for taking the time to look at this @Ethereal77, and @NicusorN5 for providing additional insight !

Also, we should thank @johang88 for his big effort 🫡🫡 . I'm impressed.

I'm guessing this one will be taken care of in another issue/pr @Jklawreszuk ?

Definitely, we need now to discuss what to do next with FBX importer, because having cpp compiler as requirement during building is pain and I think potential PR would cover additional changes to assimp importer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants