Ejemplo n.º 1
0
    // TODO: text position depends on screen aspect ratio!
//	void OnGUI()
//	{
//		if(targetMonster != null)
//			GUI.Label(textRect, numMonstersLeft + "x");
//	}

    public void PlayerIsNearby(Component monsterPrefab)
    {
        timePlayerWasNearby = Time.time;

        if (numMonstersLeft < 1)
        {
            // first quest, or previous quest completed

            if (numMonstersLeft != -100)
            {
                // quest completed
                GetComponent <ParticleSystem>().Play();
                player.QuestCompleted();
                monsterAttackSpeed = Mathf.Max(0.05f, monsterAttackSpeed * 0.9f);
            }

            print("NPC picked a new monster type");
            if (targetMonster != null)
            {
                Component.DestroyObject(targetMonster.gameObject);
            }
            numMonstersLeft = (int)(Random.value * (maxMonstersToKill - 0.01)) + 1;

            // make new texture for monster prefab
            var texture = TexGen.MakeTexture_RandomMirroredSprite(8, 0.5f);
            TexGen.SetSpriteFromTexture(monsterPrefab.GetComponent <Renderer>(), 0.1f, texture);
        }

        if (targetMonster == null)
        {
            print("spawned a monster target above NPC");
            targetMonster          = (Transform)Component.Instantiate(monsterPrefab);
            targetMonster.position = npcTargetMonsterPos;
        }
    }
Ejemplo n.º 2
0
        public override bool Place(Point origin, StructureMap structures)
        {
            //this handles generating the actual tiles, but you still need to add things like treegen etc. I know next to nothing about treegen so you're on your own there, lol.

            Mod mod = JetshiftMod.instance;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>();

            colorToTile[new Color(51, 51, 51)]    = -2;
            colorToTile[new Color(120, 120, 120)] = -2;
            colorToTile[new Color(150, 150, 150)] = -2;
            colorToTile[Color.Black] = -1;

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>();

            colorToWall[new Color(150, 150, 150)] = -1;
            colorToWall[Color.Black] = -1; //don't touch when genning

            TexGen gen       = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Worldgen/GreatDarkness"), colorToTile);
            Point  newOrigin = new Point(origin.X, origin.Y - 30);
            int    genX      = origin.X - (gen.width / 3);
            int    genY      = origin.Y - 25;

            gen.Generate(genX, genY, true, true);

            return(true);
        }
Ejemplo n.º 3
0
        public override bool Place(Point origin, StructureMap structures)
        {
            //this handles generating the actual tiles, but you still need to add things like treegen etc. I know next to nothing about treegen so you're on your own there, lol.

            Mod mod         = SauceMod.instance;
            int biomeRadius = 300;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>();

            colorToTile[new Color(0, 255, 0)] = -2;
            colorToTile[Color.Black]          = -1; //don't touch when genning


            Texture2D Infection = mod.GetTexture("WorldGen/SauceWorld_Tiles");

            TexGen gen       = BaseWorldGenTex.GetTexGenerator(Infection, colorToTile);
            Point  newOrigin = new Point(origin.X, origin.Y);                                       //biomeRadius);

            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //remove all fluids in sphere...
            {
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new Actions.SetLiquid(0, 0)
            }));
            WorldUtils.Gen(new Point(origin.X - (gen.width / 2), origin.Y - 20), new Shapes.Rectangle(gen.width, gen.height), Actions.Chain(new GenAction[] //remove all fluids in the volcano...
            {
                new Actions.SetLiquid(0, 0)
            }));
            gen.Generate(origin.X - (gen.width / 2), origin.Y, true, true);

            return(true);
        }
Ejemplo n.º 4
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Mod mod = CSkies.inst;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>
            {
                [new Color(255, 0, 0)]     = ModContent.TileType <HeatEngineBrickUnsafe>(),
                [new Color(255, 255, 0)]   = ModContent.TileType <HeatGlass>(),
                [new Color(255, 0, 255)]   = ModContent.TileType <CoreValve>(),
                [new Color(0, 0, 255)]     = ModContent.TileType <ScrapHeap>(),
                [new Color(255, 255, 255)] = -1,
                [Color.Black] = -2
            };

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>
            {
                [new Color(0, 255, 0)] = ModContent.WallType <HeatEngineWallUnsafe>(),
                [new Color(255, 0, 0)] = ModContent.WallType <HeatCircuitWall>(),
                [Color.Black]          = -1
            };

            TexGen gen = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Worldgen/MagmaCore"), colorToTile, mod.GetTexture("Worldgen/MagmaCoreWalls"), colorToWall, mod.GetTexture("Worldgen/MagmaCore_Lava"), mod.GetTexture("Worldgen/MagmaCore_Slope"));

            gen.Generate(origin.X, origin.Y, true, true);

            return(true);
        }
Ejemplo n.º 5
0
        public bool UpdateRadius(TexGen surfaceTexGen, Vector3 currentSurfacePoint)
        {
            var handleSize     = CSG_HandleUtility.GetHandleSize(this.RotateCenterPoint);
            var vectorToCenter = currentSurfacePoint - this.RotateCenterPoint;

            this.RotateRadius = vectorToCenter.magnitude;
            vectorToCenter.Normalize();

            var rotateCurrentAngle = 0.0f;

            if (!this.HaveRotateStartAngle)
            {
                if (this.RotateRadius > handleSize * GUIConstants.minRotateRadius)
                {
                    this.HaveRotateStartAngle    = true;
                    this.RotateOriginalAngle     = surfaceTexGen.RotationAngle;
                    this.RotateStartVector       = vectorToCenter;
                    this.RotateCurrentStartAngle = GeometryUtility.SignedAngle(this.RotateSurfaceTangent, vectorToCenter, this.RotateSurfaceNormal);
                }
                this.RotateRadius = Math.Max(this.RotateRadius, handleSize * GUIConstants.minRotateRadius);
            }
            else
            {
                rotateCurrentAngle = GeometryUtility.SignedAngle(this.RotateStartVector, vectorToCenter, this.RotateSurfaceNormal);
                var minSize        = handleSize * GUIConstants.minRotateRadius * 2;
                var radiusStepSize = minSize;
                this.RotateRadius = (Mathf.CeilToInt(((this.RotateRadius - minSize) / radiusStepSize) - 0.5f) * radiusStepSize) + minSize;
            }

            // snap texture coordinates in world/local space
            this.RotateCurrentSnappedAngle = GridUtility.SnappedAngle(this.RotateOriginalAngle + rotateCurrentAngle) - this.RotateOriginalAngle;

            return(this.HaveRotateStartAngle);
        }
Ejemplo n.º 6
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Mod mod = CSkies.inst;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>
            {
                [new Color(0, 0, 255)]     = ModContent.TileType <AbyssBricks>(),
                [new Color(0, 255, 0)]     = ModContent.TileType <AbyssDoor>(),
                [new Color(255, 0, 0)]     = ModContent.TileType <AbyssStone>(),
                [new Color(255, 0, 255)]   = ModContent.TileType <AbyssGrass>(),
                [new Color(255, 255, 255)] = -2,
                [Color.Black] = -1
            };

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>
            {
                [new Color(0, 0, 255)] = ModContent.WallType <AbyssWall>(),
                [Color.Black]          = -1
            };

            TexGen gen = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Worldgen/AbyssVaultPlanet"), colorToTile, mod.GetTexture("Worldgen/AbyssVaultPlanetWall"), colorToWall, null, mod.GetTexture("Worldgen/AbyssVaultPlanetSlopes"));

            gen.Generate(origin.X, origin.Y, true, true);

            CUtils.ObectPlace(origin.X + 32, origin.Y + 34, mod.TileType("HeartAltar1"));

            return(true);
        }
Ejemplo n.º 7
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Mod mod = DBTMod.Instance;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>
            {
                [new Color(54, 50, 255)] = TileID.Titanstone,
                [Color.Black]            = -1
            };

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>
            {
                [new Color(255, 229, 0)]  = WallID.DiamondGemspark,
                [new Color(255, 97, 0)]   = WallID.DiamondGemsparkOff,
                [new Color(242, 0, 255)]  = WallID.SapphireGemsparkOff,
                [new Color(148, 255, 48)] = WallID.Cloud,
                [Color.Black]             = -1
            };

            TexGen gen = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Generation/GravChamberTiles"), colorToTile, mod.GetTexture("Generation/GravChamberWalls"), colorToWall, null, mod.GetTexture("Generation/GravChamberSlopes"));

            gen.Generate(origin.X, origin.Y, true, true);

            return(true);
        }
Ejemplo n.º 8
0
        public override bool Place(Point origin, StructureMap structures)
        {
            //this handles generating the actual tiles, but you still need to add things like treegen etc. I know next to nothing about treegen so you're on your own there, lol.

            Mod mod         = CelestialMod.instance;
            int worldSize   = GetWorldSize();
            int biomeRadius = worldSize == 3 ? 400 : worldSize == 2 ? 300 : 200;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>();

            colorToTile[new Color(0, 0, 255)]     = mod.TileType("VoidicGrass");
            colorToTile[new Color(0, 255, 0)]     = mod.TileType("VoidicStone");
            colorToTile[new Color(0, 125, 0)]     = mod.TileType("VoidicMud");
            colorToTile[new Color(0, 191, 255)]   = mod.TileType("CelestialRemnantsTempleTile");
            colorToTile[new Color(127, 0, 55)]    = mod.TileType("GloomWoodPlatform");
            colorToTile[new Color(128, 128, 128)] = TileID.Spikes;
            colorToTile[new Color(255, 0, 0)]     = -2; //turn into air
            colorToTile[Color.Black] = -1;              //don't touch when genning

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>();

            colorToWall[new Color(0, 0, 255)]   = mod.WallType("VoidicSoilWall");
            colorToWall[new Color(255, 0, 110)] = mod.WallType("CelestialRemnantsTempleWall");

            colorToWall[new Color(255, 0, 0)] = -2;
            colorToWall[Color.Black]          = -1; //don't touch when genning


            Texture2D yeet1 = mod.GetTexture("WorldGeneration/CrimsonSeptetteFiles/CrimsonSeptette");
            Texture2D yeet2 = mod.GetTexture("WorldGeneration/CrimsonSeptetteFiles/CrimsonSeptetteWall");

            if (CrimsonSeptetteBegin == null)
            {
                CrimsonSeptetteBegin = yeet1;

                CrimsonSeptetteWalls = yeet2;
            }

            TexGen gen       = BaseWorldGenTex.GetTexGenerator(CrimsonSeptetteBegin, colorToTile, CrimsonSeptetteWalls, colorToWall);
            Point  newOrigin = new Point(origin.X, origin.Y);                                       //biomeRadius);

            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //remove all fluids in sphere...
            {
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new Actions.SetLiquid(0, 0)
            }));
            WorldUtils.Gen(new Point(origin.X, origin.Y - 60), new Shapes.Rectangle(gen.width, gen.height), Actions.Chain(new GenAction[] //remove all fluids in the volcano...
            {
                new Actions.SetLiquid(0, 0)
            }));

            int genX = origin.X;
            int genY = origin.Y - 60;

            gen.Generate(genX, genY, true, true);

            return(true);
        }
Ejemplo n.º 9
0
    void Start()
    {
        numMonstersLeft = -100;

        // generate texture for NPC
        var texture = TexGen.MakeTexture_RandomMirroredSprite(8, 0.6f, Color.green, 13);

        TexGen.SetSpriteFromTexture(GetComponent <Renderer>(), 0.1f, texture);
    }
Ejemplo n.º 10
0
        static void TestTexGen()
        {
            TexGen generator;
            ColorSet colors;
            Texture image;
            bool grayscale = true;

            image = ImageBMP.OpenBitmap("medium_gray_stone.bmp", 0);
            colors = new ColorSet();
            colors.TrainFromTexture(image, 0, grayscale);
            generator = new TexGen(colors, 2, 2);
            generator.AddTexture(image, grayscale);
            //            generator.TrainFromTexture(image, 16, 16, grayscale);
            Texture output = generator.GenerateTexture(200, 200, 1);
            ImageBMP.WriteBitmap("output.bmp", output);
        }
Ejemplo n.º 11
0
        public void TryFindPlaneMaterial(CSGPlane buildPlane)
        {
            var uniqueBrushes = new HashSet <CSGBrush>();

            foreach (var brush in onBrushVertices)
            {
                if (brush)
                {
                    uniqueBrushes.Add(brush);
                }
            }

            foreach (var brush in uniqueBrushes)
            {
                var surfaces  = brush.Shape.Surfaces;
                var materials = brush.Shape.Materials;
                var texgens   = brush.Shape.TexGens;

                var worldToLocalMatrix = brush.transform.worldToLocalMatrix;
                var localPosition      = worldToLocalMatrix.MultiplyPoint(buildPlane.pointOnPlane);
                var localDirection     = worldToLocalMatrix.MultiplyVector(buildPlane.normal);

                for (int surfaceIndex = 0; surfaceIndex < surfaces.Length; surfaceIndex++)
                {
                    var surface = surfaces[surfaceIndex];
                    var dist    = Mathf.Abs(surface.Plane.Distance(localPosition));
                    if (dist > MathConstants.DistanceEpsilon)
                    {
                        continue;
                    }
                    var alignment = Mathf.Abs(Vector3.Dot(surface.Plane.normal, localDirection));
                    if (alignment < 1 - MathConstants.NormalEpsilon)
                    {
                        continue;
                    }

                    var texGenIndex = surface.TexGenIndex;
                    planeMaterial = materials[texGenIndex];
                    planeTexgen   = texgens[texGenIndex];
                    break;
                }
            }
        }
Ejemplo n.º 12
0
        public override bool Place(Point origin, StructureMap structures)
        {
            //this handles generating the actual tiles, but you still need to add things like treegen etc. I know next to nothing about treegen so you're on your own there, lol.

            Mod mod         = CelestialMod.instance;
            int worldSize   = GetWorldSize();
            int biomeRadius = worldSize == 3 ? 400 : worldSize == 2 ? 300 : 200;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>();

            colorToTile[new Color(0, 0, 255)] = -2;
            colorToTile[Color.Black]          = -1; //don't touch when genning


            Texture2D yeet = mod.GetTexture("WorldGeneration/FloweringNightsFiles/FloweringNightsDelete");

            if (FloweringNightsBegin == null)
            {
                FloweringNightsBegin = yeet;
            }

            TexGen gen       = BaseWorldGenTex.GetTexGenerator(yeet, colorToTile);
            Point  newOrigin = new Point(origin.X, origin.Y);                                       //biomeRadius);

            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //remove all fluids in sphere...
            {
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new Actions.SetLiquid(0, 0)
            }));
            WorldUtils.Gen(new Point(origin.X, origin.Y - 60), new Shapes.Rectangle(gen.width, gen.height), Actions.Chain(new GenAction[] //remove all fluids in the volcano...
            {
                new Actions.SetLiquid(0, 0)
            }));

            int genX = origin.X;
            int genY = origin.Y - 60;

            gen.Generate(genX, genY, true, true);

            return(true);
        }
Ejemplo n.º 13
0
        public static void ChineseTeaHouse()
        {
            Mod mod = CelestialMod.instance;
            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>();

            colorToTile[new Color(0, 0, 255)] = mod.TileType("VoidicGrass");
            colorToTile[new Color(0, 255, 0)] = mod.TileType("VoidicStone");
            colorToTile[new Color(0, 125, 0)] = mod.TileType("VoidicMud");
            colorToTile[new Color(255, 0, 0)] = -2;            //turn into air
            colorToTile[Color.Black]          = -1;            //don't touch when genning

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>();

            colorToWall[new Color(0, 0, 255)] = mod.WallType("VoidicSoilWall");
            colorToWall[new Color(255, 0, 0)] = -2;
            colorToWall[Color.Black]          = -1;            //don't touch when genning

            TexGen gen = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("WorldGeneration/ChineseTeaHouseFiles/ChineseTeaHouse"), colorToTile, mod.GetTexture("WorldGeneration/ChineseTeaHouseFiles/ChineseTeaHouseWalls"), colorToWall, mod.GetTexture("WorldGeneration/ChineseTeaHouseFiles/ChineseTeaHouseLiquids"), mod.GetTexture("WorldGeneration/ChineseTeaHouseFiles/ChineseTeaHouseSlopes"));

            gen.Generate(0, 0, true, true);
        }
Ejemplo n.º 14
0
        public override bool UseItem(Player player)
        {
            Mod mod = AAMod.instance;
            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>();

            colorToTile[new Color(255, 0, 0)]     = mod.TileType("Torchstone");
            colorToTile[new Color(0, 0, 255)]     = mod.TileType("Torchstone");
            colorToTile[new Color(150, 150, 150)] = -2; //turn into air
            colorToTile[Color.Black] = -1;              //don't touch when genning

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>();

            colorToWall[new Color(255, 0, 0)] = mod.WallType("TorchstoneWall");
            colorToWall[Color.Black]          = -1; //don't touch when genning

            TexGen gen    = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Worldgeneration/Volcano"), colorToTile, mod.GetTexture("Worldgeneration/VolcanoWalls"), colorToWall, mod.GetTexture("Worldgeneration/VolcanoLava"));
            Point  origin = new Point((int)(player.Center.X / 16f), (int)(player.Center.Y / 16f));

            origin.Y = BaseWorldGen.GetFirstTileFloor(origin.X, origin.Y, true);
            gen.Generate(origin.X, origin.Y - 40, true, true);
            return(true);
        }
Ejemplo n.º 15
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Mod mod = DBTMod.Instance;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>
            {
                [new Color(152, 74, 0)]    = ModContent.TileType <HardenedRock>(),
                [new Color(255, 181, 81)]  = ModContent.TileType <CoarseRock>(),
                [new Color(255, 212, 171)] = -2,
                [Color.Black] = -1
            };

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>
            {
                [new Color(103, 50, 0)] = ModContent.WallType <CoarseRockWall>(),
                [Color.Black]           = -2
            };

            TexGen gen = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Generation/SaibaNestTiles"), colorToTile, mod.GetTexture("Generation/SaibaNestWalls"), colorToWall, null, mod.GetTexture("Generation/SaibaNestSlopes"));

            gen.Generate(origin.X, origin.Y, true, true);

            return(true);
        }
Ejemplo n.º 16
0
        private static void GenTiles(int x, int y)
        {
            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>
            {
                //color to tile, these are all the color coded tiles, you can replace these with your own custom tiles of course
                [new Color(166, 215, 222)] = ModContent.TileType <BarrenDirtTile>(),
                [new Color(91, 124, 143)]  = ModContent.TileType <BarrenStoneTile>(),
                [new Color(255, 255, 255)] = -1, //leaving something white will not be affected during gen
                [Color.Black] = -2               //turn into air
            };

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>
            {
                //color to wall, same thing as above but for walls, and change these to what you want
                // [new Color(47, 0, 93)] = ModContent.WallType<BarrenWall>(),
                [Color.Black] = -2, //turn into air
            };

            TexGen gen = BaseWorldGenTex.GetTexGenerator(GetTexture("Depth/BarrenBiome/BarrenBiome"), colorToTile, GetTexture("Depth/BarrenBiome/BarrenBiomeWalls"), colorToWall);

            gen.Generate(x - (gen.width / 2), y - (gen.height / 2), true, true);

            //WorldGen.PlaceChest(x - 2, y + 202, (ushort)ModContent.TileType<Backpack>()); ///this code places a chest at a certain coordinate in the shadow biome, just ignore this lmao
        }
Ejemplo n.º 17
0
        public override bool Place(Point origin, StructureMap structures)
        {
            //this handles generating the actual tiles, but you still need to add things like treegen etc. I know next to nothing about treegen so you're on your own there, lol.

            Mod  mod = AAMod.instance; //replace with your own
            bool DEV = true;
            //--- Initial variable creation
            ushort tileGrass = (ushort)mod.TileType("InfernoGrass"), tileStone = (ushort)mod.TileType("Torchstone"),
                   tileIce = (ushort)mod.TileType("Torchice"), tileSand = (ushort)mod.TileType("Torchsand"), tileSandHardened = (ushort)mod.TileType("TorchsandHardened"), tileSandstone = (ushort)mod.TileType("Torchsandstone");

            int worldSize = GetWorldSize();
            int biomeRadius = (worldSize == 3 ? 180 : worldSize == 2 ? 150 : 120), biomeRadiusHalf = biomeRadius / 2; //how deep the biome is (scaled by world size)

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>();

            colorToTile[new Color(255, 0, 0)]     = mod.TileType("Torchstone");
            colorToTile[new Color(0, 0, 255)]     = mod.TileType("Torchstone");
            colorToTile[new Color(150, 150, 150)] = -2; //turn into air
            colorToTile[Color.Black] = -1;              //don't touch when genning

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>();

            colorToWall[new Color(255, 0, 0)] = mod.WallType("TorchstoneWall");
            colorToWall[Color.Black]          = -1; //don't touch when genning

            TexGen gen       = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Worldgeneration/Volcano"), colorToTile, mod.GetTexture("Worldgeneration/VolcanoWalls"), colorToWall, mod.GetTexture("Worldgeneration/VolcanoLava"));
            Point  newOrigin = new Point(origin.X, origin.Y - 30);                                  //biomeRadius);

            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //remove all fluids in sphere...
            {
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new Actions.SetLiquid(0, 0)
            }));
            WorldUtils.Gen(new Point(origin.X - (gen.width / 2), origin.Y - 20), new Shapes.Rectangle(gen.width, gen.height), Actions.Chain(new GenAction[] //remove all fluids in the volcano...
            {
                new Actions.SetLiquid(0, 0)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[]             //gen grass...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.Grass, TileID.CorruptGrass, TileID.FleshGrass }), //ensure we only replace the intended tile (in this case, grass)
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),                                       //this provides the 'blending' on the edges (except the top)
                new BaseMod.SetModTile(tileGrass, true, true)                                                   //actually place the tile
            }));

            /* WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //dirt...
             *           {
             *   new Modifiers.OnlyTiles(new ushort[]{ TileID.Dirt }),
             *   new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
             *   new BaseMod.SetModTile(tileDirt, true, true)
             * }));*/
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //and stone.
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.Stone }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileStone, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //ice...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.IceBlock, TileID.CorruptIce, TileID.FleshIce }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileIce, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //sand...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.Sand, TileID.Ebonsand, TileID.Crimsand }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileSand, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //hardened sand...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.HardenedSand, TileID.CorruptHardenedSand, TileID.CrimsonHardenedSand }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileSandHardened, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[]             //...and sandstone.
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.Sandstone, TileID.CorruptSandstone, TileID.CrimsonSandstone }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileSandstone, true, true)
            }));
            gen.Generate(origin.X - (gen.width / 2), origin.Y - 20, true, true);

            return(true);
        }
Ejemplo n.º 18
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Mod    mod = CSkies.inst;
            ushort tileGrass = (ushort)ModContent.TileType <AbyssGrass>(), tileStone = (ushort)ModContent.TileType <AbyssStone>(), tileIce = (ushort)ModContent.TileType <Abice>(),
                   tileSand = (ushort)ModContent.TileType <AbyssSand>(), tileSandHardened = (ushort)ModContent.TileType <HardenedAbyssSand>(), tileSandstone = (ushort)ModContent.TileType <AbyssSandstone>(),
                   tileMoss = (ushort)ModContent.TileType <AbyssMoss>();

            byte StoneWall = (byte)ModContent.WallType <AbyssStoneWall>(), SandstoneWall = (byte)ModContent.WallType <AbyssSandstoneWall>(), HardenedSandWall = (byte)ModContent.WallType <HardenedAbyssSandWall>(),
                 GrassWall = (byte)ModContent.WallType <AbyssLeafWall>();

            int biomeRadius = 89;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>
            {
                [new Color(0, 0, 255)]     = mod.TileType("AbyssBricks"),
                [new Color(0, 255, 0)]     = mod.TileType("AbyssDoor"),
                [new Color(255, 255, 255)] = -2,
                [Color.Black] = -1
            };

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>
            {
                [new Color(255, 255, 255)] = mod.WallType("AbyssWall"),
                [Color.Black] = -1
            };

            TexGen gen = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Worldgen/AbyssVault"), colorToTile, mod.GetTexture("Worldgen/AbyssVaultWall"), colorToWall, null, mod.GetTexture("Worldgen/AbyssVaultSlopes"));

            Point newOrigin = new Point(origin.X, origin.Y);

            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //grass...
            {
                new InWorld(),
                new Modifiers.OnlyTiles(new ushort[] { TileID.Grass, TileID.CorruptGrass, TileID.FleshGrass, TileID.HallowedGrass }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new SetModTile(tileGrass, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //moss...
            {
                new InWorld(),
                new Modifiers.OnlyTiles(new ushort[] { TileID.BlueMoss, TileID.BrownMoss, TileID.GreenMoss, TileID.LavaMoss, TileID.LongMoss, TileID.PurpleMoss, TileID.RedMoss }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new SetModTile(tileMoss, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //stone...
            {
                new InWorld(),
                new Modifiers.OnlyTiles(new ushort[] { TileID.Stone, TileID.Ebonstone, TileID.Crimstone, TileID.Pearlstone }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new SetModTile(tileStone, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //ice...
            {
                new InWorld(),
                new Modifiers.OnlyTiles(new ushort[] { TileID.IceBlock, TileID.CorruptIce, TileID.FleshIce }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new SetModTile(tileIce, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //sand...
            {
                new InWorld(),
                new Modifiers.OnlyTiles(new ushort[] { TileID.Sand, TileID.Ebonsand, TileID.Crimsand }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new SetModTile(tileSand, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //hardened sand...
            {
                new InWorld(),
                new Modifiers.OnlyTiles(new ushort[] { TileID.HardenedSand, TileID.CorruptHardenedSand, TileID.CrimsonHardenedSand }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new SetModTile(tileSandHardened, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //...and sandstone.
            {
                new InWorld(),
                new Modifiers.OnlyTiles(new ushort[] { TileID.Sandstone, TileID.CorruptSandstone, TileID.CrimsonSandstone }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new SetModTile(tileSandstone, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //Walls
            {
                new InWorld(),
                new Modifiers.OnlyWalls(new byte[] { WallID.Stone, WallID.EbonstoneUnsafe, WallID.CrimstoneUnsafe }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new PlaceModWall(StoneWall, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //Walls
            {
                new InWorld(),
                new Modifiers.OnlyWalls(new byte[] { WallID.Sandstone, WallID.CorruptSandstone, WallID.CrimsonSandstone }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new PlaceModWall(SandstoneWall, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //Walls
            {
                new InWorld(),
                new Modifiers.OnlyWalls(new byte[] { WallID.HardenedSand, WallID.CorruptHardenedSand, WallID.CrimsonHardenedSand }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new PlaceModWall(HardenedSandWall, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //Walls
            {
                new InWorld(),
                new Modifiers.OnlyWalls(new byte[] { WallID.HardenedSand, WallID.CorruptHardenedSand, WallID.CrimsonHardenedSand }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new PlaceModWall(HardenedSandWall, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //Walls
            {
                new InWorld(),
                new Modifiers.OnlyWalls(new byte[] { WallID.GrassUnsafe, WallID.CorruptGrassUnsafe, WallID.CrimsonGrassUnsafe }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new PlaceModWall(GrassWall, true)
            }));

            int genX = origin.X - (gen.width / 2);
            int genY = origin.Y - 30;

            gen.Generate(genX, genY, true, true);

            if (CWorld.VaultCount == 0)
            {
                CUtils.ObectPlace(genX + 29, genY + 31, mod.TileType("HeartAltar2"));
            }
            else if (CWorld.VaultCount == 1)
            {
                CUtils.ObectPlace(genX + 29, genY + 31, mod.TileType("HeartAltar3"));
            }
            else if (CWorld.VaultCount == 2)
            {
                CUtils.ObectPlace(genX + 29, genY + 31, mod.TileType("HeartAltar4"));
            }

            return(true);
        }
Ejemplo n.º 19
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Mod mod = CSkies.inst;

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>
            {
                [new Color(0, 255, 0)]     = ModContent.TileType <StarBrickUnsafe>(),
                [new Color(255, 0, 0)]     = ModContent.TileType <StarglassUnsafe>(),
                [new Color(0, 0, 255)]     = ModContent.TileType <StarCircuitUnsafe>(),
                [new Color(255, 255, 255)] = -2,
                [Color.Black] = -1
            };

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>
            {
                [new Color(0, 255, 0)] = ModContent.WallType <StarBrickWallUnsafe>(),
                [new Color(255, 0, 0)] = ModContent.WallType <StarglassWallUnsafe>(),
                [new Color(0, 0, 255)] = ModContent.WallType <StarCircuitWallUnsafe>(),
                [Color.Black]          = -1
            };

            TexGen gen = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Worldgen/Observatory"), colorToTile, mod.GetTexture("Worldgen/ObservatoryWalls"), colorToWall, null, mod.GetTexture("Worldgen/ObservatorySlopes"));

            gen.Generate(origin.X, origin.Y, true, true);

            #region Decorations

            CUtils.ObectPlace(origin.X + 145, origin.Y + 118, mod.TileType("BrokenArtemis"));

            #region Lanterns
            CUtils.ObectPlace(origin.X + 134, origin.Y + 57, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 165, origin.Y + 57, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 54, origin.Y + 63, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 59, origin.Y + 63, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 240, origin.Y + 63, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 245, origin.Y + 63, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 41, origin.Y + 66, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 258, origin.Y + 66, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 129, origin.Y + 70, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 170, origin.Y + 70, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 40, origin.Y + 75, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 70, origin.Y + 75, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 78, origin.Y + 75, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 81, origin.Y + 75, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 218, origin.Y + 75, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 221, origin.Y + 75, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 229, origin.Y + 75, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 259, origin.Y + 75, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 89, origin.Y + 80, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 210, origin.Y + 80, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 71, origin.Y + 88, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 76, origin.Y + 88, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 223, origin.Y + 88, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 228, origin.Y + 88, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 33, origin.Y + 91, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 37, origin.Y + 91, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 44, origin.Y + 91, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 255, origin.Y + 91, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 262, origin.Y + 91, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 266, origin.Y + 91, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 34, origin.Y + 99, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 37, origin.Y + 99, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 262, origin.Y + 99, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 265, origin.Y + 99, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 67, origin.Y + 102, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 70, origin.Y + 102, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 229, origin.Y + 102, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 232, origin.Y + 102, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 37, origin.Y + 111, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 79, origin.Y + 111, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 220, origin.Y + 111, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 262, origin.Y + 111, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 93, origin.Y + 112, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 96, origin.Y + 112, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 99, origin.Y + 112, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 200, origin.Y + 112, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 203, origin.Y + 112, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 206, origin.Y + 112, mod.TileType("ObservatoryLantern"));

            CUtils.ObectPlace(origin.X + 79, origin.Y + 123, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 82, origin.Y + 123, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 85, origin.Y + 123, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 88, origin.Y + 123, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 211, origin.Y + 123, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 214, origin.Y + 123, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 217, origin.Y + 123, mod.TileType("ObservatoryLantern"));
            CUtils.ObectPlace(origin.X + 220, origin.Y + 123, mod.TileType("ObservatoryLantern"));

            #endregion

            #region Chandeliers
            CUtils.ObectPlace(origin.X + 140, origin.Y + 48, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 159, origin.Y + 48, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 31, origin.Y + 66, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 269, origin.Y + 66, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 100, origin.Y + 80, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 106, origin.Y + 80, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 112, origin.Y + 80, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 118, origin.Y + 80, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 181, origin.Y + 80, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 187, origin.Y + 80, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 193, origin.Y + 80, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 199, origin.Y + 80, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 40, origin.Y + 83, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 45, origin.Y + 83, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 254, origin.Y + 83, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 259, origin.Y + 83, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 6, origin.Y + 93, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 293, origin.Y + 93, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 103, origin.Y + 90, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 196, origin.Y + 90, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 95, origin.Y + 91, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 203, origin.Y + 91, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 49, origin.Y + 99, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 250, origin.Y + 99, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 63, origin.Y + 102, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 73, origin.Y + 102, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 225, origin.Y + 102, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 236, origin.Y + 102, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 15, origin.Y + 103, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 20, origin.Y + 103, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 278, origin.Y + 103, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 284, origin.Y + 103, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 29, origin.Y + 107, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 270, origin.Y + 107, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 44, origin.Y + 111, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 50, origin.Y + 111, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 133, origin.Y + 111, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 166, origin.Y + 111, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 249, origin.Y + 111, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 254, origin.Y + 111, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 16, origin.Y + 112, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 283, origin.Y + 112, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 128, origin.Y + 121, mod.TileType("ObservatoryChandelier"));
            CUtils.ObectPlace(origin.X + 171, origin.Y + 121, mod.TileType("ObservatoryChandelier"));
            #endregion

            #endregion

            return(true);
        }
Ejemplo n.º 20
0
        public static void FixMaterials(Vector3[]                       originalVertices,
                                        List <ShapePolygon> polygons,
                                        Quaternion rotation,
                                        Vector3 origin,
                                        CSGPlane buildPlane,
                                        Material[]                      edgeMaterials = null,
                                        TexGen[]                        edgeTexgens   = null,
                                        ShapeEdge[]                     shapeEdges    = null)
        {
            if (shapeEdges != null)
            {
                for (int e = 0; e < shapeEdges.Length; e++)
                {
                    shapeEdges[e].EdgeIndex    = -1;
                    shapeEdges[e].PolygonIndex = -1;
                }
            }

            for (int p = 0; p < polygons.Count; p++)
            {
                var shapePolygon = polygons[p];
                var vertices3d   = shapePolygon.Vertices;

                var shapeMaterials = new Material[vertices3d.Length];
                var shapeTexgens   = new TexGen[vertices3d.Length];
                //var shapeTexgenFlags	= new TexGenFlags[vertices3d.Length];

                if (edgeMaterials != null &&
                    edgeTexgens != null)
                {
                    var indices = new int[vertices3d.Length];
                    for (int n0 = 0; n0 < vertices3d.Length; n0++)
                    {
                        indices[n0] = -1;
                        for (int n1 = 0; n1 < originalVertices.Length; n1++)
                        {
                            float diff = (vertices3d[n0] - originalVertices[n1]).sqrMagnitude;
                            if (diff > MathConstants.EqualityEpsilonSqr)
                            {
                                continue;
                            }

                            indices[n0] = n1;
                            break;
                        }
                    }

                    for (int n0 = indices.Length - 1, n1 = 0; n1 < indices.Length; n0 = n1, n1++)
                    {
                        var vertex0 = indices[n0] % edgeMaterials.Length;
                        var vertex1 = indices[n1] % edgeMaterials.Length;

                        if (vertex0 == -1 || vertex1 == -1)
                        {
                            shapeMaterials[n1] = CSGSettings.DefaultMaterial;
                            shapeTexgens[n1]   = new TexGen(n0);
                            //shapeTexgenFlags[n1]	= TexGenFlags.Discarded;
                        }
                        else
                        if ((Mathf.Abs(vertex1 - vertex0) == 1 ||
                             vertex0 == vertices3d.Length - 1 && vertex1 == 0))
                        {
                            if (shapeEdges != null)
                            {
                                shapeEdges[vertex0].PolygonIndex = p;
                                shapeEdges[vertex0].EdgeIndex    = n1;
                            }
                            shapeMaterials[n1] = edgeMaterials[vertex0];
                            shapeTexgens  [n1] = edgeTexgens[vertex0];
                            //shapeTexgenFlags[n1]	= TexGenFlags.None;
                        }
                        else
                        {
                            shapeMaterials[n1] = edgeMaterials[vertex0];                            // CSGSettings.DefaultMaterial;
                            shapeTexgens  [n1] = new TexGen(n0);
                            //shapeTexgenFlags[n1]	= TexGenFlags.None;
                        }
                    }
                }
                else
                {
                    for (int n0 = 0; n0 < vertices3d.Length; n0++)
                    {
                        shapeMaterials[n0] = CSGSettings.DefaultMaterial;
                        shapeTexgens[n0]   = new TexGen(n0);
                        //shapeTexgenFlags[n0]	= TexGenFlags.None;
                    }
                }

                shapePolygon.EdgeMaterials = shapeMaterials;
                shapePolygon.EdgeTexgens   = shapeTexgens;

                ShapePolygonUtility.RemoveDuplicatePoints(shapePolygon);
            }
        }
Ejemplo n.º 21
0
        public static bool GenerateControlMeshFromVertices(ShapePolygon shape2DPolygon,
                                                           Matrix4x4 localToWorld,
                                                           Vector3 direction,
                                                           float height,
                                                           Material capMaterial,
                                                           TexGen capTexgen,
                                                           bool?smooth,
                                                           bool singleSurfaceEnds,                                                                                 //Plane buildPlane,
                                                           out ControlMesh controlMesh,
                                                           out Shape shape)
        {
            if (shape2DPolygon == null)
            {
                controlMesh = null;
                shape       = null;
                return(false);
            }

            var vertices = shape2DPolygon.Vertices;

            if (vertices.Length < 3)
            {
                controlMesh = null;
                shape       = null;
                return(false);
            }
            if (height == 0.0f)
            {
                controlMesh = null;
                shape       = null;
                return(false);
            }

            Vector3 from;
            Vector3 to;

            if (height > 0)
            {
                @from = direction * height;                // buildPlane.normal * height;
                to    = MathConstants.zeroVector3;
            }
            else
            {
                @from = MathConstants.zeroVector3;
                to    = direction * height;               //buildPlane.normal * height;
            }

            var count           = vertices.Length;
            var doubleCount     = (count * 2);
            var extraPoints     = 0;
            var extraEdges      = 0;
            var endsPolygons    = 2;
            var startEdgeOffset = doubleCount;

            if (!singleSurfaceEnds)
            {
                extraPoints      = 2;
                extraEdges       = (4 * count);
                endsPolygons     = doubleCount;
                startEdgeOffset += extraEdges;
            }


            var dstPoints   = new Vector3 [doubleCount + extraPoints];
            var dstEdges    = new HalfEdge[(count * 6) + extraEdges];
            var dstPolygons = new Polygon [count + endsPolygons];

            var center1 = MathConstants.zeroVector3;
            var center2 = MathConstants.zeroVector3;


            for (int i = 0; i < count; i++)
            {
                var point1 = vertices[i];
                var point2 = vertices[(count + i - 1) % count];

                point1 += @from;
                point2 += to;

                // swap y/z to solve texgen issues
                dstPoints[i].x = point1.x;
                dstPoints[i].y = point1.y;
                dstPoints[i].z = point1.z;

                center1 += dstPoints[i];

                dstEdges [i].VertexIndex = (short)i;
                dstEdges [i].HardEdge    = true;

                // swap y/z to solve texgen issues
                dstPoints[i + count].x = point2.x;
                dstPoints[i + count].y = point2.y;
                dstPoints[i + count].z = point2.z;
                center2 += dstPoints[i + count];

                dstEdges [i + count].VertexIndex = (short)(i + count);
                dstEdges [i + count].HardEdge    = true;
            }

            if (!singleSurfaceEnds)
            {
                dstPoints[doubleCount]     = center1 / count;
                dstPoints[doubleCount + 1] = center2 / count;

                int   edge_offset   = doubleCount;
                short polygon_index = (short)count;

                // 'top'
                for (int i = 0, j = count - 1; i < count; j = i, i++)
                {
                    var jm = (j) % count;
                    var im = (i) % count;

                    var edgeOut0 = edge_offset + (jm * 2) + 1;
                    var edgeIn0  = edge_offset + (im * 2) + 0;
                    var edgeOut1 = edge_offset + (im * 2) + 1;

                    dstEdges[edgeIn0].VertexIndex = (short)(doubleCount);
                    dstEdges[edgeIn0].HardEdge    = true;
                    dstEdges[edgeIn0].TwinIndex   = edgeOut1;

                    dstEdges[edgeOut1].VertexIndex = (short)im;
                    dstEdges[edgeOut1].HardEdge    = true;
                    dstEdges[edgeOut1].TwinIndex   = edgeIn0;

                    dstEdges[im].PolygonIndex       = polygon_index;
                    dstEdges[edgeIn0].PolygonIndex  = polygon_index;
                    dstEdges[edgeOut0].PolygonIndex = polygon_index;

                    dstPolygons[polygon_index] = new Polygon(new int[] { im, edgeIn0, edgeOut0 }, polygon_index);
                    polygon_index++;
                }

                edge_offset = doubleCount * 2;
                // 'bottom'
                for (int i = 0, j = count - 1; j >= 0; i = j, j--)
                {
                    var jm = (count + count - j) % count;
                    var im = (count + count - i) % count;

                    var edgeOut0 = edge_offset + (jm * 2) + 1;
                    var edgeIn0  = edge_offset + (im * 2) + 0;
                    var edgeOut1 = edge_offset + (im * 2) + 1;

                    dstEdges[edgeIn0].VertexIndex = (short)(doubleCount + 1);
                    dstEdges[edgeIn0].HardEdge    = true;
                    dstEdges[edgeIn0].TwinIndex   = edgeOut1;

                    dstEdges[edgeOut1].VertexIndex = (short)(im + count);
                    dstEdges[edgeOut1].HardEdge    = true;
                    dstEdges[edgeOut1].TwinIndex   = edgeIn0;

                    dstEdges[im + count].PolygonIndex = polygon_index;
                    dstEdges[edgeIn0].PolygonIndex    = polygon_index;
                    dstEdges[edgeOut0].PolygonIndex   = polygon_index;

                    dstPolygons[polygon_index] = new Polygon(new int[] { im + count, edgeIn0, edgeOut0 }, polygon_index);
                    polygon_index++;
                }
            }
            else
            {
                var polygon0Edges = new int[count];
                var polygon1Edges = new int[count];
                for (var i = 0; i < count; i++)
                {
                    dstEdges [i].PolygonIndex         = (short)(count + 0);
                    dstEdges [i + count].PolygonIndex = (short)(count + 1);
                    polygon0Edges[i] = i;
                    polygon1Edges[count - (i + 1)] = i + count;
                }
                dstPolygons[count + 0] = new Polygon(polygon0Edges, count + 0);
                dstPolygons[count + 1] = new Polygon(polygon1Edges, count + 1);
            }


            for (int v0 = count - 1, v1 = 0; v1 < count; v0 = v1, v1++)
            {
                var polygonIndex = (short)(v1);

                var nextOffset = startEdgeOffset + (((v1 + 1) % count) * 4);
                var currOffset = startEdgeOffset + (((v1)) * 4);
                var prevOffset = startEdgeOffset + (((v1 + count - 1) % count) * 4);

                var nextTwin = nextOffset + 1;
                var prevTwin = prevOffset + 3;

                dstEdges[v1].TwinIndex         = currOffset + 0;
                dstEdges[v1 + count].TwinIndex = currOffset + 2;

                dstEdges[currOffset + 0].PolygonIndex = polygonIndex;
                dstEdges[currOffset + 1].PolygonIndex = polygonIndex;
                dstEdges[currOffset + 2].PolygonIndex = polygonIndex;
                dstEdges[currOffset + 3].PolygonIndex = polygonIndex;

                dstEdges[currOffset + 0].TwinIndex = (v1);
                dstEdges[currOffset + 1].TwinIndex = prevTwin;
                dstEdges[currOffset + 2].TwinIndex = (v1 + count);
                dstEdges[currOffset + 3].TwinIndex = nextTwin;

                dstEdges[currOffset + 0].VertexIndex = (short)(v0);
                dstEdges[currOffset + 1].VertexIndex = (short)(v1 + count);
                dstEdges[currOffset + 2].VertexIndex = (short)(((v1 + 1) % count) + count);
                dstEdges[currOffset + 3].VertexIndex = (short)(v1);

                dstEdges[currOffset + 0].HardEdge = true;
                dstEdges[currOffset + 1].HardEdge = true;
                dstEdges[currOffset + 2].HardEdge = true;
                dstEdges[currOffset + 3].HardEdge = true;

                dstPolygons[polygonIndex] = new Polygon(new [] { currOffset + 0,
                                                                 currOffset + 1,
                                                                 currOffset + 2,
                                                                 currOffset + 3 }, polygonIndex);
            }

            for (int i = 0; i < dstPoints.Length; i++)
            {
                dstPoints[i] = localToWorld.MultiplyPoint(dstPoints[i]);
            }

            controlMesh = new ControlMesh
            {
                Vertices = dstPoints,
                Edges    = dstEdges,
                Polygons = dstPolygons
            };
            controlMesh.SetDirty();

            shape = new Shape
            {
                Materials   = new Material[dstPolygons.Length],
                Surfaces    = new Surface[dstPolygons.Length],
                TexGenFlags = new TexGenFlags[dstPolygons.Length],
                TexGens     = new TexGen[dstPolygons.Length]
            };


            var smoothinggroup = (smooth.HasValue && smooth.Value) ? SurfaceUtility.FindUnusedSmoothingGroupIndex() : 0;


            var containedMaterialCount = 0;

            if (shape2DPolygon.EdgeMaterials != null &&
                shape2DPolygon.EdgeTexgens != null /* &&
                                                    * shape2DPolygon.edgeTexgenFlags != null*/)
            {
                containedMaterialCount = Mathf.Min(shape2DPolygon.EdgeMaterials.Length,
                                                   shape2DPolygon.EdgeTexgens.Length /*,
                                                                                      *                        shape2DPolygon.edgeTexgenFlags.Length*/);
            }

            if (!capMaterial)
            {
                capMaterial = CSGSettings.DefaultMaterial;
                capTexgen   = new TexGen(-1);
            }

            for (var i = 0; i < dstPolygons.Length; i++)
            {
                if (i < containedMaterialCount)
                {
                    //shape.TexGenFlags[i] = shape2DPolygon.edgeTexgenFlags[i];
                    shape.Materials  [i]             = shape2DPolygon.EdgeMaterials[i];
                    shape.TexGens    [i]             = shape2DPolygon.EdgeTexgens[i];
                    shape.Surfaces   [i].TexGenIndex = i;
                    shape.TexGens[i].MaterialIndex   = -1;
                }
                else
                {
                    shape.Materials[i] = capMaterial;
                    shape.TexGens[i]   = capTexgen;
                    //shape.TexGenFlags[i]			= TexGenFlags.None;
                    shape.Surfaces[i].TexGenIndex  = i;
                    shape.TexGens[i].MaterialIndex = -1;
                }
                if (smooth.HasValue)
                {
                    if (i < count)
                    {
                        shape.TexGens[i].SmoothingGroup = smoothinggroup;
                    }
                    else
                    {
                        shape.TexGens[i].SmoothingGroup = 0;
                    }
                }
            }

            for (var s = 0; s < dstPolygons.Length; s++)
            {
                var normal = shape.Surfaces[s].Plane.normal;
                shape.Surfaces[s].Plane = GeometryUtility.CalcPolygonPlane(controlMesh, (short)s);
                Vector3 tangent, binormal;
                GeometryUtility.CalculateTangents(normal, out tangent, out binormal);
                //var tangent		= Vector3.Cross(GeometryUtility.CalculateTangent(normal), normal).normalized;
                //var binormal	= Vector3.Cross(normal, tangent);
                shape.Surfaces[s].Tangent     = tangent;
                shape.Surfaces[s].BiNormal    = binormal;
                shape.Surfaces[s].TexGenIndex = s;
            }

            controlMesh.IsValid = ControlMeshUtility.Validate(controlMesh, shape);
            if (controlMesh.IsValid)
            {
                return(true);
            }

            controlMesh = null;
            shape       = null;
            return(false);
        }
Ejemplo n.º 22
0
        /*
         * static void OnGUIContentsMaterialInspector(Material material, bool mixedValues)
         * {
         *      //if (materialEditor == null || prevMaterial != material)
         *      {
         *              var editor = materialEditor as Editor;
         *              Editor.CreateCachedEditor(material, typeof(MaterialEditor), ref editor);
         *              materialEditor = editor as MaterialEditor;
         *      }
         *
         *      if (materialEditor != null)
         *      {
         *              EditorGUI.showMixedValue = mixedValues;
         *              try
         *              {
         *                      materialEditor.DrawHeader();
         *                      if (materialEditor.PropertiesGUI())
         *                      {
         *                              materialEditor.PropertiesChanged();
         *                      }
         *              }
         *              catch
         *              {}
         *              EditorGUI.showMixedValue = false;
         *      }
         * }
         */

        private static void OnGUIContents(bool isSceneGUI, EditModeSurface tool)
        {
            EditModeCommonGUI.StartToolGUI();

            var selectedBrushSurfaces = (tool == null) ? new SelectedBrushSurface[0] : tool.GetSelectedSurfaces();
            var enabled = selectedBrushSurfaces.Length > 0;

            EditorGUI.BeginDisabledGroup(!enabled);
            {
                Material material      = null;
                var      currentTexGen = new TexGen();

                var  haveTexgen            = false;
                var  multipleColors        = !enabled;
                var  multipleTranslationX  = !enabled;
                var  multipleTranslationY  = !enabled;
                var  multipleScaleX        = !enabled;
                var  multipleScaleY        = !enabled;
                var  multipleRotationAngle = !enabled;
                var  multipleMaterials     = !enabled;
                bool?textureLocked         = null;

                bool foundHelperMaterial = false;
                RenderSurfaceType?firstRenderSurfaceType = null;
                Material          firstMaterial          = null;
                if (selectedBrushSurfaces.Length > 0)
                {
                    for (var i = 0; i < selectedBrushSurfaces.Length; i++)
                    {
                        var brush = selectedBrushSurfaces[i].brush;
                        if (!brush)
                        {
                            continue;
                        }
                        var surfaceIndex = selectedBrushSurfaces[i].surfaceIndex;
                        if (surfaceIndex >= brush.Shape.Surfaces.Length)
                        {
                            Debug.LogWarning("surface_index >= brush.Shape.Surfaces.Length");
                            continue;
                        }
                        var texGenIndex = brush.Shape.Surfaces[surfaceIndex].TexGenIndex;
                        if (texGenIndex >= brush.Shape.TexGens.Length)
                        {
                            Debug.LogWarning("texGen_index >= brush.Shape.TexGens.Length");
                            continue;
                        }
                        var      brushCache = InternalCSGModelManager.GetBrushCache(brush);
                        var      model      = (brushCache != null) ? brushCache.childData.Model : null;
                        Material foundMaterial;
                        var      texGenFlags = brush.Shape.TexGenFlags[texGenIndex];
                        if (model && (!model.IsRenderable || model.ShadowsOnly))
                        {
                            foundHelperMaterial = true;
                            if (!firstRenderSurfaceType.HasValue)
                            {
                                firstRenderSurfaceType = ModelTraits.GetModelSurfaceType(model);
                            }
                            foundMaterial = null;
                        }
                        else
                        if ((texGenFlags & TexGenFlags.NoRender) == TexGenFlags.NoRender)
                        {
                            foundHelperMaterial = true;
                            if (!firstRenderSurfaceType.HasValue)
                            {
                                if ((texGenFlags & TexGenFlags.NoCastShadows) != TexGenFlags.NoCastShadows)
                                {
                                    firstRenderSurfaceType = RenderSurfaceType.ShadowOnly;
                                }
                                else
                                if ((texGenFlags & TexGenFlags.NoCollision) != TexGenFlags.NoCollision)
                                {
                                    firstRenderSurfaceType = RenderSurfaceType.Collider;
                                }
                                else
                                {
                                    firstRenderSurfaceType = RenderSurfaceType.Hidden;
                                }
                            }
                            foundMaterial = null;
                        }
                        else
                        {
                            var surfaceMaterial = brush.Shape.TexGens[texGenIndex].RenderMaterial;
                            if (!foundHelperMaterial)
                            {
                                var surfaceType = MaterialUtility.GetMaterialSurfaceType(surfaceMaterial);
                                if (!firstRenderSurfaceType.HasValue)
                                {
                                    firstRenderSurfaceType = surfaceType;
                                }
                                foundHelperMaterial = surfaceType != RenderSurfaceType.Normal;
                            }
                            foundMaterial = surfaceMaterial;
                        }
                        if ((texGenFlags & TexGenFlags.WorldSpaceTexture) == TexGenFlags.WorldSpaceTexture)
                        {
                            if (i == 0)
                            {
                                textureLocked = false;
                            }
                            else if (textureLocked.HasValue && textureLocked.Value)
                            {
                                textureLocked = null;
                            }
                        }
                        else
                        {
                            if (i == 0)
                            {
                                textureLocked = true;
                            }
                            else if (textureLocked.HasValue && !textureLocked.Value)
                            {
                                textureLocked = null;
                            }
                        }
                        if (foundMaterial != material)
                        {
                            if (!material)
                            {
                                firstMaterial = foundMaterial;
                                material      = foundMaterial;
                            }
                            else
                            {
                                multipleMaterials = true;
                            }
                        }
                        if (!haveTexgen)
                        {
                            currentTexGen = brush.Shape.TexGens[texGenIndex];
                            haveTexgen    = true;
                        }
                        else
                        {
                            if (!multipleColors)
                            {
                                var color = brush.Shape.TexGens[texGenIndex].Color;
                                multipleColors = currentTexGen.Color.a != color.a ||
                                                 currentTexGen.Color.b != color.b ||
                                                 currentTexGen.Color.g != color.g ||
                                                 currentTexGen.Color.r != color.r;
                            }
                            if (!multipleScaleX || !multipleScaleY)
                            {
                                var scale = brush.Shape.TexGens[texGenIndex].Scale;
                                multipleScaleX = multipleScaleX || currentTexGen.Scale.x != scale.x;
                                multipleScaleY = multipleScaleY || currentTexGen.Scale.y != scale.y;
                            }

                            if (!multipleTranslationX || !multipleTranslationY)
                            {
                                var translation = brush.Shape.TexGens[texGenIndex].Translation;
                                multipleTranslationX = multipleTranslationX || currentTexGen.Translation.x != translation.x;
                                multipleTranslationY = multipleTranslationY || currentTexGen.Translation.y != translation.y;
                            }

                            if (!multipleRotationAngle)
                            {
                                var rotationAngle = brush.Shape.TexGens[texGenIndex].RotationAngle;
                                multipleRotationAngle = currentTexGen.RotationAngle != rotationAngle;
                            }
                        }
                    }
                    if (foundHelperMaterial && !firstMaterial)
                    {
                        if (firstRenderSurfaceType.HasValue)
                        {
                            firstMaterial = MaterialUtility.GetSurfaceMaterial(firstRenderSurfaceType.Value);
                        }
                        else
                        {
                            firstMaterial = MaterialUtility.HiddenMaterial;
                        }
                    }
                }

                GUILayout.BeginVertical(isSceneGUI ? materialDoubleWidth : CSG_GUIStyleUtility.ContentEmpty);
                {
                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        /*
                         * Color new_color;
                         * EditorGUI.BeginChangeCheck();
                         * {
                         *      EditorGUI.showMixedValue = multipleColors;
                         *      // why doesn't the colorfield return a modified color?
                         *      try
                         *      {
                         *              new_color = EditorGUILayout.ColorField(GUIContent.none, currentTexGen.Color);
                         *      }
                         *      catch
                         *      {
                         *              new_color = currentTexGen.Color;
                         *      }
                         * }
                         * if (EditorGUI.EndChangeCheck() || currentTexGen.Color != new_color)
                         * {
                         *      SurfaceUtility.SetColors(selectedBrushSurfaces, new_color);
                         * }
                         */
                        if (isSceneGUI)
                        {
                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                EditorGUI.BeginDisabledGroup(material == null);
                                {
                                    GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                                    {
                                        GUILayout.Space(1);

                                        /*
                                         * Color new_color;
                                         * EditorGUI.BeginChangeCheck();
                                         * {
                                         *      EditorGUI.showMixedValue = multipleColors;
                                         *      // why doesn't the colorfield return a modified color?
                                         *      try
                                         *      {
                                         *              new_color = EditorGUILayout.ColorField(GUIContent.none, currentTexGen.Color);
                                         *      }
                                         *      catch
                                         *      {
                                         *              new_color = currentTexGen.Color;
                                         *      }
                                         * }
                                         * if (EditorGUI.EndChangeCheck() || currentTexGen.Color != new_color)
                                         * {
                                         *      SurfaceUtility.SetColors(selectedBrushSurfaces, new_color);
                                         * }
                                         *
                                         * GUILayout.Space(1);
                                         */
                                        Material newMaterial;
                                        EditorGUI.BeginChangeCheck();
                                        {
                                            EditorGUI.showMixedValue = multipleMaterials;
                                            newMaterial = EditorGUILayout.ObjectField(material, typeof(Material), true) as Material;
                                            EditorGUI.showMixedValue = false;
                                        }
                                        if (EditorGUI.EndChangeCheck())
                                        {
                                            if (newMaterial)
                                            {
                                                SurfaceUtility.SetMaterials(selectedBrushSurfaces, newMaterial);
                                                CSGSettings.DefaultMaterial = newMaterial;
                                                CSGSettings.Save();
                                            }
                                        }
                                    }
                                    GUILayout.EndVertical();
                                    GUILayout.Space(1);
                                }
                                EditorGUI.EndDisabledGroup();
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.Space(4);
                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                GUILayout.Space(2);
                                OnGUIContentsMaterialImage(isSceneGUI, firstMaterial, multipleMaterials, selectedBrushSurfaces);
                                GUILayout.BeginHorizontal(materialWidth);
                                {
                                    GUILayout.FlexibleSpace();
                                    GUILayout.BeginVertical(materialHeight);
                                    {
                                        OnGUIContentsJustify(isSceneGUI, selectedBrushSurfaces);
                                        GUILayout.FlexibleSpace();
                                    }
                                    GUILayout.EndVertical();
                                }
                                GUILayout.EndHorizontal();
                                GUILayout.FlexibleSpace();
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                    GUILayout.EndVertical();

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                    }

                    if (currentTexGen.Scale.x == 0.0f)
                    {
                        currentTexGen.Scale.x = 1.0f;
                    }
                    if (currentTexGen.Scale.y == 0.0f)
                    {
                        currentTexGen.Scale.y = 1.0f;
                    }

                    const float scale_round = 10000.0f;
                    currentTexGen.Scale.x       = Mathf.RoundToInt(currentTexGen.Scale.x * scale_round) / scale_round;
                    currentTexGen.Scale.y       = Mathf.RoundToInt(currentTexGen.Scale.y * scale_round) / scale_round;
                    currentTexGen.Translation.x = Mathf.RoundToInt(currentTexGen.Translation.x * scale_round) / scale_round;
                    currentTexGen.Translation.y = Mathf.RoundToInt(currentTexGen.Translation.y * scale_round) / scale_round;
                    currentTexGen.RotationAngle = Mathf.RoundToInt(currentTexGen.RotationAngle * scale_round) / scale_round;

                    var leftStyle   = isSceneGUI ? EditorStyles.miniButtonLeft  : GUI.skin.button;
                    var middleStyle = isSceneGUI ? EditorStyles.miniButtonMid   : GUI.skin.button;
                    var rightStyle  = isSceneGUI ? EditorStyles.miniButtonRight : GUI.skin.button;

                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = !textureLocked.HasValue;
                            textureLocked            = EditorGUILayout.ToggleLeft(ContentLockTexture, textureLocked.HasValue ? textureLocked.Value : false);
                            TooltipUtility.SetToolTip(ToolTipLockTexture);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            SurfaceUtility.SetTextureLock(selectedBrushSurfaces, textureLocked.Value);
                        }
                    }
                    GUILayout.EndVertical();

                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (isSceneGUI)
                            {
                                EditorGUILayout.LabelField(ContentUVScale, EditorStyles.miniLabel, labelWidth);
                            }
                            else
                            {
                                EditorGUILayout.LabelField(ContentUVScale, largeLabelWidth);
                            }
                            TooltipUtility.SetToolTip(ToolTipScaleUV);

                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                if (!isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentUSymbol, unitWidth);
                                }
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue = multipleScaleX;
                                    currentTexGen.Scale.x    = EditorGUILayout.FloatField(currentTexGen.Scale.x, minFloatFieldWidth);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetScaleX(selectedBrushSurfaces, currentTexGen.Scale.x);
                                }
                                if (!isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentVSymbol, unitWidth);
                                }
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue = multipleScaleY;
                                    currentTexGen.Scale.y    = EditorGUILayout.FloatField(currentTexGen.Scale.y, minFloatFieldWidth);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetScaleY(selectedBrushSurfaces, currentTexGen.Scale.y);
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (isSceneGUI)
                            {
                                EditorGUILayout.LabelField(ContentOffset, EditorStyles.miniLabel, labelWidth);
                            }
                            else
                            {
                                EditorGUILayout.LabelField(ContentOffset, largeLabelWidth);
                            }
                            TooltipUtility.SetToolTip(ToolTipOffsetUV);

                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                if (!isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentUSymbol, unitWidth);
                                }
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue    = multipleTranslationX;
                                    currentTexGen.Translation.x = EditorGUILayout.FloatField(currentTexGen.Translation.x, minFloatFieldWidth);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetTranslationX(selectedBrushSurfaces, currentTexGen.Translation.x);
                                }

                                if (!isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentVSymbol, unitWidth);
                                }
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue    = multipleTranslationY;
                                    currentTexGen.Translation.y = EditorGUILayout.FloatField(currentTexGen.Translation.y, minFloatFieldWidth);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetTranslationY(selectedBrushSurfaces, currentTexGen.Translation.y);
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (isSceneGUI)
                            {
                                EditorGUILayout.LabelField(ContentRotate, EditorStyles.miniLabel, labelWidth);
                            }
                            else
                            {
                                EditorGUILayout.LabelField(ContentRotate, largeLabelWidth);
                            }
                            TooltipUtility.SetToolTip(ToolTipRotation);

                            if (!isSceneGUI)
                            {
                                GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                            }

                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue    = multipleRotationAngle;
                                    currentTexGen.RotationAngle = EditorGUILayout.FloatField(currentTexGen.RotationAngle, minFloatFieldWidth);
                                    if (!isSceneGUI)
                                    {
                                        EditorGUILayout.LabelField(ContentAngleSymbol, unitWidth);
                                    }
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    SurfaceUtility.SetRotationAngle(selectedBrushSurfaces, currentTexGen.RotationAngle);
                                }
                            }
                            GUILayout.EndHorizontal();

                            var buttonWidth = isSceneGUI ? new GUILayoutOption[] { angleButtonWidth } : new GUILayoutOption[0];
                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                if (GUILayout.Button(ContentRotate90Negative, leftStyle, buttonWidth))
                                {
                                    SurfaceUtility.AddRotationAngle(selectedBrushSurfaces, -90.0f);
                                }
                                TooltipUtility.SetToolTip(ToolTipRotate90Negative);
                                if (GUILayout.Button(ContentRotate90Positive, rightStyle, buttonWidth))
                                {
                                    SurfaceUtility.AddRotationAngle(selectedBrushSurfaces, +90.0f);
                                }
                                TooltipUtility.SetToolTip(ToolTipRotate90Positive);
                            }
                            GUILayout.EndHorizontal();
                            if (!isSceneGUI)
                            {
                                GUILayout.EndVertical();
                            }
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                    }

                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (!isSceneGUI)
                            {
                                GUILayout.Label(ContentFit, largeLabelWidth);
                            }
                            else
                            {
                                GUILayout.Label(ContentFit, EditorStyles.miniLabel, smallLabelWidth);
                            }
                            if (GUILayout.Button(ContentFitX, leftStyle))
                            {
                                SurfaceUtility.FitSurfaceX(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFitX);
                            if (GUILayout.Button(ContentFitXY, middleStyle))
                            {
                                SurfaceUtility.FitSurface(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFitXY);
                            if (GUILayout.Button(ContentFitY, rightStyle))
                            {
                                SurfaceUtility.FitSurfaceY(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFitY);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (!isSceneGUI)
                            {
                                GUILayout.Label(ContentReset, largeLabelWidth);
                            }
                            else
                            {
                                GUILayout.Label(ContentReset, EditorStyles.miniLabel, smallLabelWidth);
                            }
                            if (GUILayout.Button(ContentResetX, leftStyle))
                            {
                                SurfaceUtility.ResetSurfaceX(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipResetX);
                            if (GUILayout.Button(ContentResetXY, middleStyle))
                            {
                                SurfaceUtility.ResetSurface(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipResetXY);
                            if (GUILayout.Button(ContentResetY, rightStyle))
                            {
                                SurfaceUtility.ResetSurfaceY(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipResetY);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (!isSceneGUI)
                            {
                                GUILayout.Label(ContentFlip, largeLabelWidth);
                            }
                            else
                            {
                                GUILayout.Label(ContentFlip, EditorStyles.miniLabel, smallLabelWidth);
                            }
                            if (GUILayout.Button(ContentFlipX, leftStyle))
                            {
                                SurfaceUtility.FlipX(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFlipX);
                            if (GUILayout.Button(ContentFlipXY, middleStyle))
                            {
                                SurfaceUtility.FlipXY(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFlipXY);
                            if (GUILayout.Button(ContentFlipY, rightStyle))
                            {
                                SurfaceUtility.FlipY(selectedBrushSurfaces);
                            }
                            TooltipUtility.SetToolTip(ToolTipFlipY);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            if (!isSceneGUI)
                            {
                                GUILayout.Label(ContentScale, largeLabelWidth);
                            }
                            else
                            {
                                GUILayout.Label(ContentScale, EditorStyles.miniLabel, smallLabelWidth);
                            }
                            if (GUILayout.Button(ContentDoubleScale, leftStyle))
                            {
                                SurfaceUtility.MultiplyScale(selectedBrushSurfaces, 2.0f);
                            }
                            TooltipUtility.SetToolTip(ToolTipDoubleScale);
                            if (GUILayout.Button(ContentHalfScale, rightStyle))
                            {
                                SurfaceUtility.MultiplyScale(selectedBrushSurfaces, 0.5f);
                            }
                            TooltipUtility.SetToolTip(ToolTipHalfScale);
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                    }

                    if (!isSceneGUI)
                    {
                        OnGUIContentsJustify(isSceneGUI, selectedBrushSurfaces);
                    }

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                    }

                    GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                    {
                        EditModeCommonGUI.OnSurfaceFlagButtons(selectedBrushSurfaces, isSceneGUI);
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginDisabledGroup(!SurfaceUtility.CanSmooth(selectedBrushSurfaces));
                            {
                                if (GUILayout.Button(ContentSmoothSurfaces, leftStyle))
                                {
                                    SurfaceUtility.Smooth(selectedBrushSurfaces);
                                }
                                TooltipUtility.SetToolTip(ToolTipSmoothSurfaces);
                            }
                            EditorGUI.EndDisabledGroup();
                            EditorGUI.BeginDisabledGroup(!SurfaceUtility.CanUnSmooth(selectedBrushSurfaces));
                            {
                                if (GUILayout.Button(ContentUnSmoothSurfaces, rightStyle))
                                {
                                    SurfaceUtility.UnSmooth(selectedBrushSurfaces);
                                }
                                TooltipUtility.SetToolTip(ToolTipUnSmoothSurfaces);
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();

                    if (!isSceneGUI)
                    {
                        EditorGUILayout.Space();
                        Material new_material;
                        GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUILayout.LabelField(ContentMaterial, largeLabelWidth);
                            GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                EditorGUI.BeginChangeCheck();
                                {
                                    EditorGUI.showMixedValue = multipleMaterials;
                                    new_material             = EditorGUILayout.ObjectField(material, typeof(Material), true) as Material;
                                    EditorGUI.showMixedValue = false;
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (!new_material)
                                    {
                                        new_material = MaterialUtility.MissingMaterial;
                                    }
                                    SurfaceUtility.SetMaterials(selectedBrushSurfaces, new_material);
                                }
                            }
                            GUILayout.Space(2);
                            GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty);
                            {
                                GUILayout.Space(5);
                                OnGUIContentsMaterialImage(isSceneGUI, firstMaterial, multipleMaterials, selectedBrushSurfaces);
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.EndVertical();
                        }
                        GUILayout.EndHorizontal();
                        // Unity won't let us do this
                        //GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                        //OnGUIContentsMaterialInspector(first_material, multiple_materials);
                        //GUILayout.EndVertical();
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.showMixedValue = false;
        }
Ejemplo n.º 23
0
        public static bool CheckMaterials(Shape shape)
        {
            bool dirty = false;

            if (shape.Surfaces == null ||
                shape.Surfaces.Length == 0)
            {
                Debug.Log("Surfaces == null || Surfaces.Length == 0");
                return(true);
            }

            if (shape.CutNodes == null || shape.CutNodes.Length < 1)
            {
                shape.CutNodes = new CutNode[shape.Surfaces.Length - 1];
                dirty          = true;
            }

            int maxTexGenIndex = 0;

            for (int i = 0; i < shape.Surfaces.Length; i++)
            {
                maxTexGenIndex = Mathf.Max(maxTexGenIndex, shape.Surfaces[i].TexGenIndex);
            }
            maxTexGenIndex++;

            if (shape.TexGens == null ||
                shape.TexGens.Length < maxTexGenIndex)
            {
                dirty = true;
                var newTexGens     = new TexGen[maxTexGenIndex];
                var newTexGenFlags = new TexGenFlags[maxTexGenIndex];
                if (shape.TexGens != null &&
                    shape.TexGens.Length > 0)
                {
                    for (int i = 0; i < shape.TexGens.Length; i++)
                    {
                        newTexGens[i]     = shape.TexGens[i];
                        newTexGenFlags[i] = shape.TexGenFlags[i];
                    }
                    for (int i = shape.TexGens.Length; i < newTexGens.Length; i++)
                    {
                        newTexGens[i].Color = Color.white;
                    }
                }
                shape.TexGens     = newTexGens;
                shape.TexGenFlags = newTexGenFlags;
            }

            for (int i = 0; i < shape.TexGens.Length; i++)
            {
                if (shape.TexGens[i].Color == Color.clear)
                {
                    shape.TexGens[i].Color = Color.white;
                }
            }

            if (shape.Materials == null ||
                shape.Materials.Length == 0)
            {
                dirty           = true;
                shape.Materials = new Material[shape.TexGens.Length];
            }

            if (shape.TexGens.Length != shape.Materials.Length)
            {
                dirty = true;
                var new_materials = new Material[shape.TexGens.Length];
                Array.Copy(shape.Materials, new_materials, Math.Min(shape.Materials.Length, shape.TexGens.Length));
                shape.Materials = new_materials;
            }
            return(dirty);
        }
        public static TexGen GetTexGenerator(Texture2D tileTex, Dictionary <Color, int> colorToTile, Texture2D wallTex = null, Dictionary <Color, int> colorToWall = null, Texture2D liquidTex = null, Texture2D slopeTex = null)
        {
            if (colorToLiquid == null)
            {
                colorToLiquid = new Dictionary <Color, int>();
                colorToLiquid[new Color(0, 0, 255)]   = 0;
                colorToLiquid[new Color(255, 0, 0)]   = 1;
                colorToLiquid[new Color(255, 255, 0)] = 2;

                colorToSlope = new Dictionary <Color, int>();
                colorToSlope[new Color(255, 0, 0)]     = 1;
                colorToSlope[new Color(0, 255, 0)]     = 2;
                colorToSlope[new Color(0, 0, 255)]     = 3;
                colorToSlope[new Color(255, 255, 0)]   = 4;
                colorToSlope[new Color(255, 255, 255)] = -1;
                colorToSlope[new Color(0, 0, 0)]       = -2;
            }

            Color[] array = new Color[tileTex.Width * tileTex.Height];
            tileTex.GetData(0, tileTex.Bounds, array, 0, tileTex.Width * tileTex.Height);

            Color[] array2 = (wallTex != null) ? new Color[wallTex.Width * wallTex.Height] : null;

            if (array2 != null)
            {
                wallTex.GetData(0, wallTex.Bounds, array2, 0, wallTex.Width * wallTex.Height);
            }

            Color[] array3 = (liquidTex != null) ? new Color[liquidTex.Width * liquidTex.Height] : null;

            if (array3 != null)
            {
                liquidTex.GetData(0, liquidTex.Bounds, array3, 0, liquidTex.Width * liquidTex.Height);
            }

            Color[] array4 = (slopeTex != null) ? new Color[slopeTex.Width * slopeTex.Height] : null;

            if (array4 != null)
            {
                slopeTex.GetData(0, slopeTex.Bounds, array4, 0, slopeTex.Width * slopeTex.Height);
            }

            int    num    = 0;
            int    num2   = 0;
            TexGen texGen = new TexGen(tileTex.Width, tileTex.Height);

            for (int i = 0; i < array.Length; i++)
            {
                Color key  = array[i];
                Color key2 = (wallTex == null) ? Color.Black : array2[i];
                Color key3 = (liquidTex == null) ? Color.Black : array3[i];
                Color key4 = (slopeTex == null) ? Color.Black : array4[i];
                int   id   = colorToTile.ContainsKey(key) ? colorToTile[key] : (-1);
                int   wid  = (colorToWall != null && colorToWall.ContainsKey(key2)) ? colorToWall[key2] : (-1);
                int   num3 = (colorToLiquid != null && colorToLiquid.ContainsKey(key3)) ? colorToLiquid[key3] : (-1);
                int   sl   = (colorToSlope != null && colorToSlope.ContainsKey(key4)) ? colorToSlope[key4] : (-1);
                texGen.tileGen[num, num2] = new TileInfo(id, 0, sl, wid, num3, (num3 != -1) ? 255 : 0);
                num++;

                if (num >= tileTex.Width)
                {
                    num = 0;
                    num2++;
                }

                if (num2 >= tileTex.Height)
                {
                    break;
                }
            }

            return(texGen);
        }
Ejemplo n.º 25
0
		private bool GenerateSphere(float radius, int splits, CSGModel parentModel, CSGBrush brush, out ControlMesh controlMesh, out Shape shape)
        {
			if (prevSplits != splits || prevIsHemisphere != IsHemiSphere || splitControlMesh == null || splitShape == null)
			{
				splitControlMesh = null;
				splitShape = null;
				BrushFactory.CreateCubeControlMesh(out splitControlMesh, out splitShape, Vector3.one);

				var axi = new Vector3[] { MathConstants.upVector3, MathConstants.leftVector3, MathConstants.forwardVector3 };
				List<int> intersectedEdges = new List<int>();
				float step = 1.0f / (float)(splits + 1);
				float offset;
				for (int i = 0; i < axi.Length; i++)
				{
					var normal = axi[i];
					offset = 0.5f - step;
					while (offset > 0.0f)
					{
						ControlMeshUtility.CutMesh(splitControlMesh, splitShape, new CSGPlane(-normal, -offset), ref intersectedEdges);
						if (i != 0 || !IsHemiSphere)
						{
							ControlMeshUtility.CutMesh(splitControlMesh, splitShape, new CSGPlane(normal, -offset), ref intersectedEdges);
						}
						offset -= step;
					}
					if (i != 0 || !IsHemiSphere)
					{
						if ((splits & 1) == 1)
							ControlMeshUtility.CutMesh(splitControlMesh, splitShape, new CSGPlane(normal, 0), ref intersectedEdges);
					}
				}

				if (IsHemiSphere)
				{
					var cuttingPlane = new CSGPlane(MathConstants.upVector3, 0);
					intersectedEdges.Clear();
					if (ControlMeshUtility.CutMesh(splitControlMesh, splitShape, cuttingPlane, ref intersectedEdges))
					{
						var edge_loop = ControlMeshUtility.FindEdgeLoop(splitControlMesh, ref intersectedEdges);
						if (edge_loop != null)
						{
							if (ControlMeshUtility.SplitEdgeLoop(splitControlMesh, splitShape, edge_loop))
							{
								Shape foundShape;
								ControlMesh foundControlMesh;
								ControlMeshUtility.FindAndDetachSeparatePiece(splitControlMesh, splitShape, cuttingPlane, out foundControlMesh, out foundShape);
							}
						}
					}
				}


				// Spherize the cube
				for (int i = 0; i < splitControlMesh.Vertices.Length; i++)
				{
					Vector3 v = splitControlMesh.Vertices[i] * 2.0f;
					float x2 = v.x * v.x;
					float y2 = v.y * v.y;
					float z2 = v.z * v.z;
					Vector3 s;
					s.x = v.x * Mathf.Sqrt(1f - (y2 * 0.5f) - (z2 * 0.5f) + ((y2 * z2) / 3.0f));
					s.y = v.y * Mathf.Sqrt(1f - (z2 * 0.5f) - (x2 * 0.5f) + ((z2 * x2) / 3.0f));
					s.z = v.z * Mathf.Sqrt(1f - (x2 * 0.5f) - (y2 * 0.5f) + ((x2 * y2) / 3.0f));
					splitControlMesh.Vertices[i] = s;//(splitControlMesh.Vertices[i] * 0.75f) + (splitControlMesh.Vertices[i].normalized * 0.25f);
				}


				if (!ControlMeshUtility.Triangulate(null, splitControlMesh, splitShape))
				{
					Debug.LogWarning("!ControlMeshUtility.IsConvex");
					controlMesh = null;
					shape = null;
					return false;
				}
				ControlMeshUtility.FixTexGens(splitControlMesh, splitShape);

				if (!ControlMeshUtility.IsConvex(splitControlMesh, splitShape))
				{
					Debug.LogWarning("!ControlMeshUtility.IsConvex");
					controlMesh = null;
					shape = null;
					return false;
				}
				ControlMeshUtility.UpdateTangents(splitControlMesh, splitShape);

				prevSplits = splits;
				prevIsHemisphere = IsHemiSphere;
			}

			if (splitControlMesh == null || splitShape == null || !splitControlMesh.Valid)
			{
				Debug.LogWarning("splitControlMesh == null || splitShape == null || !splitControlMesh.IsValid");
				controlMesh = null;
				shape = null;
				return false;
			}

			controlMesh = splitControlMesh.Clone();
			shape = splitShape.Clone();

			/*
			float angle_offset = GeometryUtility.SignedAngle(gridTangent, delta / sphereRadius, buildPlane.normal);
			angle_offset -= 90;

			angle_offset += sphereOffset;
			angle_offset *= Mathf.Deg2Rad;

			Vector3 p1 = MathConstants.zeroVector3;
			for (int i = 0; i < realSplits; i++)
			{
				var angle = ((i * Mathf.PI * 2.0f) / (float)realSplits) + angle_offset;

				p1.x = (Mathf.Sin(angle) * sphereRadius);
				p1.z = (Mathf.Cos(angle) * sphereRadius);
			}
			*/

			for (int i = 0; i < controlMesh.Vertices.Length; i++)
			{
				var vertex = controlMesh.Vertices[i];
				vertex *= radius;
				controlMesh.Vertices[i] = vertex;
			}

			for (int i = 0; i < shape.Surfaces.Length; i++)
			{
				var plane = shape.Surfaces[i].Plane;
				plane.d *= radius;
				shape.Surfaces[i].Plane = plane;
			}

			bool smoothShading = SphereSmoothShading;
			if (!sphereSmoothingGroup.HasValue && smoothShading)
			{
				sphereSmoothingGroup = SurfaceUtility.FindUnusedSmoothingGroupIndex();
			}

			for (int i = 0; i < shape.TexGenFlags.Length; i++)
			{
				shape.TexGens[i].SmoothingGroup = smoothShading ? sphereSmoothingGroup.Value : 0;
			}

			var defaultTexGen = new TexGen();
			defaultTexGen.Scale = MathConstants.oneVector3;
			//defaultTexGen.Color = Color.white;
			
			var fakeSurface = new Surface();
			fakeSurface.TexGenIndex = 0;
			
			var defaultMaterial = CSGSettings.DefaultMaterial;
			for (var s = 0; s < shape.Surfaces.Length; s++)
			{
				var texGenIndex = shape.Surfaces[s].TexGenIndex;

				var axis		= GeometryUtility.SnapToClosestAxis(shape.Surfaces[s].Plane.normal);
				var rotation	= Quaternion.FromToRotation(axis, MathConstants.backVector3);
				var matrix		= Matrix4x4.TRS(MathConstants.zeroVector3, rotation, MathConstants.oneVector3);

				SurfaceUtility.AlignTextureSpaces(matrix, false, ref shape.TexGens[texGenIndex], ref shape.TexGenFlags[texGenIndex], ref shape.Surfaces[s]);
				shape.TexGens[texGenIndex].RenderMaterial = defaultMaterial;
			}

			return true;
        }
Ejemplo n.º 26
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Mod  mod = AAMod.instance;
            bool DEV = true;
            //--- Initial variable creation
            ushort tileGrass = (ushort)mod.TileType("MireGrass"), tileDirt = TileID.Mud, tileStone = (ushort)mod.TileType("Depthstone"),
                   tileIce = (ushort)mod.TileType("Depthice"), tileSand = (ushort)mod.TileType("Depthsand"), tileSandHardened = (ushort)mod.TileType("DepthsandHardened"), tileSandstone = (ushort)mod.TileType("Depthsandstone");

            int worldSize = GetWorldSize();
            int biomeRadius = (worldSize == 3 ? 180 : worldSize == 2 ? 150 : 120), biomeRadiusHalf = biomeRadius / 2;             //how deep the biome is (scaled by world size)

            Dictionary <Color, int> colorToTile = new Dictionary <Color, int>();

            colorToTile[new Color(0, 0, 255)]     = mod.TileType("Depthstone");
            colorToTile[new Color(255, 128, 0)]   = TileID.Mud;
            colorToTile[new Color(0, 255, 0)]     = mod.TileType("MireGrass");
            colorToTile[new Color(150, 150, 150)] = -2; //turn into air
            colorToTile[Color.Black] = -1;              //don't touch when genning

            Dictionary <Color, int> colorToWall = new Dictionary <Color, int>();

            colorToWall[new Color(0, 0, 255)] = mod.WallType("DepthstoneWall");
            colorToWall[Color.Black]          = -1; //don't touch when genning

            TexGen gen       = BaseWorldGenTex.GetTexGenerator(mod.GetTexture("Worldgeneration/Lake"), colorToTile, mod.GetTexture("Worldgeneration/LakeWalls"), colorToWall, mod.GetTexture("Worldgeneration/LakeWater"));
            Point  newOrigin = new Point(origin.X, origin.Y - 10);                                                                  //biomeRadius);

            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[]                                 //gen grass...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.Grass, TileID.JungleGrass, TileID.CorruptGrass, TileID.FleshGrass }), //ensure we only replace the intended tile (in this case, grass)
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),                                                           //this provides the 'blending' on the edges (except the top)
                new BaseMod.SetModTile(tileGrass, true, true)                                                                       //actually place the tile
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[]                                 //dirt...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.Dirt }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileDirt, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[]             //stone...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.Stone }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileStone, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //ice...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.IceBlock, TileID.CorruptIce, TileID.FleshIce }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileIce, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //sand...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.Sand, TileID.Ebonsand, TileID.Crimsand }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileSand, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[] //hardened sand...
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.HardenedSand, TileID.CorruptHardenedSand, TileID.CrimsonHardenedSand }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileSandHardened, true, true)
            }));
            WorldUtils.Gen(newOrigin, new Shapes.Circle(biomeRadius), Actions.Chain(new GenAction[]             //...and sandstone.
            {
                new Modifiers.OnlyTiles(new ushort[] { TileID.Sandstone, TileID.CorruptSandstone, TileID.CrimsonSandstone }),
                new Modifiers.RadialDither(biomeRadius - 5, biomeRadius),
                new BaseMod.SetModTile(tileSandstone, true, true)
            }));
            gen.Generate(origin.X - (gen.width / 2), origin.Y - 20, true, true);

            return(true);
        }