Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
A guide to placing obj / wavefront files with ent_create #450779
04/22/15 14:23
04/22/15 14:23
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Hi,

This is short guide about using ent_create to place obj models in gamestudio 3d. Its wip so can/will be expanded lateron. This is fairly easy and is nothing special, but still a handy feature in some cases.

Why would you want using obj for ent_create?
Almost every model program can export a model as an obj. Only a few model editors can export to mdl format. In most cases that isn't a problem since MED can import .obj and export them to .mdl. But what if you want to let users being able to import their own models in your program or game? For example, their own weapon model.

Alternatives
One could give them a link to the gamestudio 3d free version so they can download and use MED. But that's not so professional and most likely only a few people would be willing to take the effort to install an entire external program for such a feature. Another alternative is using an other program that can convert .obj (or other often used formats) to .mdl, that's often a bit more professional if there are easy to install but some cost money and/or are rare. Besides, the more options the merrier.


Placing .obj with ent_create


Current features that I know off
* Does not break geometry (allows closed mesh)
* Skin support (by using ent_setskin)
/ Animations and bones, haven't tried yet

File requirements
This requires a model in .obj (obviously). For exporting from some model programs this requires either notepad for the user or you can add some code in your program/game that removes bad lines the obj file. The reason for this is that some model programs export .obj files with a material and so far from what I have seen, such a material included results in a bad format error when using en_create.

Obj requirements
* skin needs to be power of two (e.g. 64x64 or 256x256, 512x512, 512x256 etc.)
* "skin must not be indexed, but normal 24 bit RGB" (quoted from jcl cool )
* obj must not have a material (can be removed within notepad but also through code). Look for something like "usemtl ..." and remove this line. Make a backup of your obj file before doing this incase you accidently remove something important lateron (just to be safe).


Code test example (with texture), don't forget to place the obj model and your texture in the same folder
Click to reveal..
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////

BMAP* tex = "BlockTex.bmp"; //your texture



function main()
{
  vec_set(screen_size,vector(800,400,0));
  vec_set(screen_color,vector(155,155,155)); // grey
  vec_set(sky_color,vector(155,155,155)); // grey
  video_window(NULL,NULL,0,"Obj model test");
  d3d_antialias = 1;
  shadow_stencil = 1; //to test closed mesh
  
  
  level_load(NULL);
  vec_set(camera.x,vector(0,0,100));
  vec_set(camera.pan,vector(0,-90,0));
  
  you = ent_create("ExportBlock3.obj", nullvector, NULL); //place big model 
  you.scale_x = 10;
  you.scale_y = 10;
  ent_setskin(you, tex, 1);
  
  you = ent_create("ExportBlock3.obj", vector(0, 0, 10), NULL); //place small model above for shadow testing
  set(you, SHADOW);
  you.scale_y = 4;
  ent_setskin(you, tex, 1);
  
  
  while (1)
  { 
    you.pan += time_step*3;
    you.tilt += time_step*3;
    wait(1);
  } 

}


Removing material line through code *update*
There are several possibilities here and the material line could be different for each model program that exports the obj (also since some programs export with line breakers and some do not). What works for me is first txt_load, change the strings with the GS3d string functions and than save them as .obj again. Than you can load the new .obj file with ent_create.


Programs tested with and instructions


Create your model. File -> Export -> Wavefront (obj) -> uncheck 'write materials' -> [export].


Create your model. File -> Export -> 3d model -> select obj as type -> [export]. Open obj file in notepad or through code, delete the "usemtl ..." line (without quotes, example: usemtl _Brick_Rough_Tan_1). Be carefull, some Sketchup functions allow users to break their mesh iirc.


Photoshop works? Damn right it does, by using 3d layers. Though with a minor problem though that has nothing to do with ent_create+obj. Photoshop export to .obj always destroys the mesh, whether you import it with MED or load the obj directly with ent_create. Note that I have only tested this with cs5, so for newer version this may be fixed but I doubt it. Cause of closed mesh this cannot be used for stencil shadows etc. but for other stuff it doesn't matter I think.
Ok how to do it: File -> New -> 3D -> New shape from layer -> Export 3d layer -> Wavefront (obj). Now open the obj in notepad and search for mtl.... lines and remove them (like usemtl Left_Material).



Hope this is usefull for some. Will be expanded later on. Cheers.

Last edited by Reconnoiter; 04/27/15 12:48.
Re: A guide to placing obj / wavefront files with ent_create [Re: Reconnoiter] #450797
04/22/15 21:25
04/22/15 21:25
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Reconnoiter@ nice tutorial man! thanks a lot!

Best regards


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: A guide to placing obj / wavefront files with ent_create [Re: 3run] #450815
04/23/15 12:24
04/23/15 12:24
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Glad to be of service laugh

I have expanded it a bit, with photoshop this also works lol.

Re: A guide to placing obj / wavefront files with ent_create [Re: Reconnoiter] #450977
04/26/15 09:51
04/26/15 09:51
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Thanks.
Hopefully ent_create is fixed one day so that the usemtl lines in the obj are just discarded...

Re: A guide to placing obj / wavefront files with ent_create [Re: FBL] #451025
04/27/15 12:47
04/27/15 12:47
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
np

About the mtl lines, I have an added a paragraph how to deal with them automatically through code (see the yellow update line). Its fairly easy but material line could be different between export programs so that is something to keep an eye on.

For instance Sketchup does add line breakers/new sentence/the \n thingy (or whatever it is called), but some do not. If the /n thingy is not done, its harder to remove the right line.

Last edited by Reconnoiter; 04/27/15 12:53.

Moderated by  aztec, Blink, HeelX 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1