-
We added a simple demo how to detect which scene (TCastleScene) was clicked with the mouse: https://github.com/castle-engine/castle-engine/blob/master/examples/3d_rendering_processing/detect_scene_clicks.lpr .
-
The behavior of shadow maps when combined with CommonSurfaceShader is now correct. Testcase: https://github.com/castle-engine/demo-models/blob/master/shadow_maps/primitives_with_commonsurfaceshader.x3dv
-
view3dscene no longer uses console for various messages. Instead we display our own message box, with contents that can be copied to clipboard with Ctrl+C. This makes it more comfortable to use as a normal GUI program, in particular on Windows. Remember that you can always download the latest view3dscene snapshots from here. (Or you can compile view3dscene from source, of course.)
-
Our website supports now IPV6, HTTP/2, has better redirects (from www domain to non-www), and is HTTPS-only (non-secure HTTP merely redirects to HTTPS, and we use HSTS). Thanks to Raul Tambre for suggesting and testing these improvements!
To finish the week of many annoucements, here are 3 more engine features added lately.
BTW, I also wrote a wiki page documenting common properties to “make rendering prettier”. Check it out:)
New engine features:
-
Scene.Attributes.SeparateDiffuseTexture allows to get a prettier lighting behavior. The textures (in
Appearance.texture
orCommonSurfaceShader.diffuseTexture
) will then really affect only the diffuse lighting term. This is generally better and prettier (specular highlights are then brighter), and it’s also more correct (according to X3D spec). But note that it is only possible in Phong shading (whenScene.Attributes.PhongShading
is alsotrue
), and it makes rendering a little more expensive (for now).In view3dscene (see view3dscene from snapshots) you can use menu item View -> Separate Diffuse Texture (When Phong Shading) in addition to View -> Phong Shading on Everything. By default it is false, to be compatible with previous look, and also because it’s more consistent with Gouraud shading behavior. (And the Gouraud shading is default, in turn, for speed.)
-
Client and server classes for implementing TCP client/server communication in Castle Game Engine games are available. See the unit CastleClientServer, and the demos in examples/tcp_connection. Thanks go to Benedikt Magnus for implementing this!
-
You can now instantly disable/enable physics by setting SceneManager.Items.EnablePhysics to false/true.
Engine improvements: generating compressed/downscaled textures is smarter
Since a long time, you can automatically generate compressed and/or downscaled textures versions using our build tool.
This process is now smarter. Instead of detecting which files to update looking at file modifications times, it now looks at file contents (using fast MD5 checksums), and automatically creates/updates a castle_engine_auto_generated.xml
file. The castle_engine_auto_generated.xml
is automatically created and maintained in your data/
directory when you call castle-engine auto-generate-textures
.
We plan to extend this feature even more, to store more information inside the automatically-maintained castle_engine_auto_generated.xml
. In the future, this file can be used to:
- Track the size of the texture. This allows to avoid trying to load non-square compressed texture on iOS, which is not possible — thanks to weird Apple limitations. Currently we just avoid using any auto-generated compressed textures on iOS.
- Track the DXT* version generated, for the case when we automatically choose the best DXT* version depending on the image alpha channel. This would complete a currently unfinished-and-undocumented feature of
<format name="DXT_AutoDetect" />
inmaterial_properties.xml
.
You can now comfortably localize (translate) your game.
Two approaches are possible:
- Use our own localization class from the CastleLocalization unit. It can read from a number of translation formats (XML, JSON, CSV, GetText MO). It can translate user-interface controls, like TCastleLabel. The demo is inside examples/localization/custom/.
For advanced users, the system allows to aid in localizing your custom classes too (see OnUpdateLocalization) and to add your own translation formats (see FileLoader).
Thousand thanks go to Benedikt Magnus for developing this!
-
Use the standard GetText unit from FPC. You use GetText formats for translating (PO, MO), utilizing tools like PoEdit. The resourcestrings are translated automatically. The demo is inside examples/localization/gettext/.
The engine uses resourcestrings for some internally-generated messages (and it will use them more), so these can be translated too.
In both cases, you can use a cross-platform CastleSystemLanguage unit that tells you the preferred user language.
Note that, while both approaches (GetText, our own) provide some infrastructure to aid you in translating (resourcestrings, special handling for UI controls), you can also translate things “explicitly” in both cases. Using the TMOFile.Translate(‘my_id’) in GetText, or Localization.Items[‘my_id’] in CastleLocalization.
So both systems are really flexible, and should fill all your needs 🙂
A related feature is also new TInputPressRelease.KeyString. This expresses key press as a string with UTF-8 encoding, and allows us to accept input of international characters across Castle Game Engine (for example in TCastleEdit). Many thanks go to Eugene Loza for this!
-
I wrote a wiki page documenting two approaches for 2D rendering using Castle Game Engine. Advised
reading for people implementing 2D games 🙂 -
You can customize the look of TGLImageCore using the TGLImageCore.CustomShader. Or you can customize the look of TCastleImageControl using TCastleImageControl.CustomShader. The demo: examples/images_videos/image_render_custom_shader.lpr.
-
You can now assign the TCastleImageControl.DrawableImage. This allows you to render TGLImage on GPU using any fancy method, and then use it as a source of TCastleImageControl efficiently.
-
Remember that you can draw one TGLImage over another, or draw arbitrary (2D or 3D) things into the TGLImage, using fast GPU rendering. The demo how to do this is in examples/images_videos/draw_images_on_gpu.lpr.
-
You can get the contents of TGLImageCore to TCastleImage (thus getting the memory from GPU to RAM, available to CPU) using the GetContents helper method.
-
We include new classes TCastleHorizontalGroup, TCastleVerticalGroup to easily layout your controls horizontally or vertically.
-
FreeType library on Android (thanks to Benedikt Magnus!).
-
TCastleEdit.AutoOnScreenKeyboard (also thanks to Benedikt Magnus!). Note that the keys from the on-screen keyboard are not yet automatically passed to your applications — we’re working on it.
-
Many parts of the user-interface (TUIControl descendants) are now calculated using floating-point values, and can even be specified using floating-point values. E.g. you can now use FloatWidth instead of Width, CalculatedFloatWidth instead of CalculatedWidth, ScreenFloatRect instead of ScreenRect and so on. Some of the public properties have also just changed to be floats (like padding, margins, anchors deltas), which may break compatibility in rare cases.
The primary reason for this change is that when using UI scaling, it doesn’t really make sense to limit sizes or positions to integers. They do not hit the exact pixel boundaries anyway (in case some UI scaling is applied), instead they should be rounded to pixels only at the very bottom of the rendering code. So anchors and such should be calculated using floats, otherwise a
Round()
in the middle of an operation (before we work in the “final” resolution) would needlessly make UI controls “snap” to an invisible grid.A minor reason is also that this is more friendly to animations. Although animations could be done earlier too (having an “animation driver” remember position as float). But it’s easier now, you can just animate existing float properties, like
Control.AnchorHorizontalDelta := Control.AnchorHorizontalDelta + UpdateSeconds;
in your
OnUpdate
event. -
Improvements to VisibleChange to help with implementing controls that react to children changes.
I have a large backlog of new Castle Game Engine improvements to announce 🙂 Let me try to make it up, by making a new announcement more-or-less daily for the following week. Remember that everything I describe is available to you right now: simply use the Castle Game Engine version from GitHub (6.5).
-
We start with the improvements to our PlayAnimation method. It is the primary way to run animations using Castle Game Engine (documented in the manual).
- New overloaded
PlayAnimation
version with TPlayAnimationParameters, that allows to specify:- StopNotification: Easy and reliable way to watch when animation stopped.
- TransitionDuration: Animation blending (see my earlier post).
- InitialTime: Start animation from the middle.
- Forward: Play animation forward or backward.
- It also, of course, allow to specify basics: animation Name and whether it loops.
- It is the only way how we animate stuff in our new game “The Unholy Society” (well, aside from some user-interface animations), so it’s really flexible.
-
New overloaded
PlayAnimation(AnimationName: string, Loop: boolean)
version. This replaces (deprecates) older overload with"Looping: TPlayAnimationLooping"
parameter — the TPlayAnimationLooping did not really prove to be of much use, so it’s simpler to just specify Loop as a boolean.
- New overloaded
-
I have also written a large documentation “How to animate things using X3D”. This may be useful for developers that want to understand how the X3D nodes are used for animations. The
PlayAnimation
method, under the hood, uses the X3D nodes.
We’re proud to present Connect4, a free game for Android published by Benedikt Magnus and LanIstAn today!
The game is using Castle Game Engine, with our 2D user-interface rendering, and includes music, localization (English, Polish, German, Spain), and networking support. You can plan against a computer, or against a friend over the network. I believe this is the first game with networked play done using CGE.
I really like this part of developing Castle Game Engine — seeing how others are using it to create the coolest things. Congratulations and thank you!
We also have a ton of new features added to Castle Game Engine lately. In particular, thanks to Benedikt Magnus we now have:
- cross-platform support for networking using TCP,
- FreeType library available on Android, and
- we will have a custom localization system (in addition to being able to just use GetText for localization).
Thousand thanks!
And I’ll be posting more about the new CGE features later.
We are now officially Embarcadero Technology Partner!
What this means, in simple terms, is that Michalis has full access to the latest Delphi version, with all the Delphi platforms (including Android and iOS), for free.
This should be great news for everyone waiting on Castle Game Engine + Delphi compatibility:) We have no more excuses now, Castle Game Engine will have to work perfectly with Delphi!
Thanks go to Embarcadero, and in particular Jim McKeeth, for making this possible.
(P.S. I curse myself for making this announcement on the one day of the year when everyone else is making jokes 🙂 Yes, this is very real, and is happening! Our supported compilers and IDEs page is already updated about it.)
Animation blending means that the transition between animations is smooth. Without animation blending, the old animation instantly stops and the new animation plays. With animation blending, there is a short time during which the old animation “fades out” (it’s applied with decreasing strength) and the new animation “fades in” (analogously, it’s applied with increasing strength).
The movie below shows this technique in action in new Castle Game Engine. Notice how animation changes are sharp when TransitionDuration
is zero, but they are smooth when TransitionDuration
is larger. This is especially visible when switching between “Idle” and “Attack” animations on the 3D knight model.
This feature was implemented thanks to Castle Game Engine supporters on Patreon, in particular thanks to Robert Daniel Murphy who wished for it. Thank you! Please support me to see more cool features 🙂
How to use this
Use TCastleSceneCore.PlayAnimation with TPlayAnimationParameters, and set TPlayAnimationParameters.TransitionDuration. TransitionDuration is the time (in seconds) when when previous animation fades-out and new animation fades-in, usually values around 0.1-0.5 make sensible smooth effect. TransitionDuration = 0 (default) means that no animation blending occurs.
We have a new demo examples/play_animation/ to test the PlayAnimation
method, including Loop
, Forward
and TransitionDuration
.
Additional cool features of our animation blending
- Note that animation blending happens even when you restart the same animation. We show this in the movie by restarting the “Walk” animation — note that “old Walk” blends smoothly into “new, restarted Walk” when Transition is non-zero.
- Animation blending works for any field that can be linearly interpolated. So it works for animating translations, rotations, coordinate sets and everything else. It works for mesh deformations, or bone animations produced by Spine. It works for 3D or 2D.
Caveats (aka “things that, sadly, do not work yet”)
- For now, the animation blending doesn’t work for animations defined by castle-anim-frames (which you probably use to export animations from Blender). Fixing this requires improving the castle-anim-frames loading a bit.
Background: Animation blending only works when the same mesh is used by all animation frames, but in case of castle-anim-frames we cheat a little and we have many (precalculated) copies of the mesh. This was supposed to be fixed one day anyway, to decrease memory usage (see the TODO here). It turns out that this fix is also needed to enable animation blending.
-
For now, there is no way to define
TransitionDuration
for animations run by our TCreature system (usingresource.xml
) files. The resources animations (like TCreature) are done a little differently, without directly calling PlayAnimation, and they require a bit different code to make use of animation blending.
Both of these will be fixed one day (AD 1 is a work for ~2 days, AD 2 is a work for ~0.5 day). Let me know if any of this is critical for your project, and I’ll try to make it rather sooner than later! 🙂