Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

30. April 2012

 

BlenderOnVita

We are now going to look at creating a fully textured model in Blender and exporting to a PlayStation Studio SDK project, a simple model viewer.  We create a very simple model, UV map, texture then export it.  At this point, we process it using the PS Studio ModelConverter tool, import it into PS Studio then finally run our code in the simulator.

 

The example model is as I said, brutally simple ( it’s simply a dice, er… die, also known as a textured cube ). However the process for exporting more complex models is exactly the same.  The process isn’t really all that difficult, especially if you know your way around Blender, but if you don’t know Blender all that well don’t worry, I’ve actually captured the entire process in video form.  This video covers exactly the same thing that the rest of this tutorial does, so if you have problems following one, refer to the other and vice versa.

 

 

Modeling, texturing and exporting from Blender to Sony PlayStation Suite SDK in under 5 minutes

 

 

The above video is actually encoded at 1080p and is probably almost illegible at anything less than 720p.  You can watch it on YouTube or Vimeo in full definition.  Again, the video demonstrates exactly what I am going to show below, except the source code.  So if you are the type that prefers to learn by watching, or the type that learns by reading, you get the best of both worlds here!  Alright, let’s get started.

 

 

If you already know how to model, texture and export in COLLADA format using Blender, I suggest you skip ahead to part 2, as the remainder of this section will be quite boring for you… it goes into detail, a lot of detail. Smile

 

 

If you haven’t already, fire up Blender.  We are going to work with the default cube, if you don’t have a default cube select the Add menu –> Mesh –>Cube.  The first thing we want to do is create a new image to texture our model.

 

In the properties panel to your right ( assuming you are using the default layout, which I will for the remainder of this tutorial ), locate the Textures tab and click it.  Like such:

 

image

 

 

Now change “Type” to Image:

image

 

Scroll down slightly to the Image section ( expand it if required ) and click New:

image

 

In the resulting dialog, we specify the texture details.  I am going to name it the ultra imaginative name “Texture” but fell free to call it whatever you want.  1024x1024 is massive overkill for what we are doing, but hey… I like overkill.  When done, click OK.

 

image

 

Now we want to apply some simple texture mapping to our 3D cube.  In the 3D view, make sure you are in “Edit Mode”, either by hitting Tab until selected, or via this menu:

image

 

Now that you are in edit mode, select all the faces of your mesh by hitting “a”.  Now in the Mesh menu, you want to select Mesh->UV Unwrap…->Follow Active Quads.

image

 

Simply click OK at the resulting dialog menu.  Now we want to switch to UV editing mode.  Locate the icon to the bottom left of your view, click it and select UV/Image Editor.

image

 

We now want to make our texture the active image.  Locate the “Browse image to be linked” button, click it and select texture from the list.

 

image

 

Now press A to select all of our faces, then using hit S to scale ( then mouse move, left click when done), followed by G to translate, until our UV coordinates are all over the black image, like so:

image

 

Now we want to quickly paint our dice faces on the texture within the UV coordinates.  From the menubar select Image->Image Painting.

image

 

Now left click to mouse paint the texture like the face of a die.  You can use the left hand panel ( press “N” if not visible ) to change the paint settings.  When done you should have something like this:

image

 

Now, back in the Image menu, unclick Image Painting.  Now we want to save our completed image.  In the same menu as before, select “Save as Image” or hit F3.  In the resulting dialog, locate the directory you want to save the texture to ( make it the same place you are going to save the model ), name it, then click Save as Image:

image

 

Now with that complete, we assign our image to our texture.  Back in the Texture panel ( to the right ), locate the Image section, click the Browse Image to be Linked button and select your texture.

image

 

Now scroll down lower in the Texture panel, locate Mapping, then select the Coordinates: dropdown and select UV.

image

 

Right below that, select the Map: dropdown and select UVMap.

image

 

 

 

All right, now we have a fully texture mapped model ready for exporting.  From the File Menu ( top right ), select File->Export->COLLADA(.dae).

image

 

 

In the resulting dialog, navigate to the same location where you saved your texture, name it ( I used box.dae ), optionally select “Export only selected” then click Export COLLADA.

 

image

 

 

And we are now done with Blender.

 

 

This section has already gotten quite long so I am going to break this post into two parts.

 

 

Continue on to Part 2.

Programming, Art , , , ,

30. April 2012
BlenderOnVita

 

This is part 2 of our series looking at getting a fully textured model from Blender to the PlayStation Vita, or at least, the simulator.

 

In part 1 we created and exported our textured model, a simple 6 sided die.  Now we are going to convert it into a format the PlayStation Suite can make use of.  To do this, we make use of a command line tool called ModelConverter. ModelConverter was installed when you installed the PSSDK.  If you haven’t already installed it, go install it now.  For details about what is installed by the SDK and where take a look at this post.  I will assume you installed to the default drive and directory, if you haven’t adjust your directories accordingly.  If you aren’t using a 64bit copy of Windows, it is Program Files instead of Program Files (X86).

 

 

ModelConverter is located at C:\Program Files (X86)\SCE\Pss\tools\ModelConverter, open a dos prompt and CD to that directory.  Now you want to run modelconverter and point it at your dae file.  I saved mine ( and associated textures ) in c:\temp, so I run “modelconverter c:\temp\box.dae”.  The results should look like:

 

image

 

( ModelConverter can handle Fbx, dae, xsi and x file formats ).

 

You have now created a new file named Box.mdx, in the same folder as your COLLADA file.  We now want to use this model in PlayStation Suite Studio.  Let’s fire it up, and create a new solution called ModelViewer.  If you don’t know how to create a project using PS Suite Studio, take a quick look at this post.  Now that we have our project, double click AppMain.cs and enter the following code (replacing whatever is there already):

 

using System; using System.Collections.Generic; using Sce.Pss.Core; using Sce.Pss.Core.Environment; using Sce.Pss.Core.Graphics; using Sce.Pss.Core.Input; using Sce.Pss.HighLevel.Model; namespace ModelViewer { public class AppMain { private static GraphicsContext graphics; private static BasicModel model; private static BasicProgram program; private static float cameraAngleX = 0.0f; private static float cameraAngleY = 0.0f; public static void Main (string[] args) { Initialize (); while (true) { SystemEvents.CheckEvents (); Update (); Render (); } } public static void Initialize () { // Set up the graphics system graphics = new GraphicsContext (); program = new BasicProgram(); model = new BasicModel("/Application/box.mdx",0); } public static void Update () { // Query gamepad for current state var gamePadData = GamePad.GetData (0); if((gamePadData.Buttons & GamePadButtons.Up) != 0) cameraAngleX += 1.1f; if((gamePadData.Buttons & GamePadButtons.Down) != 0) cameraAngleX -= 1.1f; if((gamePadData.Buttons & GamePadButtons.Left) != 0) cameraAngleY += 1.1f; if((gamePadData.Buttons & GamePadButtons.Right) != 0) cameraAngleY -= 1.1f; if(cameraAngleX < 0.0f) cameraAngleX = 360.0f; if(cameraAngleX > 360.0f) cameraAngleX = 0.0f; if(cameraAngleY < 0.0f) cameraAngleY = 360.0f; if(cameraAngleY > 360.0f) cameraAngleY = 0.0f; } public static void Render () { // Clear the screen graphics.SetClearColor (1.0f, 1.0f, 1.0f, 0.0f); graphics.Clear (); Matrix4 projectionMatrix = Matrix4.Perspective(FMath.Radians(45.0f),graphics.Screen.AspectRatio, 1.0f, 100000.0f); Matrix4 viewMatrix = Matrix4.LookAt( new Vector3(0.0f,5.0f,5.0f), new Vector3(0.0f,0.0f,0.0f), new Vector3(0.0f,1.0f,0.0f)); Vector3 litDirection = new Vector3( 0.5f, -1.0f, -1.0f ).Normalize(); Vector3 litColor = new Vector3( 1.0f, 1.0f, 1.0f ); BasicParameters parameters = program.Parameters; parameters.Enable(BasicEnableMode.Lighting, true); parameters.SetViewMatrix(ref viewMatrix); parameters.SetLightCount(1) ; parameters.SetLightDirection(0, ref litDirection); parameters.SetLightDiffuse( 0, ref litColor); parameters.SetLightSpecular(0, ref litColor); parameters.SetProjectionMatrix(ref projectionMatrix); Matrix4 world = Matrix4.RotationXyz(FMath.Radians(cameraAngleX),FMath.Radians(cameraAngleY),0.0f); graphics.SetViewport(0,0,graphics.Screen.Width,graphics.Screen.Height ); graphics.Enable(EnableMode.Blend); graphics.Enable(EnableMode.CullFace) ; graphics.SetCullFace(CullFaceMode.Back, CullFaceDirection.Ccw) ; graphics.Enable(EnableMode.DepthTest); graphics.SetDepthFunc(DepthFuncMode.LEqual, true); model.SetWorldMatrix(ref world); model.Update(); model.Draw(graphics,program); graphics.SwapBuffers (); graphics.Disable(EnableMode.CullFace); graphics.Disable(EnableMode.DepthTest); } } }

 

 

EDIT: You also need to add a reference to Sce.Pss.HighLevel.Model.  If you don’t know how to add a reference, refer to this post.

 

 

I am not going to go into a ton of detail about the code for two reasons.  One, its mostly just a stripped down version of the BasicModelSample included in the SDK and two, I am going to cover 3D in a bit more detail in a later tutorial.  So here is the ultra quick version of what’s happening.

 

In Main, we have our primary event loop, which calls Inititalize(), then simply loops forever, getting events, then calling Update() and Render().  Initialize sets up our required objects, the GraphicsContext, BasicProgram and most importantly, our BasicModel.  The parameter to the BasicModel is the file path to where our mdx file is stored ( after being imported into Studio, not on your hard drive ).  If you named your model anything other than box.dae, you need to change it here!

 

Next up is Update(), which is called once per frame before drawing.  All I am doing here is checking the status of the gamepad ( not the analog pads ) and if it is up or down, I set the cameraAngleX variable to increment or decrement 1.1 degrees in that direction.  I do the same thing then for left and right, this time updating the variable cameraAngleY.  Finally I make sure that we aren’t trying to rotate more than 360 degrees, or less than 0 degree.  For more details on handling input, see here.

 

Next we come to Render, which is responsible for drawing the frame to the screen.  First we set up the required viewing matrixes for our screen, create a light and a BasicParameters object that is going to tell our renderer how to render ( via program ).  The lighting details are part of this parameters object, as are our view and projection matrix.  Next we set up our world matrix, representing “our” or more accurately “our camera’s” location in the world, by transforming it relative to our rotation values we set with earlier in update. This effectively rotates the camera relative to our two rotation variables.

 

Finally we set up our graphics object, which is actually used to render our scene.   Set the various rendering options, update our model using our world matrix, render the model via it’s Draw() method, passing in our graphics and program object ( which contains are parameters object ).  Finally we tell it to SwapBuffers, which causes the scene we’ve been rendering to be displayed on screen.

 

I know that grossly glossed over what was happening here, but to go into much more detail would require a couple dozen more pages.  We will cover this stuff later, I promise.

 

 

Ok, now that we have code capable of displaying our model, we need to import it into Studio.  In the Solution window on the left hand side of Studio, right click the ModelViewer project and select Add Files…

 

image

 

 

In the resulting dialog, select your model and texture, in my case box.dae and dice.png.  Click Open.

 

image

 

Once you have selected your file, the following dialog will appear:

 

image

 

Choose “Add a link” if you want to keep your modeling project separate from your code, this personally is what I do.  The nice thing with this setup is if you run modelconverter on your model again, the changes are automatically updated in Studio.  If you choose copy, you will have to reimport each time you change.  The choice ultimately is yours.

 

 

Now is the very key part.  You need to tell PlayStation Suite Studio how to handle these files.  Your png texture will automatically be set right, but your mdx file will not.  Files are actually copied into different directory when your project is built, depending on if you are creating a debug or deployment build.  This is the “/Application” folder we saw earlier.  You need to tell PS Studio that your mdx file is a content file, and should be copied to the right folder when you do a build.  To do this, right click the file box.mdx in the Solution Viewer and select Build Action->Content, like such:

 

image

 

 

Now you should be able to run your application.  If everything worked properly, you should see the following.  Use the gamepad(arrow keys in simulator) to rotate the camera left, right, up and down.

 

 

BlendToPssResults

 

 

And now, you have successfully exported a fully textured model from Blender to a PlayStation Vita application!

 

 

One thing you may notice is your texture looks rather washed out, I found this as well, and currently am unable to figure out why.  The results are even worse when you export as FBX, while astonishingly your results are vastly improved exporting as X ( DirectX format ), as you can see below:

 

DifferentVersions

 

 

I am not completely sure what is responsible at this point, my code, Blender or modelconverter, but as it stands , X format gives basically identical results to what you started with in Blender.  Once I figure out what is responsible, I will update here.

 

 

That concludes how to export from Blender to PlayStation and trust me, it is nowhere near as complex as it looks.  As you can see in the video, the entire process takes less than 4 minutes.

 

EDIT:  Oops, forgot the project code.  Here is a zip of the project file.

Art, Programming , , , ,

30. April 2012

image

 

 

 

Research in Motion, of Blackberry and Playbook fame, recently released Gameplay 1.2, a cross-platform 3D game programming library aimed at Indie developers.  As a game maker, it is easy to ignore RIM these days, especially with their CEO making comments like:

 

"We plan to refocus on the enterprise business and capitalise on our leading position in this segment,"

 

That doesn’t exactly give you the warm and fuzzy about the future of RIM consumer devices now does it?

 

That said, ignoring GamePlay would be a foolish thing to do.  Why?

 

Well first off, it’s free.  I like free.  As in, I really like free.

 

Second and perhaps most amazingly, it is cross platform.  You can target Mac OS, Windows, iOS 5.0 or higher devices, Android 2.3 or greater devices in addition to Blackberry Tablet OS 2.0 and Blackberry 10 devices ( when they arrive ).

 

Third, it’s IDE agnostic, except when required otherwise ( aka, compiling for iOS ).  I can work in my preferred Visual Studio environment.  You however have the choice between Visual Studio, XCode or Momentics IDE ( an Eclipse based IDE Rim inherited from QNX ).

 

Fourth, it’s open source and hosted on GitHub.

 

Here is a screen shot from a demo game in development:

 

 

I have to say, it looks impressive to me.

 

 

Oh, did I happen to mention it’s C++ based?  I think I just heard half of you cheer, while the other half swore! Winking smile

 

 

I do have to say, the folks at Marmalade probably aren’t pleased.  They both fill the same niche… but gameplay is free.  Now the question is, how good is it?

 

Feature-wise, here is what you can expect:

 

Current features in gameplay
  • Written completely in C++ and well documented using doxygen.
  • Solution and workspaces for Visual Studio 2010, XCode 3.2.1 and Momentics IDE’s.
  • Platform-Game abstraction layer separating all operating system code from game engine code.
  • Input system support for Mouse, Keyboard and Touch.
  • Full vector math library with classes for Vector2/3/4, Matrix, Quaternion, Ray, Plane. Also Frustum and BoundingBox/BoundingSphere classes for object culling.
  • Solid OpenGL 3.2+ (for Desktop) and OpenGL ES 2.0 (for Mobile) based rendering system with classes for RenderState, FrameBuffer, Mesh, Material, Effect, Pass and Techniques.
  • Easy-to-use and efficient Font and Sprite classes.
  • Scene-graph components such as Scene, Node, Light, Camera and Model.
  • Binary encoding tool for creating optimized bundles for loading TTF fonts and 3D game assets supporting both COLLADA and FBX formats.
  • Extensible animation system with classes for Animation, AnimationClip and Curve with built-in AnimationTarget’s on Transform and MaterialParameter’s classes.
  • Complete 3D audio system with additional support for compressed audio using OGG and supporting HDMI gaming.

 

New features in gameplay v1.2
  • Newplatforms now supporting:
    • BlackBerry Tablet OS 2.0 and BlackBerry 10 ready!
    • Apple iOS 5.1 for iPhone and iPad
    • Google Android 2.3+
    • Microsoft Windows 7
    • Apple MacOSX
  • New shader-based material system with built-in common shader library.
  • New declarative scene binding.
  • New declarative particle system.
  • Improved physics system with rigid body dynamics and constraints.
  • New character physics and ghost objects.
  • Improved animation system supporting animated skeletal character animation.
  • New declarative user interface system with support for declartive theming and ortho, and 3D form definition with built-in core control classes such as Button, Label, TextBox, Slider, CheckBox, RadioButton. Also includes Layout classes such as Absolute/Vertical and FlowLayout.
  • New cross-platform new game project wizard scripts.
  • New game developer guide.
  • New game samples and tutorials.

 

 

With the following coming soon:

 

The ‘next’ feature branch for v1.3, v1.4, v1.5
  • Optimizations and Performance improvements
  • Shadows
  • Terrain and Sky
  • Gamepad input for Wii, Xbox 360 and Bluetooth® HID controllers
  • Scoreloop Social integration
  • Editor

 

 

Editor hmm?  Wonder what that means?

 

 

I am going to download and play with the SDK, and if I get some time ( something I am chronically short of lately ) I may post a walk around and possibly a tutorial or two.  Has anyone out there been playing with this technology?  Any opinions?

 

 

If you are interested, check out the announcement blog post as well as the source on GitHub.  Oh and perhaps most impressive of all for an open source gaming product… there is actually documentation. The documentation is available here including this development guide[direct pdf link].

 

I have to say, congratulations to Sean Paul Taylor and Steve Grenier on this impressive release!

General , , , ,

29. April 2012

 

 

One of the most bizarre things missing from the PlayStation simulator was support for analog imagesticks, or gamepad support in general.  I had just assumed that you would be able to plug a gamepad into your PC to control the simulator, but I was wrong.  A keyboard only solution made owning an actual device pretty much an absolute requirement.  Fortunately a user on the PlayStation Suite Developer Forums YamatoKei released a code driven solution, which in his own words:

 

 

 

The simulator's input layout and limitations weren't to my taste, so I made myself a way around it:

Run a TCP server that reads PC's gamepad state and sends it back on a client request. And add a simple utility class/lib to connect to that server + decode data transparently from within the game. With a one-line change to revert-back to using the native input on real devices.

Uploaded here: http://dl.dropbox.com/u/1969613/openglForum/PadServer.7z

Code to use:

static ILXPAD pad1 = new ILXPAD_Net();
//static ILXPAD pad1 = new ILXPAD_Vita();
...
pad1.start();
...
pad1.update();
...
camera.roty -= pad1.RStick.X;
bool jump = pad1.Cur.CROSS;

Cheers. :Wink:

 

Just what the doctor ordered!

 

[Download Link]

 

Buyer beware, I haven’t actually tried this out, so if it doesn’t work, destroys your computer or causes a horde of angry cows to raze your house, I take no responsibility.

Programming ,

29. April 2012

 

 

One of the biggest points of confusion for people new to Blender seems to be navigating the UI.  The UI layout of Blender is amazingly powerful but it is extremely easy to find yourself lost in a sea of windows and panels you’ve opened with no idea how to close them.  This video tutorial shows you how to customize the Blender layout exactly how you want it and once you get the gist of it, it is an extremely powerful system. The video is for Blender 2.59, but should be equally valid in 2.6x.

 

 


 

 

There is no audio, it is entirely narrated on screen.  The video is probably illegible in the embedded window above, however it was encoded at 1080p and hosted on YouTube and Vimeo in HD ( although for some reason the Vimeo encoding looks much worse, so use YouTube for the best quality ).

 

 

If you are just starting out with Blender, I highly suggest you check it out. Once you realize just how much flexibility you have in deciding how you want to work you will become much more productive.  Oh and if you are lucky enough to have multiple monitors, Blender is amazingly flexible in this regard too!

Art ,

Month List

Popular Comments