floooh / oryol-samples

Oryol extension module samples
MIT License
82 stars 17 forks source link

Help with very simple mesh application #8

Closed ivandrodri closed 6 years ago

ivandrodri commented 7 years ago

Hello, I'm trying to load a simple mesh file on the screen. My code compiles but the executable gives me an error. I have followed the MeshViewer application (together with its shader file), that works perfectly, but in my simplified and simpler code I'm doing something wrong I guess. Below is the part of my code where I guess there could be an error.

Thanks in advance for any help!!

##########################################

AppState::Codes MeshViewerApp::OnInit() {

IOSetup ioSetup;
ioSetup.FileSystems.Add("file", LocalFileSystem::Creator());
ioSetup.Assigns.Add("data:", "file:///C:/Users/ivand/Documents/UI_WASS/oryol-samples/data/");
IO::Setup(ioSetup);

auto gfxSetup = GfxSetup::WindowMSAA4(800, 512, "Rendering APP");

gfxSetup.HighDPI = true;
gfxSetup.DefaultPassAction = PassAction::Clear(glm::vec4(0.5f, 0.5f, 0.5f, 1.0f));
Gfx::Setup(gfxSetup);

this->mesh = Gfx::LoadResource(MeshLoader::Create(MeshSetup::FromFile(this->meshPaths[0]), 
[this](MeshSetup& setup) {
    this->curMeshSetup = setup;

    Id shd_n = Gfx::CreateResource(NormalsShader::Setup());

    auto ps = PipelineSetup::FromLayoutAndShader(this->curMeshSetup.Layout, shd_n);
    ps.DepthStencilState.DepthWriteEnabled = true;
    ps.DepthStencilState.DepthCmpFunc = CompareFunc::LessEqual;
    ps.RasterizerState.CullFaceEnabled = true;
    ps.RasterizerState.SampleCount = 4;

    this->drawState.Pipeline = Gfx::CreateResource(ps);
} ));

this->drawState.Mesh[0] = this->mesh;

// setup projection and view matrices
const float fbWidth = (const float)Gfx::DisplayAttrs().FramebufferWidth;
const float fbHeight = (const float)Gfx::DisplayAttrs().FramebufferHeight;
this->proj = glm::perspectiveFov(glm::radians(60.0f), fbWidth, fbHeight, 0.01f, 100.0f);

return App::OnInit();

}

//----------------------------------------------------------------------------- AppState::Code MeshViewerApp::OnRunning() {

this->frameCount++;
this->updateCamera();
this->updateLight();

Gfx::BeginPass();

NormalsShader::vsParams VsParams;
VsParams.mvp = this->modelViewProj;
Gfx::ApplyDrawState(this->drawState);
Gfx::ApplyUniformBlock(VsParams);

Gfx::Draw();

Gfx::EndPass();

Gfx::CommitFrame();

return Gfx::QuitRequested() ? AppState::Cleanup : AppState::Running;

}

#############################################

floooh commented 7 years ago

What does the error look like? Is there an assert-message and call stack? Did you try stepping through the code with a debugger?

ivandrodri commented 7 years ago

Thanks for the quick reply! The code compiles without any error so I guess I am sending some wrong information to the GPU? When I try to open the executable it appears a window but the application says Debug Error! and It gives me an abort() option...

What I wanted to do is to plot a mesh from an external file into the screen. I was following the steps in the Triangle example (that is very clear) but I think I am doing something wrong. The MeshViewer application is very nice but a bit involved (at least to me :) ) to understand the basic concepts around the MeshSetup, Pipelines, etc....

floooh commented 7 years ago

Hmm remote-debugging such problems is kind of hard ;) If you run the program from Visual Studio the error window should give you a "Retry" button which eventually puts you in the debugger at the location where the crash happens. This should give you enough information (type of error, callstack, console output) to debug the problem.

ivandrodri commented 7 years ago

Thanks for the info, I've solved the problem now !. I have another question about the meshes :) .

I would like to use a mesh file in .stl format but I saw that the MeshViewer use the extension .omsh . The first question is if is it possible to use the .stl files directly without transforms to .omsh .

The second one is related with the oryol-export application. I am not able to always convert a .stl file to .omsh. I am using this command

./oryol-export -config /oryol-tools/test_files/test_config.toml -model /../stl_files/mesh.stl -out /oryol-samples/data/mesh.omsh

but some times the conversion works but in some cases I have the following error:

[error] 16-bit indices requested, but found index >= (1<<16)!

Is it related with the file test_config.toml?

Thanks in advance for any help!

floooh commented 7 years ago

Hmm, you could try adding a an "IndexSize = 4" line to the test_config.toml file, this should then export 32-bit indices, but I don't know if this is supported all the way to the renderer.

The oryol-export tool has mostly been tested with FBX, and even this only required very 'clean' FBX files, so seeing those random problems doesn't surprise me.

In general, there's currently not really a useful asset import strategy, you're basically required to write you own loaders (but I have at least started with a new general 3D asset file format, described here: https://github.com/floooh/oryol-fileformats/blob/master/OrbFileFormat.h), but the tool to generate this file format is still very early (https://github.com/floooh/oryol-tools/tree/master/src/oryol-conv3d)

ivandrodri commented 7 years ago

Thanks a lot for the information! I'll give a look to the new tool you suggest me and I think I'll try anyway to write my own loader 👍