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

Addition of Chapter 3 Part 1: Model Loading #76

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

adamsmith1990
Copy link
Contributor

This is my attempt at beginning a Chapter 3 based on https://learnopengl.com
This covers loading a model using AssimpNet and rendering it. This could be continued with another chapter that applies the lighting techniques used in previous chapters.

I had to adjust the texture loading significantly to get it to work properly. For some reason when I tried to load the .obj that the original author supplied (https://learnopengl.com/data/models/backpack.zip), it got stuck in the model loading loop and crashed after using up all of my memory. So instead I just downloaded the original fbx and loaded the texture directly into a Texture object and used a simple shader to apply it.

I adjusted the tutorial from https://learnopengl.com and have attached it to this pull request. I did my best, but I would love for this to be reviewed and standardized to match the rest of the chapters. I hope you like what I have put together!

I did just read through your contributing guidelines, and in the future I will use Early Pull requests.

OpenTK Chapter 3.docx

Copy link
Member

@NogginBops NogginBops left a comment

Choose a reason for hiding this comment

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

Really nice work!
It's great to receive such substantial contributions!
Thanks a ton!

This is looking quite good for a start.
I've commented on bunch of stuff that can be improved with this chapter, mostly about adding more comments describing what is going on and why.

There are also some things we can document here about how to use OpenTK with math types, and also how to be efficient with memory and avoiding copying it unnecessarily. Those code parts I could help with if you want me to. :)

Chapter3/1-ModelLoading/Shaders/shader.frag Outdated Show resolved Hide resolved
Chapter3/1-ModelLoading/Shaders/shader.frag Outdated Show resolved Hide resolved
Common/Model.cs Outdated Show resolved Hide resolved
Common/Model.cs Outdated
//Create a new importer
AssimpContext importer = new AssimpContext();

//This is how we add a logging callback
Copy link
Member

Choose a reason for hiding this comment

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

What is a logging callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comes directly from the Assimp-Net Wiki and from what I understand, it attaches a function to the importer so that during the import you can see the steps that are happening and they will be written to the console. The documentation for AssimpNet is rather lacking (I couldn't get their chm file to work. I am adding some comments to explain it better, since looking more into it, I think it is a very useful debugging tool.

Copy link
Member

Choose a reason for hiding this comment

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

Are you interested in expanding on this comment to explain it a bit more? Should be the last thing before I can merge it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made some changes to the comments which hopefully clarify this better.

Common/Model.cs Outdated Show resolved Hide resolved
Common/Model.cs Outdated Show resolved Hide resolved
Common/Model.cs Outdated Show resolved Hide resolved
Common/Model.cs Outdated Show resolved Hide resolved
Common/Model.cs Outdated Show resolved Hide resolved
Common/Model.cs Show resolved Hide resolved
@adamsmith1990
Copy link
Contributor Author

I just made a second commit with these changes. I would especially appreciate help working with implementing System.Numerics. Thanks for all the feedback and patience. I am learning a lot from this and still getting used to Pull Requests, so let me know if I do anything weird.

@NogginBops
Copy link
Member

I've added a new commit to this PR where I refactor a few things. Please take a look and tell me what you think 🙂

Seems like you've got this thing with commits and PRs down 😎, wouldn't know you aren't used to PRs if you didn't tell me.

NogginBops and others added 2 commits July 5, 2022 22:55
…d CursorGrabbed to CusorState. Updated assimp matrix conversion comment to reflect column-major state.
@adamsmith1990
Copy link
Contributor Author

I did some cleanup and tried to improve the comments throughout. Thanks for catching the inverse transformation matrix needed for the normals. I actually realized this later and was pleasantly surprised to see it had already been fixed. In my latest commit, I specifically mentioned the comment about the Assimp matrix being column-major to make sure I had that right.

Let me know if you see anything else we should change, or go ahead and make the changes. Thanks!

…() method. Made a few minor changes to comments to help the code be more in line with the online tutorial.
@adamsmith1990
Copy link
Contributor Author

OpenTK Chapter 3_07-09-22.docx

I updated the documentation to match our changes and made a small commit to go with it.

I think we are almost there.

Common/Model.cs Outdated
Comment on lines 79 to 83
public void Draw()
{
for (int i = 0; i < meshes.Count; i++)
meshes[i].Draw();
}
Copy link
Member

Choose a reason for hiding this comment

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

I would actually like to see this logic moved into the chapter code itself. This type of abstraction using objects with a Draw method isn't an abstraction that works in the long term for graphics. It becomes really inefficient, so I think that we should avoid making the suggestion that this is a good way to structure rendering code.

Copy link
Member

Choose a reason for hiding this comment

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

This means both the mesh and the model drawing code.

And I know the other abstractions like texture and shaders do this type of things too with their Use methods, but I'm not happy with those either.

@NogginBops
Copy link
Member

Also is the docx file meant for the website? If so I would recommend you make a PR to the website repo where you just add the folder and a markdown file containing the chapter text.

@NogginBops
Copy link
Member

@adamsmith1990 What is the status of this? Should I do the last pieces to get this merged or do you have time to do them?

@adamsmith1990
Copy link
Contributor Author

I've just gotten over COVID, so thanks for you patience. I think the commit I just made fits what you were looking for. This way there is a bit more control over how things are drawn and the meshes are now just containers for VAOs and models are just containers for meshes from a loaded model.

Copy link
Member

@NogginBops NogginBops left a comment

Choose a reason for hiding this comment

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

I'm ready to merge this. There is only one thing that I realized needed doing and that is fixing the proper attribution according to the CC BY 4.0 license.


GL.Enable(EnableCap.DepthTest);

// Backpack by Berk Gedik: https://sketchfab.com/3d-models/survival-guitar-backpack-low-poly-799f8c4511f84fab8c3f12887f7e6b36
Copy link
Member

Choose a reason for hiding this comment

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

According to the license the model is under you need to not only give attribution to the creator but also link the license.
You also need to specify if any changes where made to the work.

I would suggest creating a license.txt or attribution.txt in Resources/Backpack where you put the sketchfab link, the license link and specify if any changes where made.

@DigitalBox98
Copy link

Nice addition!
I've been able to use it with ImGUI to have a quick FBX model viewer.

ModelViewer

Regarding the comment "I had to adjust the texture loading significantly to get it to work properly".
I might have a look at his part, as it would be great to use the textures directly from the models.

I have the same C++ program from LearnOpenGL compiled, so I can debug to understand more deeply what remains to be done here.

@DigitalBox98
Copy link

Ok I've got a draft version working which mimicks learnopengl (loading of OBJ model including the various textures). I might propose a dedicated PR soon if it's OK.

obj

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

3 participants