Archive for the ‘Tutorials’ category

TexturePacker Extension for ShiVa 3D

January 14th, 2013

UPDATE: TexturePacker 3.0.6 comes with a separate Shiva 3D output format. I updated the post to reflect these changes as well as some other workflow optimizations.

My first product got published on the ShiVa Asset Store: an extension to support the awesome program TexturePacker by Andreas Löw. If you don’t know of it yet, check it out at http://www.codeandweb.com/texturepacker. Here is a screen shot of the supplied demo, showing off all the supported features:

demo

Features

  • No need to build your atlas by hand, TexturePacker does the work for you :)
  • Texturize Models
  • Texturize HUD Components

Usage

texturepackerExport

  1. Create your atlas with TexturePacker:
    • Data Format is “Shiva3D“.
    • Texture Format is TGA.
    • Allow Rotation” is only supported for texturing Models. HUDs are not supported!
    • Trim Mode is “None“.
    • Press the “Publish” Button. This will create 2 files: an XML and a PNG.
  2. Import the XML and the PNG via the Data Explorer into Shiva and add them as Resources to your game:
    importTexture  importXml

    1. Workflow Optimization: if you want to skip the importing, configure your output paths to the shiva resources folder directly! I only tested this once the resources was already created though.
  3. If texturing a Model, create a Material with the same name as the texture, configure it such that it uses the texture and also add it to the Resources of your game.

You are now ready to use the atlas!

 

Here is some example code:

local hUser = application.getCurrentUser ( )
 
application.setCurrentUserScene ( "TexturePacker" )
 
--Load atlas data:
--Use sendEventImmediate!
user.sendEventImmediate ( hUser, "TexturePacker", "onLoadAtlas", "atlasTexturePacker" )
--user.sendEventImmediate ( hUser, "TexturePacker", "onLoadAtlas", "otherAtlas" )
 
--Texturize Model via code:
user.sendEventImmediate ( hUser, "TexturePacker", "onSetObjectTexture", application.getCurrentUserSceneTaggedObject ( "obj8" ), "tp05" )
user.sendEventImmediate ( hUser, "TexturePacker", "onSetObjectTexture", application.getCurrentUserSceneTaggedObject ( "obj1" ), "tp01" )
user.sendEventImmediate ( hUser, "TexturePacker", "onSetObjectTexture", application.getCurrentUserSceneTaggedObject ( "obj2" ), "tp02" )
 
--Or use Object AI "TexturePackerAI" (done for obj3 and obj4)

 

Best you take a look at the supplied TexturePackerDemo.
Set your viewport to Android Landscape (800×480) for best results.

Here’s a snapshot of a little game I’m currently working on, utilizing the TexturePacker extension (every texture is coming out of an atlas):

overview

Feedback is welcome!

And once again, the link to the ShiVa Asset Store: http://www.shivaengine.com/store/aimodels/132-texturepacker-ai.html.

Box2D-Shiva-Wrapper: Compiling Box2D As Plugin

May 16th, 2012

I will write which stones I fell over during the process of getting Box2D to compile as a ShiVa-Android-plugin. This could also be useful for anybody who wants to use STL on Android.

Disclaimer: I am far no C++, build or make file guru. If you spot anything, which could be done better, please tell me (I am willing to learn).

Enabling STL

First, modify the MyPlugin.makefile (located in “/ShiVaEditor/Data/PluginTemplate/Make/Android/”) such that CPPFLAGS looks like this:

CPPFLAGS            = -fno-rtti -I"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/include" -I"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include"

Then in ShiVa, regenerate your Android plugin makefile and click on recompile (RE-compile, not compile). If everything works out right, you should see the red circle next to the android plugin turned green:

Now you’re ready to export!

Export your game with the Android profile selected. This is important, because when using plugins, only the selected profile version of the plugin is packed into the STK. So if you export with the DefaultProfile, the Android plugin will probably be missing! Note: After exporting, you can always look at the yourgame.xml to see what files are packed into the STK. Just open it with your browser.

With the freshly exported STK, now create an Android project with UAT. Unzip it’s contents and make the following changes to these two files:

root/build.xml:
Add the line

APP_STL			 := gnustl_static

to where the Application.mk is defined (2 spots in the build.xml: for release and debug).

root/jni/Android.mk:
Add the line

LOCAL_LDLIBS           += -lgnustl_static

after the last LOCAL_LDLIBS assignments.

Now compile the build.xml and hope that everything works :) I have come accross some weird build errors, they are handled in the next section.

Credits to this whole procedure go to supernat on this thread in the ShiVa forum! In case you want to use STLPORT instead of GNUSTL, you can see what changes need to be made over at the forum. I stuck with GNUSTL. Also big thanks to Dominik from StarkApps.

Box2D Specific Modifications

Precompiled Headers

I don’t really have a clue, what precompiled headers do (nice rhyme eh?), but I managed to get them to compile. In the end, I had to add a #include "PrecompiledHeader.h" to nearly every Box2D source file (the compiler gave some tips/warnings that I must do so). As I had done this, the plugin started to compile for Windows. For Android, I got some weird error like “error in algorithm” or “error in stdlib.h”, which were quite misleading.

In the end, I simply MOVED the failing include statements to the precompiled header file (meaning removing them from the Box2D sources and adding them to the precompiled header file), leading to these additional include statements in the precompiled header file (~ stands for < or > …had some trouble with html editor):

#include ~stdlib.h~
#include ~cstdlib~
#include ~cstdio~
#include ~cstdarg~
#include ~climits~
#include ~cstring~
#include ~memory~
#include ~algorithm~

The funny thing now is, there’s a precompiled header file for each platform and I only added these includes to the windows one. I actually don’t know why this is working on Android, but sometimes you just have to stop asking questions :) If anybody out there has an idea, please tell me.

b2BroadPhase And std::sort

The file b2BroadPhase.h has a call to std::sort, which the Android compiler complained that he can’t find. Looking at the GNUSTL headers/templates, it read like that for GNUSTL, this isn’t in the std namespace … but I’m not sure about that one. Reading headers and templates in notepad++ isn’t a good idea with all those macros and defines. For the first version, I just commented the line out, as it’s just a performance optimization anyway.

Includes

Don’t use backslashes in include statements, use slashes! Meaning don’t write #include "Box2D\Box2D.h", instead write #include "Box2D/Box2D.h". Not sure if this would have also failed on Android, but on iOS it raised an error.

 

That was it for now. I’ll keep updating the issues list as I keep working on it and maybe I’ll have some insights on the unclear points.

MASH-up

May 25th, 2011

Today we released the first iteration of MASH, the “Modern Alchemists ShiVa Libs”:

Modern Alchemists ShiVa Libs is a bundle of custom written ShiVa addons. All projects rely on ShiVa 1.9 and UAT 1.2 beta 7. This doesn’t mean it won’t work with older versions, but the docs might refer to code hockups which weren’t present back then.

All code is under LGPL License. If you like our work, tell us! If not, tell us even more! Got a code fix? Tell us… you get the idea ;)

It features:

  • MASS: In-App-Purchase for iOS and Android
  • MAOF: OpenFeint for iOS and Android
  • Mortar (TBA): automating the world!

You can get all the files/code either from the download section or via SVN at  google code: http://code.google.com/p/ma-sh/

Android: Could not reserve enough space for object heap

April 15th, 2011

If you ever get an error like
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

or
BUILD FAILED
...ant_rules_r3.xml:361: The following error occurred while executing this line:
...ant_rules_r3.xml:174: apply returned: 1
,
don’t let yourself get fooled about some threads found on google.

The answer why your VM crashes is, that the heap space trying to be allocated is not free in physical memory.

That means: try to decrease the setting for max heap space in the file android-sdk-windows/platform-toolsdx.bat to smaller value. I had to change it to 512M instead of 1024M, meaning:
set defaultMx=-Xmx512M

And tada, off you go!

Drag and drop install APK script

September 30th, 2010

Update April 5th 2011: since the latest Android SDK, the adb tool has been moved to the platform-tools folder. I updated the script to point to the correct directory.

If you want to be able to just drag and drop your APK file onto a CMD file, and let it be installed on the connected device automatically, use something like this (simply copy this to your *.cmd file):

New:

:: Just some debug output:
echo Attempting to install file: %1
 
:: Enter drive letter:
d:
 
:: Enter path to adb here:
cd D:\android_sdk on 10.17.1.205\platform-tools
 
:: Install file:
adb install -r %1
PAUSE

Old:

:: Just some debug output:
echo Attempting to install file: %1
 
:: Enter drive letter:
d:
 
:: Enter path to adb here:
cd D:\androidsdk\tools
 
:: Install file:
adb install -r %1
PAUSE

PS: Of course one could use set varNAme=__PATH__ instead of the cd-ing, but my path has some spaces and that leads to troubles.