backspaces / agentscript

An Agent Based Modeling system (ABM)
http://backspaces.github.io/agentscript/
GNU General Public License v3.0
107 stars 14 forks source link

In Three draw can turtles change color or are they fixed when first drawn? #20

Closed stigmergic closed 3 years ago

backspaces commented 3 years ago

Just checked: In ThreeMeshes.js:

I suspect that's what you're using, a shape that is real 3D.

Let me check on just how easy that would be to add color changes for the mesh-per-turtle

backspaces commented 3 years ago

OK, here's a fairly easy (I think!) approach. Each draw checks the requested shape,size,color (the viewFcn(turtle)) with the existing one. If any differ, simply delete the existing mesh and create an entirely new one. Would that solve the issue?

stigmergic commented 3 years ago

Yes I expect it would. I think it is important that turtles be able to change color. I also understand that it could have an impact on performance. But I tend toward first being able to do it, and later if necessary worrying about speeding it up.

backspaces commented 3 years ago

OK, I've made it possible to modify the shape, color, size of an existing mesh. BUT it requires colors to be typed colors.

Basically the problem is that the ctor does a lot of preprocessing of the drawOptions, so simply changing the drawOptions can bypass that preprocessing.

The best solution would be to add a method for changing the entire drawOptions object but I think this may do for now.

stigmergic commented 3 years ago

seeing it run a little slowly. Here are my drawOptions


    turtlesShape: (t) => (isCamera(t) ? 'Dart' : 'Sphere'),
    turtlesColor: (t) =>
        t.el < 0
            ? 'black'
            : isPlanet(t)
            ? planetColor(t.data.name)
            : isStar(t)
            ? 'yellow'
            : 'red',
    turtlesSize: (t) =>
        isPlanet(t) ? (t.data.name == 'Sun' ? 3 : 1.5) : isStar(t) ? 0.3 : 4,
}```
backspaces commented 3 years ago

@stigmergic I think this is fixed now. I'll close it for now and hope it's fixed :)