Writting your own Tools

In the Cave Engine you can write your own tools using python. They can be as simple as just executing a text to do something for you or more complex and well made tools, with a proper interface that contains buttons, sliders and whatever you want in a Tab format, that you can dock to the Editor's ui.

To start writting your tools, create a new Python Script in the asset browser, open it in the text editor (double click) and delete the current startup code.

Run your first Tool

Let's start with a simple tool that just sets some Sun light settings:

import cave

# You can write the code you want to using the cave API:
scene = cave.getCurrentScene()
sun = scene.getSun()

sun.hour = 6.15
sun.intensity = 5.0
sun.color = cave.Vector3(1.0, 0.8, 0.8)

In order to run this code, simply go to "Editor Tools.." and then "Run Script":

It will run and change the sun settings, as expected. Note that you can use print(...) here to debug your stuff as well.

Have fun!

Create a Tab and Interface for your Tool

Now that you already know how to run simple scripts like that, it's time to understand how to do some a bit more advanced ones. So let's start talking about a tool with its own Tab docked in the editor, with a proper interface with buttons, sliders and so on. Here is a screenshot showing that in action. The code in the left generated the tab highlighted in red:

Here is a simple code that produces a similar result and can be used as a starting point for your own tools:

import cave
import caveui as ui

class Example(ui.DebugTab):
    def __init__(self):
        super().__init__()
        self.counter = 0

    def draw(self):
        ui.text("Hello, world!")
        ui.separator()
        self.counter = ui.prop("Counter", self.counter)
        if ui.button("Increase counter (+1)"):
            self.counter += 1

In order to run that and register the Tab to the ui, go to the "Editor Tools..." option and open the "Register Tab..." sub menu. It will automatically identify all the classes in the code that inherits from the base class caveui.DebugTab and show there. Simply click in the one you want to in order to register it.