Jump to content

Scene Loading Example


Marleys Ghost
 Share

Recommended Posts

Using VC++ 2008 Express

 

Use the 2.3 Project Wizard to create a new project

 

I simply called the example "sceneloading"

 

Delete the generated example code in sceneloading.cpp

 

Replace with the following code:

 

 

#include "Framewerk.h"

int main(int argc, char** argv)
{
Initialize();
RegisterAbstractPath("PATH TO YOUR SDK FOLDER");
Graphics(800,600);

leadwerks::Framewerk fw;

fw.Create();

// Setup Global Objects
SetGlobalObject ("world_main", fw.GetMain ().GetWorld ());
SetGlobalObject ("world_transparency", fw.GetTransparency ().GetWorld ());
SetGlobalObject ("world_background", fw.GetBackground ().GetWorld ());
SetGlobalObject ("camera_main", fw.GetMain ().GetCamera ());
SetGlobalObject ("camera_transparency", fw.GetTransparency ().GetCamera ());
SetGlobalObject ("camera_background", fw.GetBackground ().GetCamera ());

TListener listener= CreateListener(fw.GetMain ().GetCamera ());
SetGlobalObject("listener", listener);


// Setup Initial Post Processing FX
fw.GetRenderer().SetGodRays(1);
fw.GetRenderer().SetHDR(1);
fw.GetRenderer().SetSSAO(1);
fw.GetRenderer().SetBloom(1);
fw.GetRenderer().SetAntialias(1);
fw.GetRenderer().SetReflectionRenderComponents(ENTITY_RENDERABLE);

// Load Skybox
        fw.GetRenderer().SetSkybox(LoadMaterial("abstract::FullskiesBlueClear0016_2_L.mat"));

// Setup On Screen Stats Info
fw.SetStats(2);

// Setup Collisions
Collisions(1, 1, 1);
Collisions(1, 2, 1);
Collisions(1, 3, 1);
Collisions(2, 2, 1);
Collisions(2, 3, 1);
Collisions(3, 3, 1);

LoadScene("abstract::YOUR_SCENE.sbx");

// Setup spectator
TBody spectator=CreateBodySphere();
SetBodyMass(spectator,1);
SetBodyGravityMode(spectator,0);
SetBodyDamping(spectator,1.0);
EntityType(spectator,3);
SetBodyBuoyancyMode(spectator,0);
PositionEntity(spectator,Vec3(0,75,0));

TVec3 camrotation=Vec3(0);
float mx=0;
float my=0;
float move=0;
float strafe=0;

HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

// MAIN LOOP
while (!KeyHit(KEY_ESCAPE))
{

mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
my=Curve(MouseY()-GraphicsHeight()/2,my,6);
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

camrotation.X=camrotation.X+my/10.0;
camrotation.Y=camrotation.Y-mx/10.0;
RotateEntity(fw.GetMain().GetCamera(),camrotation);

move=KeyDown(KEY_W)-KeyDown(KEY_S);
strafe=KeyDown(KEY_D)-KeyDown(KEY_A);
TVec3 force = Vec3(strafe*10.0,0,move*10.0);
force=TFormVector(force,fw.GetMain().GetCamera(),0);
AddBodyForce(spectator,force);

UpdateAppTime();
UpdateWorld(AppSpeed()) ; 

PositionEntity(fw.GetMain().GetCamera(),EntityPosition(spectator));

fw.Update();
fw.Render();

Flip(0);
}

fw.Free();

return Terminate();
}

 

Add existing items

 

Framewerk.cpp

Layer.cpp

Renderer.cpp

 

(Right click on the sceneloading solution, add/existing item and navigate to your SDK's CPP folder)

 

Copy to the sceneloading project folder

 

shaders.pak

Scripts folder

 

from your 2.3 SDK folder

 

*You will need to make sure you have wobbledot3.dds in the materials folder in your SDK folder. I found without it, using emitters in a scene will casue the app to crash on loading. I am not sure if 2.3 comes with this file and my download just missed it, or its not included. I took mine from a previous install. Simply place it in the root of the materials folder.

 

I made it so the code points to the SDK folder so nothing, other than the scripts folder and textures.pak need to be moved to the sceneloading app dir.

 

 

Create a scene and save it in the maps folder in your SDK folder, note though as far as I can tell you will have to load the skybox manually via code (as per above code) or parse it and the waterplane via a small ProcessScene function.

 

 

You need to update the oildrum.lua file with this (Thanks to Macklebee):

 

dofile('Scripts/base.lua') -- We need the base class entity

--Time between hit noises
hitnoisedelay=100

--Minimum collision speed to make noise
hitthreshhold=3
lasthitnoisetime=0
hitnoisetimevariation=50
maxhitsources=10

--Load some noises to play
hitnoise={}
hitnoise[0]=LoadSound('abstract::impact_metal12.wav')
hitnoise[1]=LoadSound('abstract::impact_metal13.wav')
hitnoise[2]=LoadSound('abstract::impact_metal07.wav')

material_dust=LoadMaterial('abstract::dust.mat')

--Spawn entity
function Spawn(model)
local entity=base_Spawn(model)
return entity
end

--Add collision noise
function Collision(model,entity,position,normal,force,speed)
       local entity=entitytable[model]
       local time,i
       if fw~=nil then
               listener = fw.listener
       else
               listener=GetGlobalObject("listener")
       end
       if EntityDistance(listener,model)<30 then
               if speed>hitthreshhold then
                       time=AppTime()
                       if time-lasthitnoisetime>hitnoisedelay then

                               --Check how many impact noises are already active
                               local countsources=0
                               for i=0,2 do
                                       if hitnoise[i]~=nil then
                                               countsources=countsources+hitnoise[i]:ActiveSources()
                                       end
                               end

                               --Only emit a sound if there are fewer than the allowed max sources
                               if countsources<maxhitsources then
                                       i=math.random(0,2)
                                       if hitnoise[i]~=nil then
                                               entity.model:EmitSound(hitnoise[i],30,1.0,0)
                                       end
                               end

                               lasthitnoisetime=time+math.random(0,hitnoisetimevariation)
                       end
               end
       end
end

 

This is only a very basic example using framewerk.

 

post-12-12607918801166_thumb.jpg

 

Hope this is of some help to someone.

  • Upvote 4

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

This is very helpful MG, thanks a lot! :blink:

No need to include engine.h?

 

 

not in the code. Its added by the wizard to the project and included from framewerk.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

I was having some problems with my existing project so I did what you suggest; I started a new c++ project using the wizard and replaced the code in my main.cpp file by yours, adjusting the abstract path and loading my sbx file. The code compiles fine, however the program crashes (segfaults) after not finding some textures. This is the message in the console:

Loading shader "f:/exer/projects/plazoleta/shaders/postfilters/postfilter.vert",
"f:/exer/projects/plazoleta/shaders/postfilters/ssao.frag"...
Warning: Failed to load texture "abstract::wobbledot3.dds": Path not found.
Warning: Uniform "aosizereduce" does not exist in shader.

 

However, if I check in all of leadwerk's folders and .pak files there's no such texture. :blink:;)

Do you know where it is trying to load this from?

Win8.1 Pro X64/ Intel core I7 @ 3.5GHz / 32GB DDR3 SDRAM / GeForce GTX 660+760/ VC++ Express 2013/ Blender /Unwrap3dpro3 /Modo 8

Link to comment
Share on other sites

hi afecelis

from MG post :

 

"*You will need to make sure you have wobbledot3.dds in the materials folder in your SDK folder. I found without it, using emitters in a scene will casue the app to crash on loading. I am not sure if 2.3 comes with this file and my download just missed it, or its not included. I took mine from a previous install. Simply place it in the root of the materials folder."

 

look in older version of SDK

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

argggghhh! I read everything but that, hahahah. I'm checking in an older version now. Does 2.19 have it? I want to get one of the ones in a zip file rather than an installer.

Thx Diedir.

Win8.1 Pro X64/ Intel core I7 @ 3.5GHz / 32GB DDR3 SDRAM / GeForce GTX 660+760/ VC++ Express 2013/ Blender /Unwrap3dpro3 /Modo 8

Link to comment
Share on other sites

OMG OMG OMG OMG! It works! Marleys Ghost you have popped my Framewerks cherry, looool! :blink: I had never used it before, it's wonderful!

Now I got to learn how to start turning things on and off. I'm getting the whole shebang; skybox, godrays, hdr, bloom, etc. And after I move a bit my scene becomes totally wahsed out, as in the overbright issue we discuseed earlier in the forums, So I'll have to start by turning HDR off. But it looks so beautiful! darn am I excited! ;)

 

as it starts:

framewerk_01.jpg

 

"overburned"

framewerk_02.jpg

 

Edit: I already found where to set the features on and off:

// Setup Initial Post Processing FX
       fw.GetRenderer().SetGodRays(1);
       fw.GetRenderer().SetHDR(0);
       fw.GetRenderer().SetSSAO(1);
       fw.GetRenderer().SetBloom(1);
       fw.GetRenderer().SetAntialias(1);
       fw.GetRenderer().SetReflectionRenderComponents(ENTITY_RENDERABLE);

 

nice code! ;) I'm going to try and assign some keys to each effect.

 

Thanks for this post MG. it should be "stickified". It's a shame that enabling HDR causes the overbrightness. Is it fixable or planned to be fixed?

Win8.1 Pro X64/ Intel core I7 @ 3.5GHz / 32GB DDR3 SDRAM / GeForce GTX 660+760/ VC++ Express 2013/ Blender /Unwrap3dpro3 /Modo 8

Link to comment
Share on other sites

The HDR bug can be fixed, but requires GLSL knowledge and some trial and error in the HDR shaders. I couldn't tell you how I fixed it, it just stopped occuring after I messed around a bit.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Yup, I'm still so not there :( But disabling HDR+Bloom did the trick and still looks quite nice, hehehe ;) So while I learn how to fix it or it gets fixed officially there shall be no "oblivionish" arch-vis hahahaha :)

Win8.1 Pro X64/ Intel core I7 @ 3.5GHz / 32GB DDR3 SDRAM / GeForce GTX 660+760/ VC++ Express 2013/ Blender /Unwrap3dpro3 /Modo 8

Link to comment
Share on other sites

Any chance of an .exe?

 

Robin

 

 

Yes, while in VC++ 2008 hit ctrl + F7 ;)

 

 

Seriously though, you will need to add to the code your SDK path and what ever name you want to use for your map. Plus an .exe of this would not allow you to turn on/off any of the Post Processing FX.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

  • 3 weeks later...

MG, any updates to the code after the latest 2010 sync? :D

 

 

Well, to be honest am now concentrating on Bmax, have not even looked at C++ for weeks. Give me a couple of minutes to see if I can stitch something together for you afecelis.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Using VC++ 2008 Express

 

Use the 2.3 Project Wizard to create a new project

 

I simply called the example "sceneloading" (again ...)

 

Delete the generated example code in sceneloading.cpp

 

Replace with the following code:

 

 

#include "engine.h"

int main(int argc, char** argv)
{
Initialize();
RegisterAbstractPath("PATH TO YOUR SDK FOLDER");
Graphics(800,600);

AFilter() ;
TFilter() ;

TFramework framework=CreateFramework();
TLayer layer = GetFrameworkLayer(0);
TCamera cam=GetLayerCamera(layer);
PositionEntity(cam,Vec3(0,0,0));

//Set Lua variable
BP L=GetLuaState();
lua_pushobject(L,framework);
lua_setglobal(L,"fw");
lua_pop(L,1);

// Setup Initial Post Processing FX
SetGodRays(1);
SetHDR(1);
SetSSAO(1);
SetBloom(1);
SetAntialias(1);
SetStats(2);

LoadScene("abstract::YOUR_SCENE.sbx");

// Setup spectator
TBody spectator=CreateBodySphere();
SetBodyMass(spectator,1);
SetBodyGravityMode(spectator,0);
SetBodyDamping(spectator,1.0);
EntityType(spectator,3);
SetBodyBuoyancyMode(spectator,0);
PositionEntity(spectator,Vec3(0,5,-10));

TVec3 camrotation=Vec3(0);
float mx=0;
float my=0;
float move=0;
float strafe=0;

HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

// MAIN LOOP
while (!KeyHit(KEY_ESCAPE))
{

mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
my=Curve(MouseY()-GraphicsHeight()/2,my,6);
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

camrotation.X=camrotation.X+my/10.0;
camrotation.Y=camrotation.Y-mx/10.0;
RotateEntity(cam,camrotation);

move=KeyDown(KEY_W)-KeyDown(KEY_S);
strafe=KeyDown(KEY_D)-KeyDown(KEY_A);
TVec3 force = Vec3(strafe*10.0,0,move*10.0);
force=TFormVector(force,cam,0);
AddBodyForce(spectator,force);

PositionEntity(cam,EntityPosition(spectator));

// Update timing and world
UpdateFramework();

// Render
RenderFramework();

// Send to screen
Flip(0) ;
}

return Terminate();
}

 

Copy to the sceneloading project folder

 

engine.dll

newton.dll

shaders.pak

Scripts folder

 

from your 2.3 SDK folder

 

 

Create a scene and save it in the maps folder in your SDK folder. Should work, but I am having a few beers :D so address all complaints to .. erm ... Macklebee :)

  • Upvote 3

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

hey! what the... :D:)

 

 

Thats him .. just hit the PM button to complain lol

  • Upvote 1

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

hahahaha, you guys rule! best thing is that you both are the ones that save my back both in C++ and bmax! :D:) I wonder what will happen now that MG has joined the dark forces of bmax coding, mmmm....mmmmm hahahah!

 

Marleys, the latest code you posted is working perfectly alright. Thanks a lot. Please keep on drinking some more beers and give the bmx code a look too. Cheers!

have some beers on us. Prost!

Win8.1 Pro X64/ Intel core I7 @ 3.5GHz / 32GB DDR3 SDRAM / GeForce GTX 660+760/ VC++ Express 2013/ Blender /Unwrap3dpro3 /Modo 8

Link to comment
Share on other sites

I wonder what will happen now that MG has joined the dark forces of bmax coding, mmmm....mmmmm hahahah!

 

 

Well hopefully I will get a black helmet and matching cape .. and be able to choke people from a distance :D

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

always thought of you more of golden bikini type... but maybe thats just me :)

 

 

I reiterate ... "and be able to choke people from a distance" :D:D

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

I made a simple sbx with a terrain (no tex) and an oildrum.

When I start my program using your "scene loading" example a get an unhandled exception.

My debug output return the following warnings:

 

Loading shader "zip::D:/projekte/games/test1/shaders.pak//postfilters/postfilter.vert", "zip::D:/projekte/games/test1/shaders.pak//postfilters/ssao.frag"...

Warning: Failed to load texture "abstract::noise.dds": Path not found.

Warning: Uniform "aosizereduce" does not exist in shader.

 

Any idea?

 

Thanks

Andi

 

Found the texture in Materials/Effects folder but I'm still having the error....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...