Пример #1
0
    public void Initialize()
    {
        // StereoKit will support world understanding features as core
        // functionality when they become available in OpenXR! In the
        // meantime, here's some tools for doing this through the Mirage APIs

        // If the system is capable of acquiring an occlusion mesh, do that!
        // Otherwise, we can also provide any mesh or model for testing
        // purposes!
        occluder = SK.AddStepper(OcclusionMesh.Capable
                        ? new OcclusionMesh()
                        : OcclusionMesh.FromSimulation(Mesh.GeneratePlane(Vec2.One * 10, 10)));

        // Make it visible and obvious for the demo, by default the material
        // will work like a solid, invisible occluder.
        occluder.Material[MatParamName.ColorTint] = new Color(1, 0, 0);
        occluder.Material.Wireframe = true;
    }
Пример #2
0
 // Use this for initialization
 void Start()
 {
     occlusionMesh      = GetComponent <OcclusionMesh>();
     particleMainModule = fireRing.main;
 }
Пример #3
0
    public void GenerateMesh()
    {
        tilemapMesh = new OcclusionMesh(tileset);

        int x9y1, x1y9, x1y1, x0y1, x1y0, x9y9, x0y9, x9y0;

        for (int x = 0; x < map.width; x++)
        {
            for (int y = 0; y < map.height; y++)
            {
                if (map.GetUnwalkableInt(x, y) == 1)
                {
                    continue;
                }

                x0y9 = map.GetUnwalkableInt(x, y + 1);
                x9y0 = map.GetUnwalkableInt(x + 1, y);
                x1y0 = map.GetUnwalkableInt(x - 1, y);
                x0y1 = map.GetUnwalkableInt(x, y - 1);

                x1y1 = map.GetUnwalkableInt(x - 1, y - 1);
                x9y9 = map.GetUnwalkableInt(x + 1, y + 1);
                x1y9 = map.GetUnwalkableInt(x - 1, y + 1);
                x9y1 = map.GetUnwalkableInt(x + 1, y - 1);

                Vector2Int position = new Vector2Int(x - map.width / 2, y - map.height / 2);

                if ((x1y1 == 1) && (x0y1 + x1y0 == 0))
                {
                    AddTile(8, position, OcclusionTileset.TileRotation.up);
                }
                if ((x9y9 == 1) && (x0y9 + x9y0 == 0))
                {
                    AddTile(8, position, OcclusionTileset.TileRotation.down);
                }
                if ((x9y1 == 1) && (x0y1 + x9y0 == 0))
                {
                    AddTile(8, position, OcclusionTileset.TileRotation.right);
                }
                if ((x1y9 == 1) && (x0y9 + x1y0 == 0))
                {
                    AddTile(8, position, OcclusionTileset.TileRotation.left);
                }

                if (x1y0 == 1 && x0y1 == 1 && x0y9 == 1 && x9y0 == 1)
                {
                    AddTile(0, position, OcclusionTileset.TileRotation.up);
                    continue;
                }

                if (x1y0 == 0 && x0y1 == 1 && x0y9 == 1 && x9y0 == 1 && x1y1 == 1 && x1y9 == 1)
                {
                    AddTile(1, position, OcclusionTileset.TileRotation.up);
                    continue;
                }
                if (x9y0 == 0 && x0y1 == 1 && x0y9 == 1 && x1y0 == 1 && x9y9 == 1 && x9y1 == 1)
                {
                    AddTile(1, position, OcclusionTileset.TileRotation.down);
                    continue;
                }
                if (x0y9 == 0 && x0y1 == 1 && x9y0 == 1 && x1y0 == 1 && x9y9 == 1 && x1y9 == 1)
                {
                    AddTile(1, position, OcclusionTileset.TileRotation.left);
                    continue;
                }
                if (x0y1 == 0 && x0y9 == 1 && x9y0 == 1 && x1y0 == 1 && x9y1 == 1 && x1y1 == 1)
                {
                    AddTile(1, position, OcclusionTileset.TileRotation.right);
                    continue;
                }

                if (x0y1 == 1 && x1y0 == 1 && x9y1 == 1 && x1y9 == 1 && (x9y0 + x0y9 == 0))
                {
                    AddTile(3, position, OcclusionTileset.TileRotation.up);
                    continue;
                }
                if (x0y9 == 1 && x9y0 == 1 && x1y9 == 1 && x9y1 == 1 && (x1y0 + x0y1 == 0))
                {
                    AddTile(3, position, OcclusionTileset.TileRotation.down);
                    continue;
                }
                if (x0y1 == 1 && x9y0 == 1 && x1y1 == 1 && x9y9 == 1 && (x1y0 + x0y9 == 0))
                {
                    AddTile(3, position, OcclusionTileset.TileRotation.right);
                    continue;
                }
                if (x0y9 == 1 && x1y0 == 1 && x9y9 == 1 && x1y1 == 1 && (x9y0 + x0y1 == 0))
                {
                    AddTile(3, position, OcclusionTileset.TileRotation.left);
                    continue;
                }

                // SMOOTH CORNERS COMPLEX
                if (x0y1 == 1 && x1y0 == 1 && x9y1 == 1 && (x1y9 + x9y0 + x0y9 == 0))
                {
                    AddTile(4, position, OcclusionTileset.TileRotation.up, false, false);
                    continue;
                }
                if (x0y1 == 1 && x1y0 == 1 && x1y9 == 1 && (x9y1 + x9y0 + x0y9 == 0))
                {
                    AddTile(4, position, OcclusionTileset.TileRotation.right, true, false);
                    continue;
                }
                if (x0y9 == 1 && x9y0 == 1 && x1y9 == 1 && (x9y1 + x1y0 + x0y1 == 0))
                {
                    AddTile(4, position, OcclusionTileset.TileRotation.down, false, false);
                    continue;
                }
                if (x0y9 == 1 && x9y0 == 1 && x9y1 == 1 && (x1y9 + x1y0 + x0y1 == 0))
                {
                    AddTile(4, position, OcclusionTileset.TileRotation.left, true, false);
                    continue;
                }
                if (x9y0 == 1 && x0y1 == 1 && x1y1 == 1 && (x9y9 + x0y9 + x1y0 == 0))
                {
                    AddTile(4, position, OcclusionTileset.TileRotation.up, true, false);
                    continue;
                }
                if (x1y0 == 1 && x0y9 == 1 && x1y1 == 1 && (x9y9 + x0y1 + x9y0 == 0))
                {
                    AddTile(4, position, OcclusionTileset.TileRotation.left, false, false);
                    continue;
                }
                if (x1y0 == 1 && x0y9 == 1 && x9y9 == 1 && (x1y1 + x0y1 + x9y0 == 0))
                {
                    AddTile(4, position, OcclusionTileset.TileRotation.down, true, false);
                    continue;
                }
                if (x9y0 == 1 && x0y1 == 1 && x9y9 == 1 && (x1y1 + x0y9 + x1y0 == 0))
                {
                    AddTile(4, position, OcclusionTileset.TileRotation.right, false, false);
                    continue;
                }

                if (x0y1 == 1 && (x9y0 + x1y0 + x1y1 + x9y1 == 0))
                {
                    AddTile(5, position, OcclusionTileset.TileRotation.up);
                }
                if (x0y9 == 1 && (x9y0 + x1y0 + x1y9 + x9y9 == 0))
                {
                    AddTile(5, position, OcclusionTileset.TileRotation.down);
                }
                if (x9y0 == 1 && (x0y1 + x0y9 + x9y9 + x9y1 == 0))
                {
                    AddTile(5, position, OcclusionTileset.TileRotation.right);
                }
                if (x1y0 == 1 && (x0y1 + x0y9 + x1y9 + x1y1 == 0))
                {
                    AddTile(5, position, OcclusionTileset.TileRotation.left);
                }

                if (x0y1 == 1 && x1y1 == 1 && (x9y0 + x1y0 + x9y1 == 0))
                {
                    AddTile(7, position, OcclusionTileset.TileRotation.up, false, false);
                }
                if (x0y1 == 1 && x9y1 == 1 && (x9y0 + x1y0 + x1y1 == 0))
                {
                    AddTile(7, position, OcclusionTileset.TileRotation.up, true, false);
                }
                if (x0y9 == 1 && x9y9 == 1 && (x1y0 + x9y0 + x1y9 == 0))
                {
                    AddTile(7, position, OcclusionTileset.TileRotation.down, false, false);
                }
                if (x0y9 == 1 && x1y9 == 1 && (x1y0 + x9y0 + x9y9 == 0))
                {
                    AddTile(7, position, OcclusionTileset.TileRotation.down, true, false);
                }
                if (x1y0 == 1 && x1y1 == 1 && (x0y9 + x0y1 + x1y9 == 0))
                {
                    AddTile(7, position, OcclusionTileset.TileRotation.left, false, true);
                }
                if (x1y0 == 1 && x1y9 == 1 && (x0y9 + x0y1 + x1y1 == 0))
                {
                    AddTile(7, position, OcclusionTileset.TileRotation.left, false, false);
                }
                if (x9y0 == 1 && x9y1 == 1 && (x0y9 + x0y1 + x9y9 == 0))
                {
                    AddTile(7, position, OcclusionTileset.TileRotation.right, false, false);
                }
                if (x9y0 == 1 && x9y9 == 1 && (x0y9 + x0y1 + x9y1 == 0))
                {
                    AddTile(7, position, OcclusionTileset.TileRotation.left, true, false);
                }

                // SIMPLE UNFINISHED
                if (x0y1 == 1 && x1y1 == 1 && x9y1 == 1 && (x9y0 + x1y0 == 0))
                {
                    AddTile(6, position, OcclusionTileset.TileRotation.up, true, false);
                }
                if (x0y9 == 1 && x1y9 == 1 && x9y9 == 1 && (x1y0 + x9y0 == 0))
                {
                    AddTile(6, position, OcclusionTileset.TileRotation.down, true, false);
                }
                if (x1y0 == 1 && x1y1 == 1 && x1y9 == 1 && (x0y9 + x0y1 == 0))
                {
                    AddTile(6, position, OcclusionTileset.TileRotation.right, true, false);
                }
                if (x9y0 == 1 && x9y1 == 1 && x9y9 == 1 && (x0y9 + x0y1 == 0))
                {
                    AddTile(6, position, OcclusionTileset.TileRotation.left, true, false);
                }

                if (x0y1 == 1 && x9y0 == 1 && x0y9 == 1 && x1y9 == 1 && (x1y1 + x1y0 == 0))
                {
                    AddTile(9, position, OcclusionTileset.TileRotation.up, false, false);
                    continue;
                }
                if (x1y0 == 1 && x0y1 == 1 && x9y0 == 1 && x9y9 == 1 && (x1y9 + x0y9 == 0))
                {
                    AddTile(9, position, OcclusionTileset.TileRotation.left, false, false);
                    continue;
                }
                if (x9y0 == 1 && x0y9 == 1 && x1y0 == 1 && x1y1 == 1 && (x9y1 + x0y1 == 0))
                {
                    AddTile(9, position, OcclusionTileset.TileRotation.right, false, false);
                    continue;
                }
                if (x0y9 == 1 && x1y0 == 1 && x0y1 == 1 && x9y1 == 1 && (x9y9 + x9y0 == 0))
                {
                    AddTile(9, position, OcclusionTileset.TileRotation.down, false, false);
                    continue;
                }
                if (x1y1 == 1 && x0y1 == 1 && x9y0 == 1 && x0y9 == 1 && (x1y9 + x1y0 == 0))
                {
                    AddTile(9, position, OcclusionTileset.TileRotation.up, false, true);
                    continue;
                }
                if (x9y9 == 1 && x0y9 == 1 && x1y0 == 1 && x0y1 == 1 && (x9y1 + x9y0 == 0))
                {
                    AddTile(9, position, OcclusionTileset.TileRotation.down, false, true);
                    continue;
                }
                if (x9y1 == 1 && x9y0 == 1 && x0y9 == 1 && x1y0 == 1 && (x1y1 + x0y1 == 0))
                {
                    AddTile(9, position, OcclusionTileset.TileRotation.right, false, true);
                    continue;
                }
                if (x1y9 == 1 && x1y0 == 1 && x0y1 == 1 && x9y0 == 1 && (x9y9 + x0y9 == 0))
                {
                    AddTile(9, position, OcclusionTileset.TileRotation.left, false, true);
                    continue;
                }

                if (x9y0 == 1 && x0y9 == 1 && (x1y9 + x9y1 + x1y0 + x0y1 == 0))
                {
                    AddTile(2, position, OcclusionTileset.TileRotation.up);
                }
                if (x1y0 == 1 && x0y9 == 1 && (x9y9 + x1y1 + x9y0 + x0y1 == 0))
                {
                    AddTile(2, position, OcclusionTileset.TileRotation.right);
                }
                if (x1y0 == 1 && x0y1 == 1 && (x1y9 + x9y1 + x9y0 + x0y9 == 0))
                {
                    AddTile(2, position, OcclusionTileset.TileRotation.down);
                }
                if (x9y0 == 1 && x0y1 == 1 && (x9y9 + x1y1 + x0y9 + x1y0 == 0))
                {
                    AddTile(2, position, OcclusionTileset.TileRotation.left);
                }

                if (x0y1 == 1 && x9y0 == 1 && x0y9 == 1 && (x1y9 + x1y0 + x1y1 == 0))
                {
                    AddTile(10, position, OcclusionTileset.TileRotation.up);
                }
                if (x0y1 == 1 && x1y0 == 1 && x0y9 == 1 && (x9y9 + x9y0 + x9y1 == 0))
                {
                    AddTile(10, position, OcclusionTileset.TileRotation.down);
                }
                if (x9y0 == 1 && x0y9 == 1 && x1y0 == 1 && (x1y1 + x0y1 + x9y1 == 0))
                {
                    AddTile(10, position, OcclusionTileset.TileRotation.right);
                }
                if (x1y0 == 1 && x0y1 == 1 && x9y0 == 1 && (x9y9 + x0y9 + x1y9 == 0))
                {
                    AddTile(10, position, OcclusionTileset.TileRotation.left);
                }
            }
        }
    }