Applying a transformation to a collection of entities

Is there a way to assign a transformation to a collection of entities? Essentially, I want to be able to do the pushMatrix() ... popMatrix() of the non-Craft system.

In a little more detail, suppose that I have some entities each with their own position and rotation. It might be that those positions and rotations change with time. Then I want to apply a single transformation to the entire group. I can cycle through them and modify them one by one, but keeping track of the “external” and “internal” transformations will be a bit of a headache. What I’d really like to be able to do is have a parent entity and set the transformations on that, and have them percolate down to its children.

I’ve not figured out how to do this natively in Craft as yet (obviously, I can implement it by hand but I’m asking if there’s already the capability in Craft so that I don’t need to).

@LoopSpace just set the parent property on the entities you want to group together to another entity that you create.

@John Thanks! That never occurred to me. I thought I had to :add them but that wasn’t working.

Right. Time to experiment with AR …

I just used this in the Craft Coaster project and one bit confused me for a bit. If you set .position before .parent then the .position information gets lost.

That is,

e = scene:entity()
p = scene:entity()
e.position = vec3(2,2,2)
e.parent = p

resets the position of e to the origin, whereas:

e = scene:entity()
p = scene:entity()
e.parent = p
e.position = vec3(2,2,2)

doesn’t.

If this is status-by-design then I think it is worth noting somewhere. If not, then can I request that it not happen like that? There seems no value to it.

@LoopSpace , whoaa are you the guy to talk to. Just saw your Craft Roller Demo on YouTube. Very impressive. You can probably point me in the right direction I have been trying to build a skybox in Craft but can’t get my images into the Craft system (Environments asset folder). How did you build yours for the demo? If it involved incorporating a separate mesh into the Craft scene I’d like to know how it’s done.

When are you going to release the demo?

@Bri_G You flatter me. I’m just experimenting, same as everyone else. Maybe I’ve been thinking about 3D in Codea longer than most …

The code for the sky is:

    local galaxy = PseudoMesh()
    galaxy:addSphere({radius = 100})
    galaxy:invertNormals()
    e = scene:entity()
    e.model = galaxy:toModel()
    e.material = craft.material("Materials:Basic")
    e.material.map = "Dropbox:starmap_small"

PseudoMesh is from the other thread, the addSphere method is from my mesh extension library but you should be able to guess what it does - the inbuilt icososphere would do as well if you inverted the normals, the star map is from NASA (link in the youtube video).

I just need to pull the code into a single project before releasing it.

Thanks @LoopSpace I’m off to play