About Monkey 2 › Forums › Monkey 2 Programming Help › Is there a example of loading a b3d model
This topic contains 12 replies, has 3 voices, and was last updated by
EdzUp
1 year, 5 months ago.
-
AuthorPosts
-
November 11, 2017 at 1:13 pm #11631
As the title suggests is there a example for loading a 3d model.
I have tried modifying DruggedBunny’s example with the following:
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134[crayon-5cb9d8205a6f0322690558 inline="true" ]#Import "<std>"#Import "<mojo3d>"#Import "<assimp>"Using std..Using mojo..Using mojo3d..Using assimp..' ----------------------------------------' Application name...' ----------------------------------------Global AppName:String = "Star Rogue"Class Game Extends Window' Basic 3D scene requirements...Field scene:SceneField camera:CameraField light:Light' Test cube...Field cube:ModelField cubemesh:MeshField cubematerial:MaterialField Ship:ModelField ShipMesh:MeshField ShipMaterial:MaterialMethod New (title:String, width:Int, height:Int, flags:WindowFlags)Super.New (title, width, height, flags)scene = Scene.GetCurrent () ' Important!camera = New Camera' Camera settings...camera.Near = 0.1' Camera position...camera.Move (0, 0, -2)camera.Rotate (0, 0, 0)light = New Lightlight.Move (-10, 10, -10)light.Rotate (0, 0, 0)cubemesh = Mesh.CreateBox (New Boxf (-0.5, -0.5, -0.5, 0.5, 0.5, 0.5)) ' 1 x 1 x 1cubematerial = New PbrMaterial (Color.Aluminum)cube = New Model (cubemesh, cubematerial)cube.Rotate (0, 45, 0)cube.Scale = New Vec3f( .1, .1, .1 )ShipMesh = Mesh.Load( "Models\Quadrill.b3d" )ShipMaterial = New PbrMaterial( Color.Red )Ship = New Model( ShipMesh, ShipMaterial )Ship.Scale = New Vec3f( 10.0, 10.0, 10.0 )EndMethod OnRender (canvas:Canvas) OverrideIf Keyboard.KeyHit (Key.Escape) Then App.Terminate ()If Keyboard.KeyDown (Key.A)camera.Move (0.0, 0.0, 0.1)EndifIf Keyboard.KeyDown (Key.Z)camera.Move (0.0, 0.0, -0.1)EndifIf Keyboard.KeyDown (Key.Left)camera.Rotate (0.0, 1.0, 0.0)EndifIf Keyboard.KeyDown (Key.Right)camera.Rotate (0.0, -1.0, 0.0)EndifIf Keyboard.KeyDown (Key.Up)camera.Rotate (1.0, 0.0, 0.0)EndifIf Keyboard.KeyDown (Key.Down)camera.Rotate (-1.0, 0.0, 0.0)Endifcube.Rotate (0.0, 1.0, 0.0)Ship.Rotate( 0.0, -1.0, 0.0 )' Render scene to canvas (passed to OnRender by mojo), from camera...scene.Render (canvas, camera)' Tell app to draw frame when ready...RequestRender ()EndEndFunction Main ()' Windowed mode...Local width:Int = 640Local height:Int = 480Local flags:WindowFlags = WindowFlags.Center' Full-screen mode (comment out above)...' Local width:Int = 1920' Local height:Int = 1080' Local flags:WindowFlags = WindowFlags.FullscreenNew AppInstanceNew Game (AppName, width, height, flags)App.Run ()EndBut to no avail, the Quadrill.b3d mesh is attached to this message.
What am I doing wrong I have been wracking me brains over trying to get a model to load but it wont load any of the Ultimate Unwrap or Milkshape3d exported models I have tried.
Attachments:
November 11, 2017 at 2:41 pm #11633On another note is there a way to actually move Models/Meshes as it appears that it doesn’t have a Move method like the camera does?
November 11, 2017 at 5:57 pm #11636Not sure if B3D is supported, but Models are Entities that include mesh and texture data (and more), same as Cameras and Lights — meshes are just the model’s mesh data, not Entities.
They use the same movement/rotation methods as Cameras, Lights and other Entity objects:
Monkey12345678910111213141516171819202122' EDIT: Didn't need full example -- this is a tweak to my template3d example in the Code Library, adding cube.Move:Method OnRender (canvas:Canvas) OverrideProcessInput ()UpdateGame ()cube.Rotate (0.0, 1.0, 0.0)cube.Move (0.0, 0.0, 0.1)' Tell app to draw frame when ready...RequestRender ()' Render scene to canvas (passed to OnRender by mojo), from camera...scene.Render (canvas, camera)EndThat’s slightly different to Blitz3D, in that models were referred to there as Entities, and now they’re sort of clarified as a separate thing
It was Lights, Cameras and Models-called-Entities in Blitz3D, despite Lights and Cameras being Entities as well, so this sort of makes more sense!
Entity is the base class, whereas Lights, Cameras and Models are the objects you’d actually use in practise, which have all the properties of Entities.
That said, the Entity docs don’t seem to mention Move, Turn, etc, and they don’t appear in the auto-complete either, presumably as a result of whatever makes them missing from the docs!
November 11, 2017 at 6:10 pm #11639Wait, the docs do mention these, but under mojo3d:mojo3d.graphics -> Extensions, rather than Entity itself, which is really confusing! I guess the editor isn’t taking the extended version into account for autocomplete purposes.
November 11, 2017 at 6:13 pm #11640Oh, you need to import mojo3d-loaders as well as assimp, see if that works:
Monkey1#Import "<mojo3d-loaders>"November 11, 2017 at 6:34 pm #11643ah thanks Druggedbunny will try that tried the loaders first with no success so looked at the assimp files and thought that assimp was all that’s required.
November 11, 2017 at 8:23 pm #11644#Import <"mojo3d-loaders">
This should be all you need to do to add assimp support to a mojo3d project so you can load b3d, 3ds, x etc.
The ‘turtles’ test in mojo-loaders/tests/ uses b3d I think.
I’m currently working on animation stuff so animated entities are properly copied (doesn’t currently work) and some form of ExtractAnimSeq is implemented, possibly via an Animation.Slice(…) method. Should have some b3d animation demos converted soon.
November 11, 2017 at 8:25 pm #11645Mark how do we access the move properties of a Entity with cameras it’s just Camera.move but entities don’t seem to have this property?
November 11, 2017 at 8:35 pm #11646As the bunny on drugs mentioned, many of the utility methods such as Move, Rotate are implemented via extensions, which means they’re rather inconveniently located in a separate section of the docs:
file:///D:/dev/monkey2/docs/modules/mojo3d/module/mojo3d-EntityEXT.html
Ideally, I want docs to either link to (at least) extensions in the same module from the class docs page, or perhaps even show extensions in the class itself, but that’ll happen ‘later’. For now, I’m concentrating on the coding part, and being able to implemement this util stuff in a separate ‘extensions’ file is very nice.
I’m not sure why autocomplete isn’t finding them – in fact, it doesn’t seem to be able to find any entity members…will look into it.
November 11, 2017 at 8:38 pm #11647Mark thanks for your help on this will get to converting my other code over and see where how it takes shape
November 12, 2017 at 6:23 pm #11655
Can anyone guess what I am makingNovember 12, 2017 at 7:02 pm #11658‘Star Rogue’?
November 12, 2017 at 7:04 pm #11660Yup good guess
-
AuthorPosts
You must be logged in to reply to this topic.