Jump to content


Photo

d3d_model_load_ext - 3d Models Importing Script


  • Please log in to reply
85 replies to this topic

#1 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 394 posts
  • Version:GM8

Posted 02 October 2006 - 10:28 PM

d3d_model_load_ext() is a script for importing models in the following file formats

  • WaveFront .obj
  • Anim8or .vtx
  • C source files .c (as exported by LithUnwrap)
  • DirectX files .x (only in ascii/non compressed)
  • 3D Studio ASCII files .asc
  • GameMaker .mod (as loaded and saved by the builtin GM3D model loading/saving routines)

to Game Maker d3d.

d3d_model_load_ext() reads all vertex, texture and normals data (if available in the file).

It has parameters to make it easier to use the model in GM, you can:

  • flip the normals
  • mirror the texture coordinates
  • set a scale (because d3d_transform_add_scaling(xy,ys,zs) distorts the normals)

(this only works for non .mod models)

Download

Download the script and demo project, .gmk


Usage
Loading a model works the same way as with d3d_load_model(), with three additional parameters:

model=d3d_model_create();
d3d_model_load_ext(model, fname, flipnormals, fliptexcoords, scale);
(TODO: Make parameters optional)

The model can then be used in the Draw Event:
d3d_model_draw(model,x,y,z,texture);

Additioal Information and Licensing
d3d_model_load_ext() is a freeware script and you may well redistribute the package as it is.

Some parts of it took me hours to develop/figure out/research.
If you use it in your projects, please give credit to me like:
"Uses d3d_model_load_ext() by Paul "Master Xilo" Frischknecht"

Created for model formats as exported by LithUnwrap 1.3, but should work for files created by any exporter.
If it doesn't, try reconverting your model using the above program.

Remember that loading Game Maker's .mod 3d model format is always the fastest. Convert other formats only once and save them as .mod if possible. If you want to load .mod files even faster, check out d3d_model_load_fast.

I hope you'll find this script useful.
- Paul

Edited by Master Xilo, 02 April 2014 - 09:02 PM.

  • 5

#2 Skarik

Skarik

    GMC member

  • GMC Member
  • 1068 posts
  • Version:GM:Studio

Posted 02 October 2006 - 10:32 PM

O_O SHINY.....

Edit:

HOLY SH*T! DOES THIS LOAD FASTER THAN MOSAIC LIGHT???????!?!?!?! OR IS IT MY PC?!?!?!

Edited by Skarik, 02 October 2006 - 10:35 PM.

  • 0

#3 INl

INl

    GMC Member

  • New Member
  • 102 posts

Posted 03 October 2006 - 02:50 AM

I haven't found any problems with it... besides what I assume to be the program's limitations (in a rather detailed file... more simplistic models work perfectly).

Nice job :)
  • 0

#4 wildweststballa

wildweststballa

    GMC Member

  • New Member
  • 272 posts

Posted 03 October 2006 - 03:01 AM

This is Very good and looks Very promising. I believe it allows for more detailed models to run at a higher fps, I believe. Anyway, I have to disagree with you on one part and that is not wanting to use marzinip anymore. How do we protect are models from people stealing them cry* I still like this program, I could see myself using this for terrain. Does it supports animations?
  • 0

#5 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 394 posts
  • Version:GM8

Posted 03 October 2006 - 12:22 PM

I'll upload a demo of the future feautres soon.

EDIT: view first post

Edited by Master Xilo, 03 October 2006 - 01:34 PM.

  • 0

#6 Proffessor_gad

Proffessor_gad

    GMC Member

  • New Member
  • 757 posts

Posted 03 October 2006 - 04:25 PM

This looks quite promising. I hope you continue making things like this :) .

P.S. Game maker 6.0, needs a good 3d collissions example. So if you have some free time :lol: ......
  • 0

#7 Voxel

Voxel

    8-bit pixel

  • New Member
  • 61 posts

Posted 08 October 2006 - 04:48 AM

can you show the example of the full one?
thanks :ph34r:

Edited by Voxel, 09 October 2006 - 02:15 AM.

  • 0

#8 Darksoul

Darksoul

    3D Dude

  • New Member
  • 124 posts

Posted 10 October 2006 - 03:23 PM

this is REALLY cool it needs more attention
  • 0

#9 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 394 posts
  • Version:GM8

Posted 11 October 2006 - 07:30 AM

OK, finally I release the whole script.

See first post.
  • 0

#10 coolsmile

coolsmile

    Programmer

  • New Member
  • 1346 posts

Posted 11 October 2006 - 11:53 PM

AWESOME JOB, this is a beautiful :GM5:
  • 0

#11 abacus

abacus

    GMC Member

  • New Member
  • 1330 posts

Posted 14 October 2006 - 12:26 AM

sickism
  • 0

#12 coolsmile

coolsmile

    Programmer

  • New Member
  • 1346 posts

Posted 15 October 2006 - 03:58 PM

This topic deserves more attention :D
  • 0

#13 alzable

alzable

    GMC Member

  • New Member
  • 188 posts

Posted 16 October 2006 - 07:11 AM

WOW ... this means I can finally load my 1610 vertex model! This is one of the fastest model loaders ive seen! THis certainly does deserve more attention! =D

Well done!!!

alzable
  • 0

#14 Obiki_San

Obiki_San

    GMC Member

  • New Member
  • 136 posts

Posted 16 October 2006 - 10:48 AM

Pretty Cool *smiles*

I've tested the model that came with the demo. Why is it that the .mod file is so much bigger but loads the fastest? Ah well.

Good Work.
  • 0

#15 Burntrubber9

Burntrubber9

    GMC Member

  • New Member
  • 101 posts

Posted 16 October 2006 - 11:47 PM

The reason the .mod file loads fastest is because it is the GM default. It does not require you to read any strings, pull out the data,and write it to a model. It is just written directly to a model from the data in the file.
  • 0

#16 aparoid_x

aparoid_x

    Nintendork

  • New Member
  • 228 posts

Posted 17 October 2006 - 12:04 AM

I can't get it to load my .vtx file. How can I import one, changing the code in the creation event of your example?
  • 0

#17 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 394 posts
  • Version:GM8

Posted 17 October 2006 - 03:41 PM

Controls:
Space: load a model
L: light on/off

more: see help
  • 0

#18 zyvolution

zyvolution

    GMC Member

  • New Member
  • 255 posts

Posted 26 October 2006 - 01:24 PM

I would really like to try this one but the link is dead can you please re-upload it?
  • 0

#19 Klite-GameMaker

Klite-GameMaker

    GMC Member

  • New Member
  • 7 posts

Posted 27 October 2006 - 05:01 PM

AWESOME :D But the link is down :GM5:
  • 0

#20 cambesa

cambesa

    GMC Member

  • GMC Member
  • 868 posts
  • Version:Unknown

Posted 27 October 2006 - 06:44 PM

i thought it only can import or load .d3d files...
you can make them with marzipan but.....
i dont like it that you need to make the texture again with gamemaker because gm cant load textured models...

i hope gm will make better 3d in the next version but i dont think so.
maybe a litle bit more but not so much thet it can load all models textured...
  • 0

Insanely large signature removed by a moderator.

(I've had that signature for decades but okay...)


#21 zyvolution

zyvolution

    GMC Member

  • New Member
  • 255 posts

Posted 27 October 2006 - 06:56 PM

I converted my obj file with marzipan and i added it to gml and i added the texture in gm and it just uses it correctly.
  • 0

#22 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 394 posts
  • Version:GM8

Posted 27 October 2006 - 09:46 PM

AWESOME :D But the link is down :GM5:

<{POST_SNAPBACK}>

I fixed the link.

Edited by Master Xilo, 27 October 2006 - 09:46 PM.

  • 0

#23 BenRK

BenRK

    Now in high-definition!

  • GMC Member
  • 810 posts
  • Version:GM:Studio

Posted 28 October 2006 - 07:03 AM

Wow! This is perfect! It ran an obj file on my computer at (lit)50fps and (not lit)~60fps on my comp with over 8500 vertexes loaded! And seeing as my comp is crap, THAT'S GREAT! I'll be using this in the future.
  • 0

#24 Voxel

Voxel

    8-bit pixel

  • New Member
  • 61 posts

Posted 29 October 2006 - 05:01 PM

wow this is so cool!
  • 0

#25 Double A

Double A

    GMC Member

  • New Member
  • 97 posts

Posted 31 October 2006 - 04:41 PM

...

This is a godsend. I love you. ^_^
  • 0

#26 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 394 posts
  • Version:GM8

Posted 31 January 2007 - 05:29 PM

no problem Double A
  • 0

#27 kawearo

kawearo

    GMC Member

  • New Member
  • 12 posts

Posted 17 February 2007 - 06:48 PM

how do i get an avatar??[SIZE=14]???
  • 0

#28 Gumgo

Gumgo

    The Gecko

  • New Member
  • 310 posts

Posted 23 February 2007 - 04:20 AM

Hmm... For some reason, it rotates my .X models 90 degrees and also seems to "center" the objects even if I want their origin somewhere else (maybe that's just the .X format though. I KNOW the rotation isn't though) and also throws an error (error in real() function or something) when loading .OBJ files (all exported from 3ds max). I took a look at the files and they both looked fairly normal, aside from the fact that for some reason 3ds max doesn't seem to export normals and texture coords in OBJ format (no idea why, but it's starting to really bug me). Anyway, and idea about the .X thing?

Edit: Figured out the weird origin thing, turns out it is because DirectX Meshes have a seperate section for transformation. There's just a little extra code you have to add. Anyways, if you want me to PM it to you, Master Xilo, I'd be happy to.

Edit2: Oh, and the thing about rotations I figured out as well. I believe that either 3DS Max or the exporter I'm using uses the Y axis as "up and down" whereas Game Maker (with the most commonly used projection) uses the Z axis. Anyways, just thought I'd mention these for anyone else who might have trouble.

And a third thing about .X files: In your script, Master Xilo, you had a spot where the script searched for "Mesh {" (with one space). My exporter actually outputs "Mesh . {" with two spaces (but not the dot, just did that so the second space'd show up), so that section was never found. I recommend changing it to something like if (string_replace_all(" ","",row) == "Mesh{") so that it will work in more cases.

Great script though!

Edited by Gumgo, 23 February 2007 - 11:46 PM.

  • 0

#29 guzu_ligo

guzu_ligo

    GMC Member

  • New Member
  • 109 posts

Posted 30 April 2007 - 11:59 PM

I made an object in Cinema 4D and export it to .x and also .obj and they didn't seem to work. I get an error message about not being able to read real (Not real) or something. If you are still working on this, I'll provide you with the files to check. The thing I noticed that the file format is a bit different than yours. There is the use of // for comments and there is something like (Mesh CINEMA_4DMESH {..... ).

Keep up the good work.
  • 0

#30 the_doominator

the_doominator

    Eight Star

  • New Member
  • 925 posts

Posted 10 May 2007 - 09:41 PM

this is easily better than mosaic light.... - :D
  • 0

#31 sonic2104

sonic2104

    Chaos Gaming

  • GMC Member
  • 530 posts

Posted 12 May 2007 - 04:55 PM

I got an error message

ERROR in
action number 1
of Key Press Event for <Space> Key
for object objloader:

Error in function real().

What's wrong. This happened when I tried to load my *.obj file.
  • 0
Just getting back into GM. . . Please excuse my noobishness.

#32 the_doominator

the_doominator

    Eight Star

  • New Member
  • 925 posts

Posted 12 May 2007 - 05:34 PM

that happens when you have a corrupt .obj file or too many triangles.
  • 0

#33 sonic2104

sonic2104

    Chaos Gaming

  • GMC Member
  • 530 posts

Posted 12 May 2007 - 06:00 PM

How many triangles is "too many" triangles?
  • 0
Just getting back into GM. . . Please excuse my noobishness.

#34 the_doominator

the_doominator

    Eight Star

  • New Member
  • 925 posts

Posted 12 May 2007 - 06:41 PM

I'm not sure.... how many do you have?
  • 0

#35 sonic2104

sonic2104

    Chaos Gaming

  • GMC Member
  • 530 posts

Posted 12 May 2007 - 07:22 PM

371 polys. I think I might know the problem. Does this script handle quads?
  • 0
Just getting back into GM. . . Please excuse my noobishness.

#36 the_doominator

the_doominator

    Eight Star

  • New Member
  • 925 posts

Posted 12 May 2007 - 07:29 PM

????????????????????????
  • 0

#37 them4n!ac

them4n!ac

    GMC Member

  • New Member
  • 1170 posts

Posted 12 May 2007 - 07:36 PM

that happens when you have a corrupt .obj file or too many triangles.

<{POST_SNAPBACK}>

or with unsupported .obj file gm may do this - if you work with 3ds max, you'll know what i am talking about (material libraries)
  • 0
what do you xpect to see here? another signature?
Cloud texture generator / renderer

#38 sonic2104

sonic2104

    Chaos Gaming

  • GMC Member
  • 530 posts

Posted 12 May 2007 - 07:51 PM

I dont work with 3DS Max, so I have absolutely no clue what you are talking about.
  • 0
Just getting back into GM. . . Please excuse my noobishness.

#39 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 394 posts
  • Version:GM8

Posted 29 May 2007 - 07:45 PM

it should handle quads, but i only wrote it for lithunwrap and anim8or .obj format. sry! :)
  • 0

#40 alucart13

alucart13

    GMC Member

  • New Member
  • 63 posts

Posted 29 May 2007 - 07:54 PM

no offense dude, i mean i know this took a lot of work, but the only problem i found was the limitation on importing .obj files. it cant open and object that mosaic light can. this may be faster than mosaic light, but it is very limited loading wise. good work though :) . If you worked on letting it import bigger objects, i would definately use it.
  • 0

#41 Caniac

Caniac

    The #1 Caniac

  • New Member
  • 2622 posts

Posted 26 June 2008 - 03:26 PM

I like it. but I doesn't seem to acept any of my blender .obj models, yes, I saw the date, oh well...
  • 0

#42 thundybear

thundybear

    GMC Member

  • New Member
  • 390 posts

Posted 01 August 2008 - 03:31 AM

how do you load the files without slecting them? I keep getting the

___________________________________________
ERROR in
action number 1
of Create Event
for object togepi:

File is not opened for reading.


how can I fix this?
  • 0
Posted Image
It's a pokemon game that someone actually works on! Features include: trainer battles, wild battles, menu + item system, NPCs, catching pokemon, Pokedex, playable maps and much more! Click the image to visit the Demo page!

Submit sprites here:
http://gmc.yoyogames...pic=453177&st=0

#43 Paddymay

Paddymay

    Puppy Playground

  • New Member
  • 320 posts

Posted 03 October 2008 - 12:09 AM

ugh

ERROR: Unkown variable rotation.

ERROR: This action is only available in Pro Edition.

ERROR: Unkown variable rotation.

ERROR: This action is only available in Pro Edition.

And so on, and on, and on, and on, and on, and on, and on, and on, and on, and on, and on, you get the point.
  • 0

#44 Fede-lasse

Fede-lasse

    AI Programmer

  • GMC Member
  • 2009 posts
  • Version:Unknown

Posted 03 October 2008 - 12:42 PM

And you don't even know why?!
  • 0

Call me Fede.


#45 Caniac

Caniac

    The #1 Caniac

  • New Member
  • 2622 posts

Posted 03 October 2008 - 04:56 PM

ERROR: This action is only available in Pro Edition.

DUH


how do you load the files without slecting them? I keep getting the

<snip>

how can I fix this?


:D

create:

model_building_1=d3d_model_create()
d3d_model_load_ext(model_building_1,"building_1.obj",0,1,4)

this is from my WIP competition 04 game

THEN

Draw event, SAME object.

d3d_model_draw(model_building_1,0,0,0,background_get_texture(bg_building_1))

I hope that this helps you ;)

Edited by Caniac, 03 October 2008 - 04:56 PM.

  • 0

#46 obliviux

obliviux

    GMC Member

  • New Member
  • 195 posts

Posted 23 November 2008 - 07:51 PM

For some reason mines keeps giving me this error message when I try to use the code in my own game: "File is not opened for reading"
  • 0

#47 toelle

toelle

    GMC Member

  • New Member
  • 123 posts

Posted 29 December 2008 - 04:59 PM

wow, this is great!
Couldnt finish my game without this!

Keep up the good work -_-
  • 0
My special: Visual Effects

Need the most awesome Visual Special Effects, custom made specially for you? Just PM me! Im at your service! I can create any visual effect, shooting effects, particles, fractals, sprites, Hud, explosions, anything! No problem! And it's of course 100% FREE!

#48 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 03 January 2009 - 09:49 PM

Nice script but I have my own Wavefront obj modeller and it creates good structured obj-files and your program can't open it.

However, WaveFront viewer and Milkshape can open it.
If you could fix this , it would be one of the best converters on GM.

Keep it up.
  • 0
Visit my website: http://www.di-martino.net

#49 chao master

chao master

    GMC Member

  • New Member
  • 36 posts

Posted 04 January 2009 - 07:43 PM

Whenever i load my modles there no textures on it - but that might just be bacause i'm exporting them from google skecthup
oh wait ignor that, that GM isnt it

Great script btw

Edited by chao master, 25 January 2009 - 10:31 AM.

  • 0
--[ Noctice I no longer do GML ]--
--[ As such I no longer provide support on my few things ]--

BRONISM, Brohoof for all.
Praise Fluttershy.
These days Im on EPR

Tutorials and examples
3d Tower Effect, transforms flat rooms easily!

#50 briantrlov

briantrlov

    GMC Member

  • GMC Member
  • 610 posts

Posted 24 January 2009 - 10:14 PM

somone doesnt want me using models because everything ive tried doesnt work, this one says ]


___________________________________________
FATAL ERROR in
action number 1
of Create Event
for object weed:

COMPILATION ERROR in code action
Error in code at line 2:
weed = d3d_model_create

at position 7: Variable name expected.
  • 0
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users