예제 #1
0
    public Texture2D CreateImage(ArtImage artImage)
    {
        for (int i = 0; i < indexWidth * indexWidth; i++)
        {
            colors[i] = new Color32(0, 1, 0, 0);
        }
        MatPairStruct id = artImage.id;

        if (generatedImages.ContainsKey(id))
        {
            return(generatedImages[id]);
        }

        Texture2D texture = null;

        Rect[][] imagePattern = GetFullPattern(artImage);
        for (int i = 0; i < imagePattern.Length; i++)
        {
            foreach (var item in imagePattern[i])
            {
                CopyElement(item, GetElementTile(artImage.elements[i]));
            }
        }

        texture = new Texture2D(16, 16, TextureFormat.RGBAHalf, false, true);
        texture.SetPixels(colors);
        texture.Apply();
        texture.name        = id.ToString();
        texture.filterMode  = FilterMode.Point;
        generatedImages[id] = texture;
        return(texture);
    }
예제 #2
0
    private Rect[][] GetFullPattern(ArtImage artImage)
    {
        //Todo: More advanced combinations, depending on verbs.
        if (artImage.elements.Count == 2)
        {
            //There's two elements, so we can easily do surrounds.
            int surroundIndex = artImage.properties.FindIndex(x => x.type == ArtImagePropertyType.TRANSITIVE_VERB && x.verb == ArtImageVerb.VERB_SURROUNDEDBY);
            if (surroundIndex >= 0)
            {
                var property   = artImage.properties[surroundIndex];
                var surrounded = new Rect[2][];
                surrounded[property.subject] = new Rect[] { new Rect(0.25f, 0.25f, 0.5f, 0.5f) };
                surrounded[property.@object] = new Rect[] {
                    new Rect(0.0f, 0.0f, 0.25f, 0.25f), new Rect(0.25f, 0.0f, 0.25f, 0.25f), new Rect(0.5f, 0.0f, 0.25f, 0.25f), new Rect(0.75f, 0.0f, 0.25f, 0.25f),
                    new Rect(0.0f, 0.25f, 0.25f, 0.25f), new Rect(0.75f, 0.25f, 0.25f, 0.25f),
                    new Rect(0.0f, 0.5f, 0.25f, 0.25f), new Rect(0.75f, 0.5f, 0.25f, 0.25f),
                    new Rect(0.0f, 0.75f, 0.25f, 0.25f), new Rect(0.25f, 0.75f, 0.25f, 0.25f), new Rect(0.5f, 0.75f, 0.25f, 0.25f), new Rect(0.75f, 0.75f, 0.25f, 0.25f),
                };
                return(surrounded);
            }
        }


        var mainPattern = GetPattern(artImage.elements.Count);
        var outPut      = new Rect[mainPattern.Length][];

        //We use the mainpattern length because it may have less than the full amount of elements, if the pattern is very large.
        for (int i = 0; i < mainPattern.Length; i++)
        {
            if (i < 0 || i >= artImage.elements.Count)
            {
                continue;
            }
            var element = artImage.elements[i];
            outPut[i] = GetPattern(element.count);
            for (int j = 0; j < outPut[i].Length; j++)
            {
                var min = outPut[i][j].min;
                var max = outPut[i][j].max;
                min.x                 *= mainPattern[i].size.x;
                min.y                 *= mainPattern[i].size.y;
                max.x                 *= mainPattern[i].size.x;
                max.y                 *= mainPattern[i].size.y;
                outPut[i][j].min       = min;
                outPut[i][j].max       = max;
                outPut[i][j].position += mainPattern[i].position;
            }
        }
        return(outPut);
    }
예제 #3
0
        protected override void OnSetSource(object source)
        {
            var art = source;

            if (!(art is ArtImage))
            {
                art = new ArtImage((Art)art);
                if (Source is ArtImage)
                {
                    ((ArtImage)art).SetImage((ArtImage)Source);
                }
            }
            base.OnSetSource(art);
        }
예제 #4
0
    public Mesh CreateMesh(ArtImage artImage, Direction direction = Direction.Floor, float size = 1)
    {
        MatPairStruct id = artImage.id;

        if (!generatedMeshes.ContainsKey(direction))
        {
            generatedMeshes[direction] = new Dictionary <MatPairStruct, Mesh>();
        }
        if (generatedMeshes[direction].ContainsKey(id))
        {
            return(generatedMeshes[direction][id]);
        }

        vertices.Clear();
        triangles.Clear();
        uvs.Clear();
        indices.Clear();

        Rect[][] imagePattern = GetFullPattern(artImage);
        for (int i = 0; i < imagePattern.Length; i++)
        {
            int tile = GetElementTile(artImage.elements[i]);
            foreach (var item in imagePattern[i])
            {
                switch (direction)
                {
                case Direction.Floor:
                    AddRectToMesh(item, tile, Matrix4x4.Scale(new Vector3(size, size, size)));
                    break;

                case Direction.Wall4:
                    //South
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(0, GameMap.tileWidth / 2, -GameMap.tileWidth / 2),
                                      Quaternion.Euler(-90, 0, 0),
                                      new Vector3(size, size, size)));
                    //West
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(-GameMap.tileWidth / 2, GameMap.tileWidth / 2, 0),
                                      Quaternion.Euler(-90, 0, 90),
                                      new Vector3(size, size, size)));
                    //North
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(0, GameMap.tileWidth / 2, GameMap.tileWidth / 2),
                                      Quaternion.Euler(-90, 0, 180),
                                      new Vector3(size, size, size)));
                    //East
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(GameMap.tileWidth / 2, GameMap.tileWidth / 2, 0),
                                      Quaternion.Euler(-90, 0, 270),
                                      new Vector3(size, size, size)));
                    break;

                case Direction.Front:
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      Vector3.zero,
                                      Quaternion.Euler(-90, 0, 0),
                                      new Vector3(size, size, size)));
                    break;

                case Direction.WallNorth:
                    //North
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(0, GameMap.tileWidth / 2, GameMap.tileWidth / 2),
                                      Quaternion.Euler(-90, 0, 180),
                                      new Vector3(size, size, size)));
                    break;

                case Direction.WallNorthWest:
                    //West
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(-GameMap.tileWidth / 2, GameMap.tileWidth / 2, 0),
                                      Quaternion.Euler(-90, 0, 90),
                                      new Vector3(size, size, size)));
                    //North
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(0, GameMap.tileWidth / 2, GameMap.tileWidth / 2),
                                      Quaternion.Euler(-90, 0, 180),
                                      new Vector3(size, size, size)));
                    break;

                case Direction.WallWest:
                    //West
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(-GameMap.tileWidth / 2, GameMap.tileWidth / 2, 0),
                                      Quaternion.Euler(-90, 0, 90),
                                      new Vector3(size, size, size)));
                    break;

                case Direction.WallSouthWest:
                    //South
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(0, GameMap.tileWidth / 2, -GameMap.tileWidth / 2),
                                      Quaternion.Euler(-90, 0, 0),
                                      new Vector3(size, size, size)));
                    //West
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(-GameMap.tileWidth / 2, GameMap.tileWidth / 2, 0),
                                      Quaternion.Euler(-90, 0, 90),
                                      new Vector3(size, size, size)));
                    break;

                case Direction.WallSouth:
                    //South
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(0, GameMap.tileWidth / 2, -GameMap.tileWidth / 2),
                                      Quaternion.Euler(-90, 0, 0),
                                      new Vector3(size, size, size)));
                    break;

                case Direction.WallSouthEast:
                    //South
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(0, GameMap.tileWidth / 2, -GameMap.tileWidth / 2),
                                      Quaternion.Euler(-90, 0, 0),
                                      new Vector3(size, size, size)));
                    //East
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(GameMap.tileWidth / 2, GameMap.tileWidth / 2, 0),
                                      Quaternion.Euler(-90, 0, 270),
                                      new Vector3(size, size, size)));
                    break;

                case Direction.WallEast:
                    //East
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(GameMap.tileWidth / 2, GameMap.tileWidth / 2, 0),
                                      Quaternion.Euler(-90, 0, 270),
                                      new Vector3(size, size, size)));
                    break;

                case Direction.WallNorthEast:
                    //North
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(0, GameMap.tileWidth / 2, GameMap.tileWidth / 2),
                                      Quaternion.Euler(-90, 0, 180),
                                      new Vector3(size, size, size)));
                    //East
                    AddRectToMesh(item, tile, Matrix4x4.TRS(
                                      new Vector3(GameMap.tileWidth / 2, GameMap.tileWidth / 2, 0),
                                      Quaternion.Euler(-90, 0, 270),
                                      new Vector3(size, size, size)));
                    break;

                default:
                    break;
                }
            }
        }
        var mesh = new Mesh();

        mesh.SetVertices(vertices);
        mesh.SetTriangles(triangles, 0);
        mesh.SetUVs(0, uvs);
        mesh.SetUVs(3, indices);
        mesh.RecalculateBounds();
        mesh.RecalculateNormals();
        mesh.RecalculateTangents();
        generatedMeshes[direction][id] = mesh;
        return(mesh);
    }
예제 #5
0
    internal void UpdateImprovement(RemoteFortressReader.ItemImprovement improvement)
    {
        Color matColor     = ContentLoader.GetColor(improvement.material);
        float textureIndex = ContentLoader.GetPatternIndex(improvement.material);
        float shapeIndex   = ContentLoader.GetShapeIndex(improvement.material);

        image = improvement.image;

        if (actualModel != null)
        {
            Destroy(actualModel);
            actualModel = null;
        }


        GameObject prefab = null;

        switch (improvement.type)
        {
        case ImprovementType.ART_IMAGE:
            prefab = DecorationManager.Instance.Image;
            break;

        case ImprovementType.BANDS:
        case ImprovementType.COVERED:
            prefab = DecorationManager.Instance.GetShape(improvement.shape);
            break;

        case ImprovementType.RINGS_HANGING:
            prefab = DecorationManager.Instance.Ring;
            break;

        case ImprovementType.SPIKES:
            prefab = DecorationManager.Instance.Spike;
            break;

        default:
            break;
        }

        if (prefab == null)
        {
            gameObject.SetActive(false);
            return;
        }

        actualModel = Instantiate(prefab, transform, false);

        meshFilter   = actualModel.GetComponentInChildren <MeshFilter>();
        meshRenderer = actualModel.GetComponentInChildren <MeshRenderer>();
        if (improvement.type == ImprovementType.ART_IMAGE)
        {
            meshFilter.sharedMesh = ImageManager.Instance.CreateMesh(improvement.image, ImageManager.Direction.Front);
        }
        else
        {
            originalMaterial            = meshRenderer.sharedMaterial;
            meshRenderer.sharedMaterial = ContentLoader.getFinalMaterial(originalMaterial, matColor.a);
        }

        MaterialPropertyBlock prop = new MaterialPropertyBlock();

        prop.SetColor("_MatColor", matColor);
        prop.SetFloat("_MatIndex", textureIndex);
        prop.SetFloat("_ShapeIndex", shapeIndex);
        meshRenderer.SetPropertyBlock(prop);
        gameObject.SetActive(true);
    }
예제 #6
0
 public void SetImage(ArtImage artImage)
 {
     _image         = artImage._image;
     IsImageChanged = artImage.IsImageChanged;
     OnPropertyChanged(ImagePropertyName);
 }