mapeditor/tiled

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Enable scripting the appearance of objects #2134

bjorn posted onGitHub

It would be nice if the appearance of objects was not solely determined by a few hardcoded options, but could be replaced or added to by scripts.

A script could for example decide to render some primitive based on a custom property, like displaying a radius or a vector.

In some cases it would even just be useful if the script could determine the color of the object (see this forum thread).

Expansion of #949.


This seems interesting. You could even let the user return an Image as the render of an object. that would allow for some really interesting applications. you might even be able to get the objects to animate with Qt.callLater.

posted by dogboydog 3 months ago

I think the tricky thing with this is to keep a good performance. We probably shouldn't call a script function to render our object every time it needs to be drawn. Instead, the script could set up some rendering primitives or paint to a QPicture and update it in response to change signals (which are currently also missing).

Even nicer might be if we could rely on QML to declare how an object should be rendered, as an expansion of using QML in extensions.

Another open question, if we can add custom visuals to objects, is whether we can also add custom interactive things. But maybe it would be better to first switch to a more modern renderer.

Hence, I've been reluctant to implement some kind of ad-hoc solution for now.

posted by bjorn 3 months ago

As well as exposing the primitive draw functions, I'd suggest one to draw the object's default appearance with optional transform and tint.

Use case: visualizing 3D body shapes which are 2D shapes extruded on the Z axis

// Given a function
// MapObject.renderDefault(position = object.position, rotation = object.rotation, tint = tiled.color("white"))

object.rerender = () => {
  object.renderDefault();

  let zHeight = object.resolvedProperty("zHeight") || 0;
  if (zHeight != 0) {
    // Draw connecting vertical lines here

    object.renderDefault({ x: object.x, y: object.y - zHeight }, object.rotation, tiled.color(1, 1, 1, .5));
  }
};

It would look something like this.

Image

(if you wanted the whole 3D volume to be the selectable area, you would need functions to alter that too)

posted by IoriBranford 11 days ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests