Skip to content
Mikulas Florek edited this page Sep 3, 2023 · 3 revisions

Getting started

This is a plugin and it's not installed by default in Lumix Engine. Install it like any other plugin.

Basic script

// we can call this 
function localFunction() {
	ImGui.Text("Hello world")
}

// this object is stored and engine will use it - i.e. it will set its properties or call functions like update
({
	name : "Test", // this will be visible/editable in property grid
	entity : _entity, // store _entity so we can access it in update
	update : function() { // update is called every frame
		this.name = "new name";
		this.entity.camera.fov = 1.2;
		ImGui.Begin("xoxo")
		ImGui.Text("foo " + this.name)
		localFunction();
		ImGui.End()
	}
})

_entity

Entity is accesible in _entity at start, but you need to store is somewhere if you want to access it later. Position, rotation and scale can be accessed through this object:

this.position = [10, 20, 30]
this.rotation = [0, Math.sin(yaw * 0.5), 0, Math.cos(yaw * 0.5)] -- quaternion x, y, z, w

Properties

Component properties are accessible through entity: _entity.component.property, e.g. _entity.camera.fov = 1.2

Input

({
	entity : _entity, // store _entity so we can access it in update
	yaw : 0,
	onInputEvent : function(event) { // update is called every frame
		if (event.type == Lumix.INPUT_EVENT_AXIS && event.device_type == Lumix.INPUT_DEVICE_MOUSE) {
			this.yaw += event.x * 0.001;
		}
		this.entity.rotation = [0, Math.sin(this.yaw * 0.5), 0, Math.cos(this.yaw * 0.5)]
	}
})

Event types:

Lumix.INPUT_EVENT_BUTTON
Lumix.INPUT_EVENT_AXIS
Lumix.INPUT_EVENT_TEXT_INPUT

Input device types:

Lumix.INPUT_DEVICE_KEYBOARD
Lumix.INPUT_DEVICE_MOUSE
Lumix.INPUT_DEVICE_CONTROLLER

Input event has this properties:

event.type
event.device_type
event.device_index
-- if button event
event.down
event.key_id
event.is_repeat
event.x
event.y
-- if axis event
event.x
event.y
event.x_abs
event.y_abs
-- if text input event
event.text

Debugger

JS can be debugger using VS code with Duktape debugger extension.

js.mp4
Clone this wiki locally