CKAngelScript integrates the AngelScript scripting language into Virtools, providing developers with a flexible and powerful scripting environment for creating advanced and interactive 3D applications.
- Full Bindings of the Virtools SDK: Access and utilize the entire Virtools SDK through AngelScript for seamless integration of custom scripting with Virtools' extensive API.
- AngelScript Integration: Leverage the AngelScript scripting language to achieve greater flexibility and control in your 3D projects.
- Foreign Function Interface (FFI): Call native C functions directly from AngelScript using FFI, powered by DynCall, enabling seamless interaction with external libraries and APIs.
- Building Blocks:
- AngelScript Loader: Load and unload AngelScript modules dynamically.
- AngelScript Runner: Execute specific functions within AngelScript modules with precision.
- Extensibility: Expand Virtools' capabilities by integrating custom AngelScript modules.
- Compatibility: Supports Virtools 2.1 and higher.
The AngelScript Loader manages AngelScript modules, providing functionality to load and unload them dynamically.
- Load: Activates the script loading process.
- Unload: Activates the script unloading process.
- Loaded: Signals successful loading of a module.
- Unloaded: Signals successful unloading of a module.
- Failed: Signals a failure during the loading or unloading process.
- Name: The name of the AngelScript module to load or unload.
- Filename: The file path of the AngelScript file.
- Use File List: Enable loading from a list of files.
- Filename As Code: Treat the filename parameter as code instead of a file path.
- No Script Cache: Disable caching for the loaded scripts (useful for debugging and development).
The AngelScript Runner executes specific functions within loaded AngelScript modules.
- In: Activates the script function execution process.
- Out: Signals successful execution of a function.
- Error: Signals that an error occurred during execution.
- Script: The name of the loaded AngelScript module.
- Function: The name of the function to execute.
- Output Error Message: Outputs detailed error messages and stack traces when enabled.
Before you begin, ensure the following:
- Virtools SDK (2.1 or higher): Required to access the APIs and resources for building this project.
- DynCall Library: Required to enable Foreign Function Interface (FFI).
- AngelScript SDK: Required to compile the AngelScript integration.
- Microsoft Visual Studio: This project can only be compiled using Visual Studio.
- Ensure the Virtools SDK is installed and accessible.
- Use the appropriate path when configuring CMake (see below).
- Download the DynCall suite from its official website.
- Extract and install the library.
- Download the AngelScript SDK from its official website.
- Extract the downloaded SDK package.
- Place the extracted contents into the
deps
directory under a folder namedangelscript
. Your directory structure should look like this:
-
Clone the Repository:
git clone https://github.com/doyaGu/CKAngelScript.git
-
Initialize Submodules:
git submodule update --init --recursive
-
Prepare the Dependencies: Complete the preparation steps outlined in the "Preparing the Dependencies" section.
-
Run CMake: Provide paths to your Virtools SDK, DynCall, and AngelScript SDK, and then run the following command.
cmake -B build -G "Visual Studio 16 2022" -A Win32 \ -DVIRTOOLS_SDK_PATH=/path/to/virtools/sdk \ -DDYNCALL_ROOT=/path/to/dyncall \ -DDYNCALLBACK_ROOT=/path/to/dyncall \ -DDYNLOAD_ROOT=/path/to/dyncall
-
Build the Project: Open the project in Microsoft Visual Studio, configure the build settings to match your Virtools SDK installation, and build the project. The process will generate the following file:
AngelScript.dll
-
Build the Project:
cmake --build .
-
Integrate with Virtools: After the build completes, copy the generated
AngelScript.dll
to theBuildingBlocks
directory of your Virtools installation:cp AngelScript.dll /path/to/virtools/BuildingBlocks/
Create an AngelScript file (example.as
) with your desired functionality. Below is an example demonstrating lifecycle events and interactions with the Virtools SDK:
void OnLoad() {
print("OnLoad!");
}
void OnUnload() {
print("OnUnload!");
}
void OnPause() {
print("OnPause!");
}
void OnResume() {
print("OnResume!");
}
void OnReset() {
print("OnReset!");
}
int main(const CKBehaviorContext &in behContext) {
print("Hello from AngelScript!");
CKContext@ context = behContext.Context;
print("3D entities:");
XObjectPointerArray objects = context.GetObjectListByType(CKCID_3DENTITY, true);
for (int i = 0; i < objects.Size(); i++) {
CK3dEntity@ entity = cast<CK3dEntity>(objects[i]);
print(entity.GetName());
}
print("3D entities end.");
return CKBR_OK;
}
- Open Virtools Dev and create a new Behavior or edit an existing one.
- Drag the AngelScript Loader building block into your Behavior from the Building Blocks palette.
- Configure the Name parameter with a unique identifier (e.g.,
example_script
) and provide the Filename parameter with the path to your script file (example.as
). - Connect a trigger to the Load input to activate the loading process.
- Verify successful loading by checking for the
OnLoad!
message in the Virtools console.
- Drag the AngelScript Runner building block into your Behavior.
- Set the Script parameter to the module name specified in the Loader (
example_script
). - Set the Function parameter to the function you wish to execute, e.g.,
main
. - Connect a trigger to the In input to activate the function.
- Observe the console for outputs from your script.
- Use the Unload input on the AngelScript Loader to deactivate the module.
- Verify that the
OnUnload
function is called, and the module is unloaded.
- Console Output: Use
print
statements in your AngelScript code for logging and debugging. - Error Messages: Enable the Output Error Message setting in the Runner block to get detailed stack traces and error messages.
- Create and Save a Script: Write your AngelScript code in a
.as
file and save it to your project directory. - Load the Script: Use the AngelScript Loader to load the script file.
- Run Script Functions: Use the AngelScript Runner to execute specific functions from the loaded module.
- Unload the Script: Use the Unload input of the Loader to clean up resources.
By following these steps, you can fully utilize AngelScript within Virtools Dev to enhance your projects.
Contributions to CKAngelScript are welcome. To contribute:
- Fork this repository on GitHub.
- Make your changes.
- Submit a pull request with a detailed explanation of your modifications.
This project is licensed under the MIT License. See the LICENSE file for details.
- AngelScript: The scripting language integrated into this project.
- DynCall: The dynamic call library powering FFI.
- Virtools: The 3D engine platform extended by CKAngelScript.