Jump to content

UNIGINE 2.0 Alpha 2: Hotfixes and C# API


photo

Recommended Posts

Introducing C# API

 

From now on it is possible to use C# for development of UNIGINE-powered applications, thereby involving the full power of IDEs. C# API provides functionality similar to C++ API. It allows you to:

  • Embed UNIGINE into C# applications.
  • Create external C# based App windows.
  • Call functions of the UnigineScript library from the C# code.
  • Export C# constant values and functions to UnigineScript.
  • Work with UnigineScript containers from the C# side.
  • Set callbacks.

20141120-c-sharp-sm.png

 

Both x86 and x64 binaries with float and double coordinate precision are supported: all C# Wrapper libraries are compatible with double precision builds if the UNIGINE_DOUBLE definition is used.

 

Requirements

  • The minimum supported C# version is 4.0.
  • The supported platforms are Windows and Linux.
  • Under Windows, Microsoft .NET Framework 4 and up is required. Under Linux, the latest Mono release version must be installed.

C# Wrapper Initialization

 

In your code, you should initialize the C# Wrapper by calling Wrapper.init() before Engine.init() in order to enable working with the engine before it is initialized: create packages, add functions to the interpreter and so on.

 

UnigineScript Interoperation

 

You can export functions from your C# code to UnigineScript. The exported function can have up to 8 arguments. However, you cannot export classes.

The function that is written in C# and must be exported to UnigineScript can receive arguments of the Variable type only. To get a value of the required type, use the corresponding getter functions.

You can also work with UnigineScript containers from the C# side. On the C# side, vectors and maps can be accessed via the ArrayVector and ArrayMap classes.

Export of constant values from C# to UnigineScript is also available.

See the examples in the source/csharp/samples/Api/Scripts/ folder for more details.

 

Callbacks

 

The callback functions can receive optional arguments of the int or IntPtr type that are used to store user data. IntPtr values can be wrapped in classes, for example:

IntPtr ptr;
// create a node and then create a Unigine object
Unigine.Object.create(new Node(ptr));

Managing Pointers

 

Each class of C# API has functions for managing pointers, which are managed in the same way as in C++. The full list of pointers is given in the C# API Reference article.

 

C# Samples

 

The C# samples are located in the source/csharp/samples/ folder. These samples are similar to the C++ API ones.

Each C# API sample folder contains the *.csproj MS Visual Studio C# project files in single precision.

Also there are 3 samples that demonstrate how to embed Unigine into a C# Windows Form application with:

  • Direct3D11 initialized via the SlimDX library (see the source/csharp/samples/App/D3D11SlimAppForm/ folder).
  • Direct3D11 initialized via the SharpDX library (see the source/csharp/samples/App/D3D11SharpAppForm/ folder).
  • OpenGL initialized via the OpenTK library (see the source/csharp/samples/App/GLTKAppForm/ folder).

These samples are located in the source/csharp/samples/App/ folder.

The samples can be compiled by typing make_x86 (or make_x64) -f Makefile.win32 on Windows (or Makefile on Linux) in the command prompt or via MS Visual Studio.

 

Renderer

  • Added a render_simple_deferred console variable. If this console variable is set to 1, the additional SIMPLE_DEFERRED shader definition will be used. This definition is used inside the terrain shader for increasing the shading speed in case when the deferred buffer quality is not so important.
  • Improved triangulation provided by ObjectVolumeBox in corner cases.
  • The length parameter of the post_blur_radial shader has been renamed radius.
  • Added a new materials/procedural_01 stress sample. This sample can be used for comparing C++ / C# / UnigineScript performance.
  • The post_filter_wet material now creates an effect of flowing down water by default. Make sure that the auxiliary buffer is enabled.
  • Increased the maximum number of ObjectMeshSkinned bones per surface to 128.
  • Added the render / depth_00 sample. It shows how to use the post_deferred_depth postprocess material, which displays the linear depth.
  • Improved the render_composite material. Now the image can be displayed with the alpha buffer.
  • Added a new mesh_shadow_based material. It receives shadows casted from objects lightened by world, projected and omnidirectional lights and has adjustable light and shadow colors. Visibility of the shadow can also be modulated by the alpha channel.

20141120-shadow-based-sm.png

 

Terrain

  • The terrain shader performs fast prefetching which is based on diffuse texture sampling only. Prefetching can disable complex back-to-front blending calculations. It checks each terrain material to find the one that meets the following requirements:
    1. The material is checked as Overlap.
    2. Diffuse, normal and specular scales of the material are set to 1.
    3. The alpha channel of the material diffuse texture is equal to 1.
    If all of these conditions are observed, the lower materials will not be included in blending calculations. Otherwise, the complex shader computation will be performed. Prefetching of up to 8 upper materials is available.
  • Added a new stress sample with 48 active terrain materials (stress/terrain_02).
  • Increased the maximum number of per-terrain materials to 48.

20141120-terrain-sm.png

 

UnigineEditor

 

Undo/Redo System

 

Undo/redo system has been completely refactored. Now there is a unified undo stack for all editor windows (except for Tracker for now) and plugins. Overall stability of the undo/redo operations has been drastically improved as well.

 

Terrain

  • Fixed terrain grabber.
  • Fixed blending for diffuse brushes.
  • Added import of 3D texture masks.
  • Fixed updating of coarse textures.
  • Height limits for brushes are now calculated from the actual terrain size.
  • Fixed updating of arrays.
  • Fixed saving of terrain .settings files.
  • Landscape plugin: added an experimental fast mode for import.
  • Fixed compression and updating of textures.

City Import Plugin

  • All of the nodes are recalculated before generating.
  • Fixed nodes placement.
  • Fixed bug with duplicates.

File Dialog

  • Speeding up for large amount of files.
  • Added mesh info.
  • Fixed saving of LUT textures.
  • Added support for TIFF files.
  • Fixed saving of bookmarks.

Other

  • Added the Edit -> Convert into NodeReference feature: it exports all selected nodes to the .node file and replaces them in the current world with the NodeReference to that file.
  • Improved the Edit -> Group selected feature.
  • Fixed terrain export to the Node Export plugin.
  • Fixed Randomizer plugin crashes.
  • Fixed Game Framework plugin.
  • Camera settings button is disabled if the camera is locked.
  • Async jobs can be interrupted now.
  • Added a world_init event.
  • Fixed focusing on objects with partially disabled surfaces.
  • Improved loading of the FBX files: meshes with joints, but without geometry, are now loaded as animations.
  • Improved the OpenFlight import plugin: added support for hidden and 2-sided flags of Face nodes.
  • Default speed presets have been changed: 5, 50, 500 units/s.
  • Editor camera position is stored on exit in the config file for each world. If there is no stored position in the config, the editor camera will be initialized with game camera settings.
  • Added a Mesh Combiner plugin: it combines surfaces of selected objects and creates a new mesh. Surfaces that have the same material assigned are combined into one and can be seen in the Surfaces tab of the resulting mesh.
  • Added the UniginePath plugin for 3ds Max. It allows you to export path transformations to the .path file.

Tools

  • Added support for the FBX file format to the MeshImport tool.
  • Added scene rotation around the Z axis by the mouse X axis in ResourceEditor. You can rotate the scene by using the horizontal mouse wheel or by pushing the vertical mouse wheel left or right.
  • Added a -define "extern_define" command line argument, which is used to pass an extern definition into the USC interpreter.

C++ API

UnigineScript

  • The call() container function can be used to call multiple user/extern functions with the same number of arguments by using their identifiers. For example, if you have an array that contains identifiers of different functions with the same number of arguments, you can call these functions at ones as follows:
    void foo_1() { 
    	log.message(__FUNC__ + ": called\n");
    }
    
    void foo_2() {
    	log.message(__FUNC__ + ": called\n");
    }
    
    void foo_3() { 
    	log.message(__FUNC__ + ": called\n");
    }
    
    // declare array of functions identifiers
    int functions[0];
    
    int init() {
    	// add the functions identifiers to the array
    	functions.append(functionid(foo_1));
    	functions.append(functionid(foo_2));
    	functions.append(functionid(foo_3));
    	// call at ones all the functions stored in the array
    	functions.call();
    }
    
  • Added the anonymous function declaration in the style of C++ syntax. If you need to call a short function or a function that is not used elsewhere in the code (and therefore, the function name is not important), you can use the anonymous function. Anonymous functions always return the functions identifiers. For example, the following examples perform the same:
call( [](int a) { log.message("%d\n",a); }, 13);
print_13(int a) {
	log.message("%d\n",a);
}
call(functionid(print_13),13);
  • The anonymous functions can be also used for async and array calls. The sample showing how to utilize anonymous functions inside the Async class: systems / socket_3.
  • Added the delete() container function that can receive two arguments. You can delete a specified number of container elements starting with a specified position. On the delete() function call, destructors will be called and the container elements in the specified range will be deleted.
  • You can write and read values with different endian notations to/from the Stream class. The default is the little-endian notation.
  • Improved the blend() function of the Image class. Now you can blend images of 32-bit floating point format.
  • Improved the function chaining. Now you can use this feature with the user defined classes in the script without casting the return value of the first function to the required type.
  • Changed the return type of the getCRC32() and getMD5() functions of the Buffer class. Now they return the hexadecimal string instead of the integer value.
  • Improved the addMeshSurface() function of the ObjectMeshStatic class. If the color array (or texture coordinates arrays) of the source or current mesh surface is empty, it will be filled with zero elements.

GUI

  • Added detection of the mouse horizontal scroll for WidgetScrollBox. You can now scroll horizontally by using the horizontal mouse wheel or by pushing the vertical mouse wheel when moving left or right.
  • Tooltips for WidgetTabBox are now positioned under the mouse cursor.
  • Added the size constraints for displaying the target image by WidgetDialogImage. The maximum image width and height is 8192 pixels. So now 1024×1024×32 texture arrays can be visualized in the image dialog window.
  • Fixed incorrect restoring of the permanent window focus under Win32.
  • The menu toggle key of the system script can be configured via systemSetToggle() / systemGetToggle() system script functions. These functions can be found in the data/core/scripts/system.h file.
  • Updated the widgets/ui_01 sample: now it shows how to declare and register widget callback functions in a single line of code.
  • Added the flags argument to the Unigine::Widget::Window / Dialog / DialogColor / DialogFile / DialogImage / DialogMessage constructors. This argument receives one of the InterfaceWindow flags.
  • Fixed the bug with inversion of a horizontal slider. If you scroll up the mouse wheel, the slider value will increase.
  • Fixed WidgetSpriteShader class. It will correctly call blending functions and set buffer mask parameters.

Mobile Platforms

  • Restored the Android platform support. Now there are two types of Android applications:
    • Native applications that have no Java code. These applications are useful for development and fast iterations. However, such applications are difficult to customize.
    • Activity-based applications that use Java code for OpenGLES and input handling as before. The number of arguments that can be passed from a system script to Java code (and vice versa) has been increased to 4. Moreover, support for double arguments has been added. A user can interact with the world and editor scripts via Java functions.
  • All Android-specific functions are available inside the engine.activity namespace instead of engine.tablet. The availability of these functions can be checked via the HAS_ACTIVITY definition.
  • Removed the Android client application and the FileClient plugin.
  • Added support for gcc-4.6 and gcc-4.8 for ARM-based Android builds.
  • Added an IPHONESDK environment variable, which is required for iOS builds. The variable must be equal to your iPhone SDK version, for example, "iPhoneOS8.1.sdk".

Documentation

Other

  • Added the AppGrabber plugin that grabs the current viewport each frame. This plugin can be used for streaming data to the different broadcasting applications.
  • Fixed the bug with the AppWall plugin crash on its start-up.
  • Added a new bool type to store console variables of the boolean type in the configuration file. Now the bool type is used instead of the int type. WARNING: It is recommended to delete your old .cfg files to re-configure projects in order to prevent errors.
  • Changed the behavior of the world_reload console command. Now it reloads the last world loaded via the world_load console command even if the loading operation has failed.
  • Added a config_readonly console variable. It blocks any attempts to write data to the configuration file.
  • Removed support for MS Visual Studio 2008.
  • Added a 3840×2160 (4K) video mode. To set it via console, specify the following: video_mode 8.
  • Increased the speed of saving RBG8 and RGBA8 images to DDS files in all of the dedicated applications.

 

 

 

Download Links

 

All files can be found in "Downloads" section of the portal: https://developer.unigine.com/downloads

 

PS: Some features are still in the active development at the moment, so this release isn't recommended for production use.

PPS: Previous stable version of the SDK (2014-07-07) is also available for download. Old documentation is also available online: http://old-docs.developer.unigine.com/

  • Like 3
Link to comment

Thanks a lot!

 

A short questions:

 

What is the preferred api to use in the future? UnigineScript or C#?

Currently the lacking support for IDEs with debugging is a huge disadvantage for UnigineScript. Are there any plans to add some sort of plugin for e specific IDE? In the long shot what are the plans to improve this situation?

 

 

Greets

Manuel

Link to comment

All APIs (UnigineScript, C++ and C#) are going to be supported.

At the moment we don't plan to implement IDE integration for UnigineScript, so if it's an important factor for you, it is recommended to use C++ or C#.

Link to comment

Congratulations for the update :). As always... excellent job.

Some questions:

  • Have you done benchmarks with 4K resolution? What graphics card should be used to have demos like Valley running more or less at 60fps?
  • AppGrabber plugin is very interesting, How do you tested it? What client have you used to receive Unigine stream?
Link to comment

I've done a very simple script to upgrade config files. It just set item type to bool for a defined set of item names. It works for me, I hope it will help others :)

To use it just type:

//from the folder to be explored (it makes a recursive search for .cfg files)
%UNIGINE_DIR%\bin\usc_x64 upgradeconfig.usc

upgradeconfig.usc.txt

Link to comment

manuel.gysin
Theoretically, building with Mono-x64 for MacOS X should do the trick. Unfortuantely, I can't give you any ETA right now when builds will be available on regular basis in SDK.
 
ivan.cuevas

Thank you for upgrade scrpit! :)


Have you done benchmarks with 4K resolution? What graphics card should be used to have demos like Valley running more or less at 60fps?


Sorry, we did not tested 4K performance yet.
 

AppGrabber plugin is very interesting, How do you tested it? What client have you used to receive Unigine stream?


AppGrabber designed mostly for cinematic software (for example, mixing different video streams from different sources).

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Shoud be manual terrain material painting functional now? I tried to manually paint in stress/terrain_02 and it is possible to paint some materials manually, some not. I dont have clue why.

 

48 material limit is now per chunk, or per whole terrain?

 

My current understanding is, that I can have lots of materials (layers) per terrain, but only 16 per chunk. So I expect, that until I reached 16 layers per chunk, I can pick any layer I want, for example layer 35. In case chunk is "full", engine shows me some message like "no free slots for other layer on chunk 00x00". Am i corrent? Or it works in different way? Also there is now no way how to know, how many layers (and which) are used on given chunk, it was possible in old terrain engine

Documentation would be really handy, I am still guessing how new system should be used. For example parenting. My guess is, that it is only for cases when I have two materials with same mask, parent is overlay, child overlap as aditional detail (road texture with pebbles details). Correct

Link to comment

demostenes,
 

48 material limit is now per chunk, or per whole terrain?

The overall limit is 48 materials for whole terrain. 16 materials per chunk limit for those materials, that would be blended with each other. However, using a parent-child system you can achieve more than 16 materials per chunk (if they are not blending with each other). So, you can blend up to 16 materials per chunk and 
 

So I expect, that until I reached 16 layers per chunk, I can pick any layer I want, for example layer 35. In case chunk is "full", engine shows me some message like "no free slots for other layer on chunk 00x00". Am i corrent? Also there is now no way how to know, how many layers (and which) are used on given chunk, it was possible in old terrain engine

There is no special messages, because it is difficult to calculate and display how many materials are actually were blended into the single texture. It was much easier when you were able to blend only 4 materials per chunk. We are still thinking on the implementation and maybe it would be added in the further updated.
 

Documentation would be really handy, I am still guessing how new system should be used. For example parenting. My guess is, that it is only for cases when I have two materials with same mask, parent is overlay, child overlap as aditional detail (road texture with pebbles details).

Yes, indeed. Tutorials will be available with the stable SDK release. I believe they will cover all the features of the new terrain system, especially parent-child system.
 

I tried to manually paint in stress/terrain_02 and it is possible to paint some materials manually, some not. I dont have clue why.

 

Do you have a reproduction steps? Which brush types are you using?

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Do you have a reproduction steps? Which brush types are you using?

 

I ve used following setup:

replace mode + mask brush, circle (add mode makes no difference), I am painting on chunk with numbers 14. No picked material does anything. I ve tried to decompress textures, no difference. I dont even know, if this should do anything...

Link to comment

demostenes

 

terrain_02 sample is created with limitation of 4 materials per chunk. Also, if you will paint with material from 1 to 13 it would not be displayed, because these materials all located under the 14.

 

It would be better to use newly created terrain to test painting option.

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
Also, if you will paint with material from 1 to 13 it would not be displayed, because these materials all located under the 14.

 

 

Thanks a lot, this is exactly information I needed! Now I need to think what does it exactly mean for artistic workflow...

Link to comment

Hi

 

I recently produced my terrain in 'Unigine 2.0 alpha r508' which contained 7 different array textures via the layer feature within the terrain node. The textures were assigned to the terrain using RGB channels across three different image masks, and all worked as expected.

 

vuknr.jpg

Unfortunately, when I attempted to reproduce the terrain using the same masks in 'Unigine 2.0 alpha r782' the results are not as expected. For example the 'green' 'fairway' and 'pine needles' are all without the detailed texture. Could you please investigate? Thanks

 

rk4l8h.jpg

 

 

Link to comment

Awesome work on the C# support! Do you have a roadmap for how far you intend to take the C# API just yet?

 

C# API will get all of the improvements of C++ API.

Link to comment
  • 3 weeks later...
×
×
  • Create New...