Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Created May 30, 2024 17:29
Show Gist options
  • Save bcardarella/2bc6486441f79efccaf2145ed3ba0455 to your computer and use it in GitHub Desktop.
Save bcardarella/2bc6486441f79efccaf2145ed3ba0455 to your computer and use it in GitHub Desktop.

template

<RealityView>
  <%= for {{x, y, z}, color} <- @blocks do %>
    <ModelEntity
      id={"#{x},#{y},#{z}"}
      mesh="box"
      mesh:width={@scale / @width}
      mesh:height={@scale / @height}
      mesh:depth={@scale / @depth}

      position:x={(x * (@scale / @width)) - (@scale / 2) + (@scale / @width / 2)}
      position:y={(y * (@scale / @height)) - (@scale / 2) + (@scale / @height / 2)}
      position:z={(z * (@scale / @depth)) - (@scale / 2) + (@scale / @depth / 2)}

      material="simple"
      material:color={color}

      generateCollisionShapes
      generateCollisionShapes:static

      phx-click="set-block-relative"
      phx-value-x={x}
      phx-value-y={y}
      phx-value-z={z}
    >
      <Group template="components">
        <HoverEffectComponent />
      </Group>
    </ModelEntity>
  <% end %>
</RealityView>

event handler

def handle_event(
    "set-block-relative",
    %{
      "x" => x, "y" => y, "z" => z,
      "_location" => %{ "x" => tap_x, "y" => tap_y, "z" => tap_z }
    },
    socket
  ) do
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment