Activity Recognition on iOS

Posted on

Activity Recognition on iOS

I have implemented a service that allows to easily query about the current user activity (walking, running, cycling etc.) on an iPhone.

Services are ways to enhance your applications with additional code that has platform-specific implementation and may link with 3rd-party library. See more about iOS services and Android services. You declare them in CastleEngineManifest.xml and then just build your application using our build tool.

We now have a new iOS service called activity_recognition. A demo is inside the examples/mobile/activity_recognition subdirecory of the engine source. The demo is cross-platform, however it will not report any activity on other platforms than iOS for now.

The Pascal API is documented in CastleActivityRecognition unit (in particular see TActivityRecognition class).

Comment on this post ➤

We have a new joysticks database in Castle Game Engine, and we need YOU to help us test it

Posted on


Hello everyone!

We have a big and important, but simple request. We’ve reworked the handling of the joysticks and gamepads in Castle Game Engine, with a lot of new features that include serious improvement of joysticks API, access to a huge joysticks database by SDL2 with hundreds of joysticks definitions, autodetection of joysticks, detection of connection/disconnection of joysticks, etc.

However, because we have very limited access to hardware, we are unable to test how well those new features work. And therefore we need your help to test if everything is working as expected on different hardware joysticks/gamepads.

You can download and build “joystick” project from “examples” in this fork: It is not yet merged into CGE master, but of course it will be — that’s why we ask you to help with testing!

Ready precompiled binaries for Windows 64 bit and Linux 64 bit are here.

If you have access to a hardware joystick or gamepad, please use this tool and tell us (e.g. using forum):

  1. Your joystick name and operation system (Linux or Windows)
  2. Name your joystick was detected in Castle Game Engine

  3. If your joystick was correctly autodetected. If not, can you find your joystick in the list of joysticks and try using it?

  4. Did the axes and buttons on your joystick corresponded to the axes and buttons displayed in the tool? Note, that the names of the buttons and exact joystick layout may be different, but right stick must be right and upper button must be the upper one.

Thanks a lot!

And thanks a lot to Eugene Loza for developing it all!

Comment on this post (9 comments now) ➤

iOS improvements: packaging, vibrations

Posted on

The Unholy Society

In preparation for The Unholy Society on iOS…

  1. Packaging of textures specific to given platform by the build tool has been fixed, to really package only textures useful on given platform.

  2. The build tool auto-generate-clean subcommand was improved: by default it cleans only unused files in the auto_generated subdirectories. Call the castle-engine auto-generate-clean --all to clean all current auto-generated files.

  3. Vibrations on iOS now work.

Comment on this post ➤

Huge optimizations of glTF animations, pool of scenes for FPS game, limited PBR specular-glossiness support

Posted on

  1. With the help from Valgrind, I made a few significant optimizations to the engine animations, in particular affecting the skinned animation of glTF:

    • We update VBOs during animations much faster (we upload it more directly when possible, without recalculating some useless structures along the way).

    • Some primitives are kept in GPU much better (previously we wasted GPU space sometimes, needlessly duplicating some data instead of uploading it to GPU without transformation).

    • OptimizeExtensiveTransformations and InternalFastTransformUpdate make sense, and are enabled for fps_game, I’ll work on making them “just done by default” ASAP.

  2. I have introduced a pool of items for fps_game — more functional and more optimal solution to manage creature instances. The example knight creature in fps_game already uses it.

  3. I added a limited support for PBR specular-glossiness parameters. It’s converted to PBR metallic-roughness parameters at import (this means it is limited, e.g. we cannot handle specularGlossinessTexture). It’s far from perfect, but at least the result looks sensible for models that contain only pbrSpecularGlossiness specification, and no pbrMetallicRoughness parameters.

Comment on this post (3 comments now) ➤

Lots of glTF work, new X3D extensions and conversion improvements

Posted on

Blender desining example_level for glTF export to fps_game example

More work on perfect glTF support in Castle Game Engine follows 🙂

Things done lately related to glTF:

  1. Our engine demo examples/fps_game/ uses now glTF format for both level and creatures. So you can just export from Blender to glTF, using standard Blender exporter.

    While X3D is still a great scene graph format our engine… But as a file format, glTF today wins, with much more capable Blender exporter, that already supports animations, PBR, textures, normalmaps and more. So we advise this approach.

  2. Placeholders (detected for levels defined in level.xml) now account for Blender-> glTF behavior.

  3. New orientation value otUpYDirectionZ, following Blender -> glTF behavior and both Blender and glTF conventions of “where is front”.

    This will be default soon. Changing this default will break compatibility, but we really want to make glTF a first-class citizen for us.

  4. CastleLoadGltf unit with public GltfForcePhongMaterials. This makes sense for people that want to easily upgrade their pipeline to glTF, but are not ready for PBR yet.

  5. New X3D extensions: ValueTrigger (compatible with InstantReality) andShape.collision field (set to "BOX" to collide as a box easily).

  6. Saving X3D (in particular after glTF -> X3D conversion), now creates unique names for all X3D nodes if needed. This makes sure that model is saved preserving all DEF/USE references and routes (DEF/USE references cannot be always preserved in case names are not unique; in case names are empty, DEF/USE references cannot be preserved, and also ROUTEs cannot be recorded).

  7. Fixed rendering animations defined by resource.xml with one scene for all animations.

  8. Fixes to glTF skinned animation transformation in some cases.

  9. Fixed normal vectors during glTF animations (normals need to be interpolated too).

  10. Optimized animations: Store and use X3D Shape node bboxCenter, bboxSize, don’t recalculate useless octrees when not needed.

I’m working still on optimizing glTF skinned animation speed. It’s still a work in-progress (CGE now does various unnecessary things, causing a slowdown; and we don’t apply skin on GPU yet).

Comment on this post ➤

Fun with Sketchfab plugin in Blender, testing glTF performance

Posted on

  • Sketchfab addon for Blender is lots of fun. You can search and download Sketchfab models straight into Blender and then export from Blender to glTF and open it in our engine. On the side you can see screenshots when I had some fun with it 🙂

    Thank you go to Blender Guru (Andrew Price) for mentioning this cool thing in his newsletter.

  • To test performance, I implemented a GltfForcePhongMaterials toggle. It’s somewhat internal now, in X3DLoadInternalGLTF unit, and I don’t know yet whether I will make it “official” (move it to non-internal unit). Toggling it to true will force glTF importing to use old Phong materials, which are uglier, but may be much faster than PBR materials (esp. when you use Phong lighting model with Gouraud shading).

    Time will show whether this will be useful. Anyway, you have the possibility to test it now. You can already use view3dscene from snapshots to toggle it (menu item View -> Load glTF materials as Phong (Faster, Requires Reload)).

Comment on this post ➤

Testing glTF with models from Sketchfab, improved per-vertex rendering from glTF

Posted on


Perfect glTF support is now my major task. It quickly became obvious that glTF is just a great asset format for our engine, it works beautifully with Blender and you can find plethora of sample glTF models on the Internet.

I’m working now on multiple glTF features: finishing PBR, gamma correction, and optimizing glTF animations.

Comment on this post ➤

Castle Game Engine integration with QuickJS (JavaScript)

Posted on


Coldzer0 is working on an integration of Castle Game Engine and QuickJS, a powerful JavaScript engine.

  1. Check out this demo how to use JavaScript as a scripting language in your game. It shows how to execute a JavaScript from a Pascal program, and also provide some functions to be called from JavaScript (and handle them in Pascal). So we have a bi-directional integration with JavaScript.

    The QuickJS demo by Coldzer0 is based on SnakeGame by Eugene Loza. In the original game, you control a snake using the keyboard. In the QuickJS demo, you control the snake by implementing an A.I. using JavaScript, like this: data/movement.js. See the demo README for details.

  2. As a next step, Coldzer0 is working on exposing Castle Game Engine API in JavaScript. The idea is to allow to code a complete game using JavaScript, if you prefer/know this language better than our Pascal 🙂

    Similar to how other engines expose integrations with various programming languages, we’re open to exposing our APIs in other programming languages than Pascal. To remind, you can already use a subset of CGE from the C and C++ languages. Michalis is happy that more integrations will appear 🙂 The more people can use our engine -> the better for the engine future.

    Here’s a movie showing instantiation and usage of TCastleTimer from JavaScript:

Comment on this post ➤

glTF skinned animation in Castle Game Engine

Posted on

glTF 2.0 skinned animations work! You can export such animations from Blender and a lot of other software.

Sample models:

Comment on this post ➤

Blender exporters upgrades and fixes, glTF unlit support, castle-anim-frames improvements, loading a series of models for animation

Posted on


As a great Blender fan, I was unhappy that since Blender 2.8 release we lost some integration features between Blender and Castle Game Engine. So I decided to fix the situation, and upgrade the support to a new level 🙂

It’s not all finished yet, one more big feature will come (spoiler: skinning in glTF)! But I can already announce various improvements to what you can do. The documentation about exporting to Blender also contains an always-up-to-date instructions.

  1. Our castle-anim-frames exporter is fixed now, to work with Blender 2.8.

    castle-anim-frames can also now use the glTF format internally (instead of X3D) to export each frame.

    Unfortunately the effect of castle-anim-frames+glTF is not perfect, because the generated frames are not “structurally equal”, so you will typically want to set “Frame Skip” to “zero”, otherwise animation isn’t smooth. But in effect the files will be huge…

    A solution to the above will be support of skinning in glTF. Working on it!

  2. I submitted Blender patches to fix X3D export with modifiers and fix X3D export of “backface culling”. They are in review now.

  3. I created some Blender demos (to test exporting to glTF and castle-anim-frames), see . They nicely show that glTF exporter is really good (so we want to use it, and advise it as the best exporter) and already exports various things (like PBR, unlit, normalmaps) correctly to CGE.

  4. We now support glTF unlit materials in Castle Game Engine and view3dscene (using glTF extension KHR_materials_unlit, used by Blender -> glTF exporter).

  5. I submitted pull request to the Blender glTF exporter to fix exporting without “Skinning” (used by our castle-anim-frames exporter internally).

  6. Finally, you can load animation from a set of static files using URL like [email protected](3).obj to load xxx001.obj, xxx002.obj, xxx003.obj etc. Blender exporter to Wavefront OBJ allows to export such animations.

Comment on this post (1 comment now) ➤