Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon Join the GFS Discord Server!
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


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


28. April 2012

 

Somewhere between 2.63RC and 2.63 release the Knife tool was changed so that you need to press Enter or Spacebar to commit the changes.  Previously you could commit using the right mouse button, which I preferred.  Lucky enough, it is easily addressed.

 

In Blender, selected the menu File->User Preferences…

 

Switch over to the Input tab, expand 3D View->Mesh then Knife Topology Tool then finally expand Knife Tool Modal Map, like such:

 

image

 

First we need to delete the existing Right Mouse binding, locate it and click the X to the right:

 

image

 

Now scroll down ( within the Knife Tool Modal Map panel) and locate the Add New Button:

 

image

 

 

 

It will insert a new empty record like such:

 

image

 

Expand the arrow to the left of our newly added entry, and it fill it in as follows ( or set by right clicking to the right of the Mouse dropdown):

 

image

 

 

Now locate the Save as Default button in the button left corner of the Window and click it:

 

image

 

Voila, right click should now cause your cuts to commit when you right click.

Art


27. April 2012

 

 

This is the release of Blender I have been waiting a long time for, as this is the release where BMesh has finally been integrated into Blender!  For those of you unaware of what exactlyblender_263 BMesh brings to the table, take a quick look at this post.  Having worked in Wings for so long, and Nendo before that, I have been dying to see ngon support added to Blender.

 

 

 

Expect things to be a bit buggy for a while, the switch to the BMesh engine is a pretty massive change.  That said, expect to see new and more powerful tools coming out, as in many ways BMesh impacts Blender developers as much as it does end users.

 

 

KnifeTool

 

 

 

However, it isn’t only about BMesh.  Cycles has also received a lot of love in the 2.63 release, with new rendering passes for Ambient occlusion and shadows, as well as a mask layer for “masking out” objects in the scene.  Environment mapping has also been improved to support float precision textures.  A mirror ball project mode has been added as well, but frankly, I don’t really understand the use.  Additionally, there is now a panoramic camera, which will render a panoramic view of the scene around the camera’s location.  There have also been improvements to viewport rendering, allowing it to show background images as well as the ability to show the currently active rendering layer in the viewport.

 

 

There are other features as well, including the ability to hide portions of geometry while sculpting, a very handy feature.  There were some additions to the motion tracking tools, as well as over 150 bug fixes.

 

 

One of the biggest releases in a very long time and the one I’ve been most eager to receive.  Kudos to the Blender team for this excellent release.

 

Go download it now!

Art News


20. April 2012

 

 

As you may have noticed, I am somewhat excited about the addition of BMesh into the main Blender trunk in the upcoming release.  What you may be wondering is why? In the past I explained what an ngon is, but without seeing them in action their benefit can be a bit hard to understand. 

 

So that is exactly what this post is going to cover, it will demonstrate the new functionality that will be available in Blender 2.63 once BMesh support is added.  Each animated image is actually 1080p in size, so click on it to see more details.  Some of these features, such as the bridge edge tool, aren’t specific to ngons specifically ( and could be accomplished without BMesh ), however the internal changes to support BMesh made adding these features more feasible.

 

 

 

 

 

Dissolving face/edges/vertices

 

Disolve

 

 

What are we seeing here?

 

Coupled with the knife tool, this is easily the biggest feature of BMesh.  Instead of simply deleting faces, vertices and edges, you can now dissolve them, which effectively turns the selection into a single giant ngon.  Therefore you can add detail where you need it, or quickly remove it where you don’t.  With traditional triangles/quads, retooling a mesh was an arduous process of deleting faces/vertices then rebuilding them one quad/tri at a time.  Now with BMesh it’s a heck of a lot easier.  One word of warning though, just because you can do something doesn’t mean you should! 

 

Dissolve can result in some really funky geometry, especially if what you are dissolving isn’t planar.  In the end, when it is sent to the renderer, it is still triangulated, so if you have dissolved into an impossible shape, you will get some weird artifacts.  That said, some time with the knife tool can quickly fix up most problems.  One thing to remember, BMesh does not replace the need for a good topology!  It may make things easier, but in the end the same basic modeling principles hold true.

 

One last note, dissolve works slightly different based on if you have edges, faces or vertices selected.

 

How do you do it?

 

In edit mode, select your geometry.

Hit ‘x’.

Select dissolve.

 



Knife Tool

 

KnifeTool

 

 

What are we seeing here?

 

The other major part of BMesh is the knife tool.  There is a knife tool in Blender 2.5x but it’s fairly awful.  First it has to tessellate as it goes because of the 3-4 vertices per face limit.  The new knife tool is much more capable and flexible and as you can see from the image above, can make pretty arbitrary cuts with ease.  Again though, good topology is still important, so use the knife with care!

 

How do you do it?

 

In edit mode, press K.

A green dot will appear where the cut will appear.

Left click to make cut, move mouse and repeat.

Right click to complete.

 



CTRL + Knife Tool ( centered cut )

 

CTRLKnife

 

 

What are we seeing here?

 

Quite often you want to cut at the halfway point, this is exactly what cutting with the Control key pressed down will do.  The green dot will snap to the halfway point between the two nearest vertices.

 

How do you do it?

 

Exact same process as the knife tool, just hold down CTRL to snap to midpoint.

 



Creating > 4 sided faces

 

CreateFace

 

 

What are we seeing here?

 

On of the big pains of working with polygons in Blender before was manually recreating faces.  You had to select 3 or 4 vertices in order then hit the F key, repeating for every polygon you need to create.  Now, select the bordering edges or vertices, regardless to their count and it will create a single ngon, which can be extrudes, scaled, etc… like a normal face.  Just like dissolve though, it is quite easy to create “bad” geometry.

 

How do you do it?

 

In edit mode, select bordering vertices or edges.

Press F to build ngon.

 



Bevel ( finally! )

 

Bevel

 

 

What are we seeing here?

 

Blender 2.4x has a bevel, 2.5x replaced it with an awful modifier that I don’t think anyone was happy with.  Now, with BMesh, bevel is back!  It can be a bit buggy at times, especially with multiple edges selected and can result in some strange cornering geometry, but its really nice to see bevel back.   Bevel basically allows you to add more geometry evenly spaced and rounded, normally used for rounding corners.

 

How do you do it?

 

In edit mode, select 2 or more consecutive vertices, or one or more edge or face.

Hit spacebar, type “Bevel”. Click Bevel in popup menu.

On the left hand Mesh Tools menu ( hit T if not open ), select percentage or recursion level.

Percentage determines how big bevel is ( relative to next closest edge/face/vertex )

Recursion level determines how many times the bevel will be performed ( number of edges created )

 



Inset/Outset face(s)

 

insetoutset

 

 

What are we seeing here?

 

Inseting is basically identical to doing a zero distance extrude followed by a scale, but much easier.  Think of it kind like creating an edge loop, but instead its relative to the selected edges.  Inset causes the new geometry to be created within the selected geometry, while outset causes the geometry to be created surrounding selected value.  The above image illustrates an inset, followed by an outset.

 

How do you do it?

 

In edit mode, select the face.

Hit spacebar, type “Inset face”, select menu item.

In the tools panel, thickness slider determines the amount it is offset.

Check outset if you wish to outset instead of inset.

 



Bridge Edge tools

 

bridge2

 

 

What are we seeing here?

 

This functionality was actually available via the loop tools plugin, but it’s nice to see it part of the main application.  Select two edge loops (within the same/connected mesh ) and it will create a “bridge” between those two points.  Sadly it doesn’t delete the interior face, so be sure to delete the face before bridging.

 

How do you do it?

 

In edit mode, select two edge loops.

Hit spacebar, type ‘Bridge Two Edge Loops.

Note! Both edge selections need to have the same number of edges.



See More Tutorials on DevGa.me!

Month List