Exemple #1
0
        public override void ApplyLOD()
        {
            BaseMesh bmesh = base.GetModel();

            if (bmesh is ProgressiveMesh)
            {
                return;
            }

            if (bmesh != null && !bmesh.Disposed)
            {
                float LODquality = 1f;

                bool enableLOD = base.isEnableLOD();

                if (enableLOD)
                {
                    LODquality = 1f / (1f + 0.003f * base.GetDistanceFromCamera());
                }

                ProgressiveMesh mesh = bmesh as ProgressiveMesh;
                int             LOD  = (int)(mesh.MaxFaces * LODquality * base.GetObjectQuality());

                if (lastLOD != LOD && enableLOD)
                {
                    mesh.NumberFaces = LOD;
                    lastLOD          = LOD;
                }
            }

            base.ApplyLOD();
        }
Exemple #2
0
    void ExportImage(BaseMesh _target, string exportName)
    {
        if (exportName == null || exportName == "")
        {
            EditorUtility.DisplayDialog("Error!", "Export file name field is empty." +
                                        "Please specify the file name in which you want to export the map.", "Got it!");
            return;
        }

        Texture2D exportImage = new Texture2D(_target.GridColumnCount, _target.GridRowCount, TextureFormat.RGB24, false, true);

        for (int i = 0; i < _target.GridColumnCount; i++)
        {
            for (int j = 0; j < _target.GridRowCount; j++)
            {
                exportImage.SetPixel(i, j, _target.gridArrayColumn[i].gridRow[j].filled ? Color.black : Color.white);
            }
        }

        byte[] bytes = exportImage.EncodeToJPG();

        string path = Application.dataPath + "/Resources/LevelsExport/" + exportName + ".jpg";

        System.IO.File.WriteAllBytes(path, bytes);

        EditorUtility.DisplayDialog("Success", "Exported successfully here. \n" + path, "Thanks!");

        AssetDatabase.ImportAsset(path);
        AssetDatabase.Refresh();
    }
        public override void ApplyLOD()
        {
            BaseMesh bmesh = base.GetModel();

            if (bmesh != null && !bmesh.Disposed)
            {
                float LODquality = 1f;

                if (base.isEnableLOD())
                {
                    LODquality = 1f / (1f + 0.008f * base.GetDistanceFromCamera());
                }

                ProgressiveMesh mesh = bmesh as ProgressiveMesh;
                int             LOD  = (int)(mesh.MaxFaces * LODquality * base.GetObjectQuality());

                if (lastLOD != LOD)
                {
                    try
                    {
                        mesh.NumberFaces = LOD;
                        lastLOD          = LOD;
                    }
                    catch (Exception ex)
                    {
                        Logging.Logger.AddError(ex.Message);
                    }
                }
            }

            base.ApplyLOD();
        }
        public QuadTreeGeneralObject(int level, GeneralObject.GeneralVertex[] vertexes, int[] indexes, Vector3 minPosition, Vector3 maxPosition, Matrix world, Texture[] color_textures0, Texture[] color_textures1, Texture[] color_textures2, Texture[] normal_textures)
            : base(null, world, color_textures0, color_textures1, color_textures2, normal_textures)
        {
            this.vertexes = vertexes;

            this.mesh   = null;
            this.device = color_textures0[0].Device;

            this.vertexDecl = new VertexDeclaration(this.device, GeneralObject.GeneralVertex.vertexElements);

            this.vb = new VertexBuffer(typeof(GeneralObject.GeneralVertex), vertexes.Length, this.device, Usage.WriteOnly, GeneralObject.GeneralVertex.Format, Pool.Managed);
            this.vb.SetData(vertexes, 0, LockFlags.NoSystemLock);

            Key key = new Key(this.device, base.GetMatrixWorld(), this.vertexes, indexes, minPosition, maxPosition);

            this.radius = key.radius;
            this.boundingSphereCenter = key.boundingSphereCenter;

            this.quadTree = new TreeGraph <Key>(4, key);

            try
            {
                GenerateQuadTree(level, this.quadTree);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
Exemple #5
0
        } // Renderizar().fim

        // ---]
        // [---
        private void desenharObjeto(BaseMesh obj, Propriedades3D props)
        {
            // Ajusta rotação do objeto 3d
            Matrix obj_rot = Matrix.RotationX(props.rotation.X + angulo) *
                             Matrix.RotationY(props.rotation.Y) *
                             Matrix.RotationZ(props.rotation.Z);

            // Ajusta posição do objeto 3d
            Matrix obj_pos = Matrix.Translation(props.position);

            // Tranfere posição e rotação para o mundo
            device.Transform.World = obj_rot * obj_pos;

            // Prepara e aplica material\textura no objeto
            for (int ncx = 0; ncx < g_meshMtl.Length; ncx++)
            {
                // Informa ao dispositivo o material a ser utilizado
                // na renderização
                device.Material = g_meshMtl[ncx];
                device.SetTexture(0, g_meshTex[ncx]);

                // Renderiza o mesh
                obj.DrawSubset(ncx);
            } // endfor
        }     // desenharObjeto().fim
Exemple #6
0
    void ImportImage(BaseMesh _target, Texture2D _sourceTexture)
    {
        if (_sourceTexture == null)
        {
            EditorUtility.DisplayDialog("Error!", "Import image field is empty. " +
                                        "Please assign any image from project to import it as a level.\n " +
                                        "And please make that texture read/write enabled in import settings.", "Got it!");
            return;
        }

        //Just to make the texture readable from Import settings.
        string          path          = AssetDatabase.GetAssetPath(_sourceTexture);
        TextureImporter importSetting = (TextureImporter)AssetImporter.GetAtPath(path);

        importSetting.isReadable = true;
        importSetting.generateMipsInLinearSpace = false;
        importSetting.npotScale = TextureImporterNPOTScale.None;
        AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);

        //Parsing image and converting it into Map.
        _target.GridColumnCount = _sourceTexture.width;
        _target.GridRowCount    = _sourceTexture.height;

        GridArray [] tempGridArray = new GridArray[_target.GridColumnCount];
        for (int i = 0; i < tempGridArray.GetLength(0); i++)
        {
            tempGridArray[i] = new GridArray(new Grid [_target.GridRowCount]);
        }

        for (int i = 0; i < _target.GridColumnCount; i++)
        {
            for (int j = 0; j < _target.GridRowCount; j++)
            {
                Color readColor = _sourceTexture.GetPixel(i, j);

                bool filled;
                if (((readColor.r + readColor.g + readColor.b) / 3) < 0.5f)
                {
                    filled = true;
                }
                else
                {
                    filled = false;
                }

                tempGridArray[i].gridRow[j] = new Grid(filled, i, j, new Vector3(_target.GridXOffset + i * _target.gridScale + _target.gridScale / 2,
                                                                                 _target.yOffset,
                                                                                 _target.GridZOffset + j * _target.gridScale + _target.gridScale / 2));
            }
        }
        _target.gridArrayColumn = tempGridArray;
    }
        public static Task CreateIndependenceActionTask(
            AuthTokens tokens,
            string url,
            string path,
            string parentId,
            string dependentOn,
            BaseMesh meshData,
            bool create
            )
        {
            var actionTask = new GenericViewSet <Task>(
                tokens,
                url,
                path
                ).GetOrCreate(
                new Dictionary <string, object>
            {
                { "name", "Actions" },
                { "parent", parentId },
                { "dependent_on", dependentOn }
            },
                new Dictionary <string, object>
            {
                {
                    "config", new Dictionary <string, object>
                    {
                        { "task_type", "magpy" },
                        { "cmd", "pipelines.pipeline" },
                        { "commands", new List <string>
                          {
                              "magpy_copytree",
                              "write_mesh"
                          } },
                        { "src", "foam" },
                        { "dst", $"independence/mesh_{meshData.CellSize}/foam" },
                        { "base_mesh", meshData },
                        { "snappyhex_mesh", null }
                    }
                }
            },
                create
                );

            return(actionTask);
        }
Exemple #8
0
        public static Result Hook06000035(BaseMesh obj, int subset)
        {
            TextureAddress addr_u = 0.0f <= mat_last.Specular.Red && mat_last.Specular.Green <= 1.0f ? TextureAddress.Clamp : TextureAddress.Wrap;

            if (addr_u != last_u)
            {
                obj.Device.SetSamplerState(0, SamplerState.AddressU, addr_u);
                last_u = addr_u;
            }
            TextureAddress addr_v = 0.0f <= mat_last.Specular.Blue && mat_last.Specular.Alpha <= 1.0f ? TextureAddress.Clamp : TextureAddress.Wrap;

            if (addr_v != last_v)
            {
                obj.Device.SetSamplerState(0, SamplerState.AddressV, addr_v);
                last_v = addr_v;
            }
            return(obj.DrawSubset(subset));
        }
        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="mesh">Objekt, ktery se bude kreslit</param>
        /// <param name="world">World matice</param>
        /// <param name="color_textures0">Pole textur nultyho bufferu</param>
        /// <param name="color_textures1">Pole textur prvniho bufferu</param>
        /// <param name="color_textures2">Pole textur druhyho bufferu</param>
        /// <param name="normal_textures">Pole normalovych textur</param>
        public GeneralObject(BaseMesh mesh, Matrix world, Texture[] color_textures0, Texture[] color_textures1, Texture[] color_textures2, Texture[] normal_textures)
        {
            SetModel(mesh);
            this.color_textures0 = color_textures0;
            this.color_textures1 = color_textures1;
            this.color_textures2 = color_textures2;
            this.normal_textures = normal_textures;

            worldOriginal = world;

            SetMatrixWorld(world);

            if (mesh != null)
            {
                VertexBuffer   vb  = mesh.VertexBuffer;
                GraphicsStream gsm = vb.Lock(0, 0, LockFlags.ReadOnly);
                radius = Geometry.ComputeBoundingSphere(gsm, mesh.NumberVertices, GeneralVertex.SizeInBytes, out boundingSphereCenter);
                Geometry.ComputeBoundingBox(gsm, mesh.NumberVertices, GeneralVertex.SizeInBytes, out minBoundingPosition, out maxBoundingPosition);
                vb.Unlock();

                Vector3 size = maxBoundingPosition - minBoundingPosition;

                boundingSphereMesh = Mesh.Sphere(this.mesh.Device, radius, 8, 8);

                Vector3 length = maxBoundingPosition - minBoundingPosition;

                boundingBoxMesh = Mesh.Box(this.mesh.Device, length.X, length.Y, length.Z);
                Mesh temp = boundingSphereMesh.Clone(MeshFlags.Managed, GeneralObject.GeneralVertex.vertexElements, vb.Device);
                boundingSphereMesh.Dispose();
                boundingSphereMesh = temp;
                temp = boundingBoxMesh.Clone(MeshFlags.Managed, GeneralObject.GeneralVertex.vertexElements, vb.Device);
                boundingBoxMesh.Dispose();
                boundingBoxMesh = temp;

                boundingMeshWorld      = new Matrix[4];
                boundingMeshWorldIT    = new Matrix[4];
                boundingMeshWorld[0]   = Matrix.Translation(boundingSphereCenter) * GetMatrixWorld();
                boundingMeshWorld[1]   = Matrix.Translation(0.5f * (minBoundingPosition + maxBoundingPosition)) * GetMatrixWorld();
                boundingMeshWorldIT[0] = Matrix.TransposeMatrix(Matrix.Invert(boundingMeshWorld[0]));
                boundingMeshWorldIT[1] = Matrix.TransposeMatrix(Matrix.Invert(boundingMeshWorld[1]));

                boundingBoxNormals = CreateBoundingBoxNormals();
            }
        }
Exemple #10
0
    public override void OnInspectorGUI()
    {
        BaseMesh _target = (BaseMesh)target;

        _target.editGrid = EditorGUILayout.Toggle("Edit Grid", _target.editGrid);
        if (_target.editGrid)
        {
            _target.GridRowCount = EditorGUILayout.IntSlider("Row Count :", _target.GridRowCount, 0, 100, GUILayout.MinWidth(300), GUILayout.MaxWidth(300));

            _target.GridColumnCount = EditorGUILayout.IntSlider("Column Count :", _target.GridColumnCount, 0, 100, GUILayout.MinWidth(300), GUILayout.MaxWidth(300));

            // _target.GridScale = EditorGUILayout.Slider("Scale :", _target.GridScale, 0.01f, 1);

            _target.GridXOffset = EditorGUILayout.FloatField("Offset X :", _target.GridXOffset);

            _target.GridZOffset = EditorGUILayout.FloatField("Offset Y :", _target.GridZOffset);


            //Export Level as a image.
            GUILayout.BeginHorizontal();
            exportName = EditorGUILayout.TextField(new GUIContent(), exportName, GUILayout.MinWidth(100), GUILayout.MaxWidth(100));
            if (GUILayout.Button("Export Level", GUILayout.MinWidth(100), GUILayout.MaxWidth(100)))
            {
                ExportImage(_target, exportName);
            }
            GUILayout.EndHorizontal();


            //Import Level from a image.
            GUILayout.BeginHorizontal();
            importImage = EditorGUILayout.ObjectField(new GUIContent(), importImage, typeof(Texture2D), true, GUILayout.MinWidth(100), GUILayout.MaxWidth(100)) as Texture2D;
            if (GUILayout.Button("Import Level", GUILayout.MinWidth(100), GUILayout.MaxWidth(100)))
            {
                ImportImage(_target, importImage);
            }
            GUILayout.EndHorizontal();

            GridMapEditor(_target);
        }

        SceneView.RepaintAll();
    }
        /// <summary>
        /// Provede uklid textur, meshe a bounding boxu
        /// </summary>
        public virtual void Dispose()
        {
            if (normal_textures != null)
            {
                for (int t = 0; t < normal_textures.Length; t++)
                {
                    if (normal_textures[t] != null && !normal_textures[t].Disposed)
                    {
                        normal_textures[t].Dispose();
                    }
                }
            }

            if (color_textures0 != null)
            {
                for (int t = 0; t < color_textures0.Length; t++)
                {
                    if (color_textures0[t] != null && !color_textures0[t].Disposed)
                    {
                        color_textures0[t].Dispose();
                    }
                }
            }

            if (mesh != null && !mesh.Disposed)
            {
                try
                {
                    mesh.Dispose();
                    mesh = null;
                }
                catch { }
            }

            if (boundingSphereMesh != null && !boundingSphereMesh.Disposed)
            {
                boundingSphereMesh.Dispose();
            }

            disposed = true;
        }
Exemple #12
0
    void GridMapEditor(BaseMesh _target)
    {
        for (int i = 0; i < _target.GridColumnCount; i++)
        {
            GUILayout.BeginHorizontal();
            for (int j = 0; j < _target.GridRowCount; j++)
            {
                if (_target.gridArrayColumn == null ||
                    i >= _target.gridArrayColumn.Length ||
                    _target.gridArrayColumn[i] == null ||
                    j >= _target.gridArrayColumn[i].gridRow.Length ||
                    _target.gridArrayColumn[i].gridRow[j] == null)
                {
                    continue;
                }

                _target.gridArrayColumn[i].gridRow[j].filled = EditorGUILayout.Toggle(new GUIContent(),                 //"Grid[" + i + "," + j + "] :",
                                                                                      _target.gridArrayColumn[i].gridRow[j].filled,
                                                                                      GUILayout.MinWidth(10),
                                                                                      GUILayout.MaxWidth(10));
            }
            GUILayout.EndHorizontal();
        }
    }
Exemple #13
0
    public void OnEnable()
    {
        BaseMesh _target = (BaseMesh)target;

        BaseMesh.Instance = _target;
    }
Exemple #14
0
 /// <summary>
 /// Use the current technique to render with a Mesh.DrawSubset() call
 /// </summary>
 /// <param name="technique"></param>
 public static void DrawMeshSubset(BaseMesh mesh, int index)
 {
     int passes = effect.Begin(0);
     for (int pass = 0; pass < passes; pass++)
     {
         effect.BeginPass(pass);
         effect.CommitChanges();
         mesh.DrawSubset(index);
         effect.EndPass();
     }
     effect.End();
 }
Exemple #15
0
 void Awake()
 {
     Instance = this;
 }
        // Draws the given mesh
        public void render(BaseMesh mesh)
        {
            if(mesh.texture.ID!= currTextureID)
            {
                currTextureID=	mesh.texture.ID;
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, currTextureID);
            }

            mesh.render();
        }
Exemple #17
0
        // Creates a bounding volume box from the given 3d mesh
        public static BVBox createFromMesh(BaseMesh mesh)
        {
            if(mesh== null)
                throw new ArgumentNullException();

            return createFromPoints(mesh.getVertices());
        }
        /// <summary>
        /// Nastavi model, ktery bude pouzit pro rendering
        /// </summary>
        /// <param name="mesh">Model</param>
        public void SetModel(BaseMesh mesh)
        {
            this.mesh = mesh;

            UpdateVerticesFacesCounters();
        }