Example #1
0
        public void Test_GetHashValue()
        {
            var mat1 = new MyMaterial (1, 2.0f, "String");
            var mat2 = new MyMaterial (1, 2.0f, "String");
            var hash1 = mat1.GetHashValue ();
            var hash2 = mat2.GetHashValue ();

            Assert.AreEqual (hash1, hash2);

            mat1.Value1 = 0;
            mat2.Value1 = -1;

            hash1 = mat1.GetHashValue ();
            hash2 = mat2.GetHashValue ();

            Assert.AreNotEqual (hash1, hash2);
        }
Example #2
0
 public ItemStack(MyMaterial material, int amount)
 {
     this.material = material;
     this.amount   = amount;
 }
Example #3
0
    public void setType(MyMaterial MyMaterial, bool updateNow = true)
    {
        material = MyMaterial;
        Stack <Chunk> chunksToUpdate = new Stack <Chunk>();
        Vector        chunkVector    = getChunkVector();
        Vector        vectorInChunk  = getVectorInChunk();

        if (vectorInChunk.getX() >= GameManager.chunkSize - 1)
        {
            Chunk chunk = GameManager.getChunk(chunkVector.add(new Vector(1, 0, 0)));
            chunksToUpdate.Push(chunk);
        }
        else if (vectorInChunk.getX() <= 0)
        {
            Chunk chunk = GameManager.getChunk(chunkVector.add(new Vector(-1, 0, 0)));
            chunksToUpdate.Push(chunk);
        }
        if (vectorInChunk.getY() >= GameManager.chunkSize - 1)
        {
            Chunk chunk = GameManager.getChunk(chunkVector.add(new Vector(0, 1, 0)));
            chunksToUpdate.Push(chunk);
        }
        else if (vectorInChunk.getY() <= 0)
        {
            Chunk chunk = GameManager.getChunk(chunkVector.add(new Vector(0, -1, 0)));
            chunksToUpdate.Push(chunk);
        }
        if (vectorInChunk.getZ() >= GameManager.chunkSize - 1)
        {
            Chunk chunk = GameManager.getChunk(chunkVector.add(new Vector(0, 0, 1)));
            chunksToUpdate.Push(chunk);
        }
        else if (vectorInChunk.getZ() <= 0)
        {
            Chunk chunk = GameManager.getChunk(chunkVector.add(new Vector(0, 0, -1)));
            chunksToUpdate.Push(chunk);
        }
        Chunk thisChunk = getChunk();

        if (MyMaterial != MyMaterial.AIR)
        {
            thisChunk.hasBlock = true;
        }
        chunksToUpdate.Push(thisChunk);
        // Debug.Log(chunkVector + "    " + vectorInChunk + "   " + chunksToUpdate.Count);
        while (chunksToUpdate.Count > 0)
        {
            Chunk chunk = chunksToUpdate.Pop();
            if (updateNow)
            {
                Scheduler.runTaskAsynchronously(() => {
                    ChunkMeshCreator.pushMeshData(chunk);
                    Scheduler.runTaskSynchronously(() => {
                        chunk.display();
                    });
                });
            }
            else
            {
                ChunkMeshCreator.immediateRenderChunks.Enqueue(chunk);
            }
        }
        thisChunk.needSave = true;

        //Remove all block damage
        damagedValue = 0;
        thisChunk.damagedBlocksIndexs.Remove(Chunk.getIndex(getVectorInChunk()));
    }
Example #4
0
 public void Setup(MyMaterial material)
 {
     this.material = material;
     GetComponent <Image>().sprite = material.img;
 }
Example #5
0
        public Mesh[] LoadJSONFileAsync(string fileName)
        {
            string           data   = System.IO.File.ReadAllText(fileName);
            var              meshes = new List <Mesh>();
            JToken           jtoken = Newtonsoft.Json.JsonConvert.DeserializeObject(data) as JToken;
            MyMeshCollection myMesh = jtoken.ToObject <MyMeshCollection>();


            List <Mesh> meshList = new List <Mesh>();

            List <MyMaterial> materials = myMesh.materials;

            Dictionary <string, MyMaterial> material_dic = new Dictionary <string, MyMaterial>();
            int meshCount = myMesh.meshes.Count;

            for (int materialIndex = 0; materialIndex < materials.Count; materialIndex++)
            {
                MyMaterial myMaterial = materials[materialIndex];

                if (myMaterial.diffuseTexture != null)
                {
                    myMaterial.DiffuseTextureName = (myMaterial.diffuseTexture.name);
                }


                material_dic.Add(myMaterial.id, myMaterial);
            }

            for (int meshIndex = 0; meshIndex < meshCount; ++meshIndex)
            {
                MyMesh   mymesh        = myMesh.meshes[meshIndex];
                double[] verticesArray = mymesh.vertices;
                int[]    indicesArray  = mymesh.indices;
                double[] position      = mymesh.position;

                int uvCount      = mymesh.uvCount;
                int verticesStep = 1;
                switch (uvCount)
                {
                case 0:
                    verticesStep = 6;
                    break;

                case 1:
                    verticesStep = 8;
                    break;

                case 2:
                    verticesStep = 10;
                    break;
                }
                // the number of interesting vertices information for us
                int verticesCount = verticesArray.Length / verticesStep;
                // number of faces is logically the size of the array divided by 3 (A, B, C)
                int facesCount = indicesArray.Length / 3;


                Mesh mesh = new Mesh(mymesh.name, verticesCount, facesCount);
                meshList.Add(mesh);
                // Filling the Vertices array of our mesh first
                for (var index = 0; index < verticesCount; index++)
                {
                    double x = verticesArray[index * verticesStep];
                    double y = verticesArray[index * verticesStep + 1];
                    double z = verticesArray[index * verticesStep + 2];
                    // Loading the vertex normal exported by Blender
                    double nx = verticesArray[index * verticesStep + 3];
                    double ny = verticesArray[index * verticesStep + 4];
                    double nz = verticesArray[index * verticesStep + 5];

                    if (uvCount > 0)
                    {   // Loading the texture coordinates
                        double u = verticesArray[index * verticesStep + 6];
                        double v = verticesArray[index * verticesStep + 7];
                        mesh.Vertices[index] = new Vertex
                        {
                            Coordinates        = new Vector3d(x, y, z),
                            Normal             = new Vector3d(nx, ny, nz),
                            TextureCoordinates = new Vector2d(u, v)
                        };
                    }
                    else
                    {   //no uv
                        mesh.Vertices[index] = new Vertex
                        {
                            Coordinates = new Vector3d(x, y, z),
                            Normal      = new Vector3d(nx, ny, nz)
                        };
                    }
                }


                // Then filling the Faces array
                for (var index = 0; index < facesCount; index++)
                {
                    int a = indicesArray[index * 3];
                    int b = indicesArray[index * 3 + 1];
                    int c = indicesArray[index * 3 + 2];
                    mesh.Faces[index] = new Face {
                        A = a, B = b, C = c
                    };
                }

                // Getting the position you've set in Blender
                mesh.Position = new Vector3d(position[0], position[1], position[2]);


                if (uvCount > 0)
                {
                    // Texture
                    string meshTextureID   = mymesh.materialId;
                    string meshTextureName = material_dic[meshTextureID].DiffuseTextureName;
                    mesh.Texture = new Texture(meshTextureName, 512, 512);
                }
                mesh.ComputeFaceNormals();
            }

            return(meshList.ToArray());
        }
        private void SAVE()
        {
            if (this.materialComboBox.Items.Count == 0)
            {
                return;
            }

            int index          = 0;
            int materialNumber = Convert.ToInt32(this.materialComboBox.SelectedItem.ToString().Split(' ')[0]);

            foreach (MyMaterial mat in this.parent.currentFullModel.materials.ListOfMaterials)
            {
                if (mat.Id == materialNumber)
                {
                    index = this.parent.currentFullModel.materials.ListOfMaterials.IndexOf(mat);
                    break;
                }
            }


            // разпарсиваем номера зон для назначения материалов
            if (this.parent.currentFullModel.FiniteElementModels.Count != 0 && this.areasRadioBut.Checked)
            {
                int currentModel = this.parent.GetCurrentModelIndex();
                if (this.areaMaterials.TextLength != 0 && this.parent.currentFullModel.FiniteElementModels[currentModel].FiniteElements.Count != 0)
                {
                    List <string> areasNumbers = new List <string>(this.areaMaterials.Text.Split(',').AsEnumerable <string>());

                    bool matExists = false;
                    for (int j = 0; j < usedMaterials.Rows.Count; j++)
                    {
                        if (Convert.ToInt32(usedMaterials.Rows[j].Cells["matID"].Value) == materialNumber)
                        {
                            matExists = true;
                        }
                    }

                    if (!matExists && this.usedMaterials.Rows.Count == 3)
                    {
                        MessageBox.Show("Для одной модели может быть задано не более трех материалов!");
                        return;
                    }
                    //this.parent.currentFullModel.FiniteElementModels[0].NMAT = this.usedMaterials.Rows.Count;

                    if (this.parent.currentFullModel.FiniteElementModels[currentModel].UsedMaterials.IndexOf(materialNumber) == -1)
                    {
                        this.parent.currentFullModel.FiniteElementModels[currentModel].UsedMaterials.Add(materialNumber);
                    }
                    if (this.parent.currentFullModel.FiniteElementModels[currentModel].Materials.IndexOf(this.parent.currentFullModel.materials.ListOfMaterials[index]) == -1)
                    {
                        this.parent.currentFullModel.FiniteElementModels[currentModel].Materials.Add(this.parent.currentFullModel.materials.ListOfMaterials[index]);
                    }



                    // добрались до назначения материалов КЭ

                    matExists = false;
                    for (int i = 0; i < this.parent.currentFullModel.geometryModel.Areas.Count; i++)
                    {
                        foreach (string str in areasNumbers)
                        {
                            try
                            {
                                Convert.ToInt32(str);
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show(e.Message);
                                return;
                            }
                            if (this.parent.currentFullModel.geometryModel.Areas[i].Id == Convert.ToInt32(str))
                            {
                                for (int j = 0; j < usedMaterials.Rows.Count; j++)
                                {
                                    if (Convert.ToInt32(usedMaterials.Rows[j].Cells["matID"].Value) == materialNumber)
                                    {
                                        matExists = true;
                                    }
                                }
                                if (!matExists)
                                {
                                    MyMaterial mat = this.parent.currentFullModel.materials.ListOfMaterials[index];
                                    object[]   row = { "удалить", mat.Id, mat.Name, mat.ElasticModulus, mat.PoissonsRatio, mat.Tension, mat.Tension2, mat.Thickness };
                                    this.usedMaterials.Rows.Add(row);
                                }
                                List <MyFiniteElement> elems = parent.currentFullModel.FiniteElementModels[currentModel].FiniteElements.FindAll(fe => fe.areaId == parent.currentFullModel.geometryModel.Areas[i].Id - 1);
                                elems.ForEach(e => e.MaterialPropertyID = materialNumber);
                            }
                        }
                    }
                }
            }

            // разпарсиваем номера КЭ для назначения материалов
            if (this.parent.currentFullModel.FiniteElementModels.Count != 0 && this.FERadioBut.Checked)
            {
                int currentModel = this.parent.GetCurrentModelIndex();
                if (this.FEMaterials.TextLength != 0 && this.parent.currentFullModel.FiniteElementModels[currentModel].FiniteElements.Count != 0)
                {
                    List <string> FENumbers = new List <string>(this.FEMaterials.Text.Split(',').AsEnumerable <string>());

                    bool matExists = false;
                    for (int j = 0; j < usedMaterials.Rows.Count; j++)
                    {
                        if (Convert.ToInt32(usedMaterials.Rows[j].Cells["matID"].Value) == materialNumber)
                        {
                            matExists = true;
                        }
                    }

                    if (!matExists && this.usedMaterials.Rows.Count == 3)
                    {
                        MessageBox.Show("Для одной модели может быть задано не более трех материалов!");
                        return;
                    }

                    if (this.parent.currentFullModel.FiniteElementModels[currentModel].UsedMaterials.IndexOf(materialNumber) == -1)
                    {
                        this.parent.currentFullModel.FiniteElementModels[currentModel].UsedMaterials.Add(materialNumber);
                    }
                    if (this.parent.currentFullModel.FiniteElementModels[currentModel].Materials.IndexOf(this.parent.currentFullModel.materials.ListOfMaterials[index]) == -1)
                    {
                        this.parent.currentFullModel.FiniteElementModels[currentModel].Materials.Add(this.parent.currentFullModel.materials.ListOfMaterials[index]);
                    }



                    // добрались до назначения материалов КЭ
                    matExists = false;
                    foreach (MyFiniteElement FE in this.parent.currentFullModel.FiniteElementModels[currentModel].FiniteElements)
                    {
                        foreach (string str in FENumbers)
                        {
                            try
                            {
                                Convert.ToInt32(str);
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show(e.Message);
                                return;
                            }
                            if (FE.Id == Convert.ToInt32(str))
                            {
                                for (int j = 0; j < usedMaterials.Rows.Count; j++)
                                {
                                    if (Convert.ToInt32(usedMaterials.Rows[j].Cells["matID"].Value) == materialNumber)
                                    {
                                        matExists = true;
                                    }
                                }
                                if (!matExists)
                                {
                                    MyMaterial mat = this.parent.currentFullModel.materials.ListOfMaterials[index];
                                    object[]   row = { "удалить", mat.Id, mat.Name, mat.ElasticModulus, mat.PoissonsRatio, mat.Tension, mat.Tension2, mat.Thickness };
                                    this.usedMaterials.Rows.Add(row);
                                }
                                FE.MaterialPropertyID = materialNumber;
                            }
                        }
                    }
                }
            }


            this.parent.ReDrawAll();
        }