예제 #1
0
 public void SetPosition(Vector3 position)
 {
     this.position = position;
     this.hashCode = EditUtil.PositionToHashCode(position);
     if (this.gameObject != null)
     {
         this.gameObject.transform.position = this.position + this.shape.offset + this.offset;
     }
 }
예제 #2
0
    // 位置指定でブロックの取得
    public Block GetBlock(Vector3 position)
    {
        int   key = EditUtil.PositionToHashCode(position);
        Block value;

        if (this.blocks.TryGetValue(key, out value))
        {
            return(value);
        }
        return(null);
    }
예제 #3
0
    public Model GetModel(Vector3 position)
    {
        int hash = EditUtil.PositionToHashCode(position);

        for (int i = 0; i < this.models.Count; i++)
        {
            if (hash == this.models[i].GetHashCode())
            {
                return(this.models[i]);
            }
        }
        return(null);
    }
예제 #4
0
 public void SetPosition(Vector3 position)
 {
     this.position = position;
     this.hashCode = EditUtil.PositionToHashCode(position);
 }
예제 #5
0
    // ブロックメッシュをマージ
    public void Merge(Mesh mesh, Vector3 position, BlockDirection direction, Vector3 scale,
                      bool divideChipVert, int textureId, int meshId)
    {
        var chip = TexturePalette.Instance.GetChip(textureId);

        int vertexOffset = this.vertexPos.Count;

        Vector3[] vertexPos    = mesh.vertices;
        Vector3[] vertexNormal = mesh.normals;
        Vector2[] vertexUv     = mesh.uv;
        int[]     indices      = mesh.GetIndices(0);
        float[]   heights      = new float[vertexUv.Length];

        // Vが0.0~1.0の範囲外の場合は高さを調整する
        for (int j = 0; j < indices.Length; j += 3)
        {
            Vector2 uv0 = vertexUv[indices[j + 0]];
            Vector2 uv1 = vertexUv[indices[j + 1]];
            Vector2 uv2 = vertexUv[indices[j + 2]];

            float height = position.y;

            if (uv0.y < 0.0f || uv1.y < 0.0f || uv2.y < 0.0f)
            {
                height += 0.5f;
            }
            else if (uv0.y > 1.0f || uv1.y > 1.0f || uv2.y > 1.0f)
            {
                height -= 0.5f;
            }

            heights[indices[j + 0]] = height;
            heights[indices[j + 1]] = height;
            heights[indices[j + 2]] = height;
        }

        for (int j = 0; j < vertexPos.Length; j++)
        {
            Vector3 localPosition = Vector3.Scale(vertexPos[j], Vector3.Scale(new Vector3(-1, 1, -1), scale));
            Vector3 localNormal   = Vector3.Scale(vertexNormal[j], new Vector3(-1, 1, -1));
            this.vertexPos.Add(position + EditUtil.RotatePosition(localPosition, direction));
            this.vertexNormal.Add(EditUtil.RotatePosition(localNormal, direction));
            this.vertexUv.Add(chip.ApplyUV(vertexUv[j], divideChipVert, heights[j]));
            this.vertexMeta.Add(new Vector2((float)meshId, 0.0f));
        }
        for (int j = 0; j < indices.Length; j++)
        {
            this.triangles.Add(vertexOffset + indices[j]);
        }

        if (this.subMeshMerger != null)
        {
            int key = EditUtil.PositionToHashCode(new Vector3(
                                                      Mathf.Floor(position.x / this.subMeshDivs.x),
                                                      Mathf.Floor(position.y / this.subMeshDivs.y),
                                                      Mathf.Floor(-position.z / this.subMeshDivs.z)));

            if (!this.subMeshMerger.ContainsKey(key))
            {
                this.subMeshMerger.Add(key, new BlockMeshMerger());
            }
            this.subMeshMerger[key].Merge(mesh, position, direction, scale, divideChipVert, textureId, meshId);
        }
    }