Stride Forums Archive

How to load and display a model at runtime

9 posts, 5119 views, 2019-06-03 to 2020-05-01

Subrahmanya_Chakrava (O.S.Chakravarthi) 2019-06-03 #1

Hi,

I have a model in a well known 3d format (like obj/fbx/dae/3ds).
The model is fully baked and the meshes in the model have various kinds of textures(diffuse, height, emmissive etc.)

How can I load such a model and render in my game?
I knew that Xenko can use Assimp and load a 3d model but I could not find any sample code to render the loaded model.

Thanks in advance.

tonfilm 2019-06-03 #2

Why not import it with game studio and load it from the game content?

https://doc.xenko.com/latest/en/manual/scripts/create-a-model-from-code.html

HapticMonkey (Hap) 2019-08-04 #3

You can add the assimp dlls to your project …

HapticMonkey (Hap) 2019-08-04 #4

Further you can investigate the methods in the dynamic libraries which are generated with the game. You can learn a great deal from just examining what is available to you there.

image

Hap

Subrahmanya_Chakrava (O.S.Chakravarthi) 2019-08-12 #5 in reply to #2

Hi,
I cannot do it as I am generating the model at runtime.

is it generative or load from file?

Subrahmanya_Chakrava (O.S.Chakravarthi) 2019-08-13 #7 in reply to #6

It is a generated model.

Then it’s pretty easy, you just create a MeshDraw class, assign your data and add it to a Model class. like here: https://doc.xenko.com/latest/en/manual/graphics/low-level-api/draw-vertices.html

or here: https://github.com/profan/XenkoByteSized/tree/master/XenkoByteSized/ProceduralMesh

david_j (David J) 2020-05-01 #9

The examples tonfilm provided are for immediate mode drawing.

I found there was a bit of a documentation gap in trying to understand how to load a retained-model into Stride3d, so that it handles drawing.

I wrote this sample, which loads a Wavefront OBJ file, at runtime, creates a model, and attaches it to an entity. This does not use immediate mode drawing, but instead sets up the buffers so Stride3d can draw it during it’s draw loop.

I also submitted a documentation update to: https://doc.xenko.com/latest/en/manual/scripts/create-a-model-from-code.html

Until it goes through, here is the relevant code snippit to manually add a single triangle to a MeshDraw: