Esempio n. 1
0
    private void DrawMeshColors()
    {
        GUILayout.BeginHorizontal(EditorStyles.textField);
        GUILayout.Label("包含Color属性的网格");

        DrawMeshProperties("t:mesh", MeshSetting.ImportColors,
                           (path) =>
        {
            if (MeshExtension.HasColors(path))
            {
                _meshSettingPaths.Add(path);
            }
        }, (path) =>
        {
            MeshExtension.SetColors(path);
        }
                           );

        GUILayout.EndHorizontal();

        DrawMeshScrollList(MeshSetting.ImportColors, (path) =>
        {
            MeshExtension.SetColors(path);
        });
    }
Esempio n. 2
0
    private void DrawMeshSubMesh()
    {
        GUILayout.BeginHorizontal(EditorStyles.textField);
        GUILayout.Label("包含2个及以上SubMesh的网格");

        DrawMeshProperties("t:mesh", MeshSetting.SubMesh,
                           (path) =>
        {
            if (MeshExtension.GetMesh(path).subMeshCount > 1)
            {
                _meshSettingPaths.Add(path);
            }
        }, (path) =>
        {
            _window.ShowNotification(new GUIContent("暂不提供处理逻辑"));
        }
                           );

        GUILayout.EndHorizontal();

        DrawMeshScrollList(MeshSetting.SubMesh, (path) =>
        {
            _window.ShowNotification(new GUIContent("暂不提供处理逻辑"));
        });
    }
Esempio n. 3
0
    private void DrawMeshLights()
    {
        GUILayout.BeginHorizontal(EditorStyles.textField);
        GUILayout.Label("开启Lights导入选项的网格");

        DrawMeshProperties("t:model", MeshSetting.ImportLights,
                           (path) =>
        {
            if (MeshExtension.IsImportLights(path))
            {
                _meshSettingPaths.Add(path);
            }
        }, (path) =>
        {
            MeshExtension.SetImportLights(path);
        }
                           );

        GUILayout.EndHorizontal();

        DrawMeshScrollList(MeshSetting.ImportLights, (path) =>
        {
            MeshExtension.SetImportLights(path);
        });
    }
Esempio n. 4
0
    private void DrawMeshTangents()
    {
        GUILayout.BeginHorizontal(EditorStyles.textField);
        GUILayout.Label("包含Tangent属性的网格");

        DrawMeshProperties("t:model", MeshSetting.ImportTangents,
                           (path) =>
        {
            if (MeshExtension.HasTangents(path))
            {
                _meshSettingPaths.Add(path);
            }
        }, (path) =>
        {
            MeshExtension.SetModelImporterTangents(path);
        }
                           );

        GUILayout.EndHorizontal();

        DrawMeshScrollList(MeshSetting.ImportTangents, (path) =>
        {
            MeshExtension.SetModelImporterTangents(path);
        });
    }
Esempio n. 5
0
    private void DrawMeshReadWrite()
    {
        GUILayout.BeginHorizontal(EditorStyles.textField);
        GUILayout.Label("开启Read/Write选项的网格");

        DrawMeshProperties("t:model", MeshSetting.ReadWriteEnabled,
                           (path) =>
        {
            if (MeshExtension.IsReadable(path))
            {
                _meshSettingPaths.Add(path);
            }
        },
                           (path) =>
        {
            MeshExtension.SetReadable(path);
        }
                           );

        GUILayout.EndHorizontal();

        DrawMeshScrollList(MeshSetting.ReadWriteEnabled, (path) =>
        {
            MeshExtension.SetReadable(path);
        });
    }
Esempio n. 6
0
    private void DrawMeshOptimize()
    {
        GUILayout.BeginHorizontal(EditorStyles.textField);
        GUILayout.Label("未开启OptimizeMesh选项的网格");

        DrawMeshProperties("t:model", MeshSetting.OptimizeMesh,
                           (path) =>
        {
            if (!MeshExtension.IsOptimize(path))
            {
                _meshSettingPaths.Add(path);
            }
        },
                           (path) =>
        {
            MeshExtension.SetOptimize(path);
        }
                           );

        GUILayout.EndHorizontal();

        DrawMeshScrollList(MeshSetting.OptimizeMesh, (path) =>
        {
            MeshExtension.SetOptimize(path);
        });
    }
Esempio n. 7
0
    protected override void OnUpdate()
    {
        if (!initialize)
        {
            List <SpriteSheetMaterial> materials = new List <SpriteSheetMaterial>();
            EntityManager.GetAllUniqueSharedComponentData(materials);
            for (int i = 0; i < materials.Count; i++)
            {
                if (!materials[i].material)
                {
                    materials.Remove(materials[i]);
                }
            }

            renderInfos = new RenderInformation[materials.Count];
            for (int i = 0; i < renderInfos.Length; i++)
            {
                renderInfos[i] = new RenderInformation(materials[i].material);
            }

            mesh       = MeshExtension.Quad();
            initialize = true;
        }

        for (int i = 0; i < renderInfos.Length; i++)
        {
            if (UpdateBuffers(i) > 0)
            {
                Graphics.DrawMeshInstancedIndirect(mesh, 0, renderInfos[i].material, new Bounds(Vector2.zero, Vector3.one), renderInfos[i].argsBuffer);
            }
        }
    }
Esempio n. 8
0
    private void DrawMeshTopology()
    {
        GUILayout.BeginHorizontal(EditorStyles.textField);
        GUILayout.Label("包含非三角形的拓扑网格");

        DrawMeshProperties("t:mesh", MeshSetting.Topology,
                           (path) =>
        {
            var mi = MeshExtension.GetModelImporter(path);

            if (mi != null)
            {
                mi.keepQuads = true;
                AssetDatabase.ImportAsset(path);
            }
            //else
            //{
            //    Debug.LogError("path: " + path);
            //}

            if (MeshExtension.GetMesh(path).GetTopology(0) != MeshTopology.Triangles)
            {
                _meshSettingPaths.Add(path);
            }
            else
            {
                if (mi != null)
                {
                    mi.keepQuads = false;
                    AssetDatabase.ImportAsset(path);
                }
            }
        }, (path) =>
        {
            _window.ShowNotification(new GUIContent("暂不提供处理逻辑"));
            MeshExtension.GetModelImporter(path).keepQuads = false;
            AssetDatabase.ImportAsset(path);
        }
                           );

        GUILayout.EndHorizontal();

        DrawMeshScrollList(MeshSetting.Topology, (path) =>
        {
            _window.ShowNotification(new GUIContent("网格拓扑类型:" + MeshExtension.GetMesh(path).GetTopology(0).ToString()));
            MeshExtension.GetModelImporter(path).keepQuads = false;
            AssetDatabase.ImportAsset(path);
        });
    }
    //Function to isolate the mesh when given a material
    Mesh IsolateMeshByMaterial(GameObject meshObject, Material material)
    {
        //Get mesh components from prefab
        Mesh         mesh     = meshObject.GetComponent <MeshFilter>().sharedMesh;
        MeshRenderer renderer = meshObject.GetComponent <MeshRenderer>();

        //This section calculates the submesh that needs to be isolated from the main mesh.
        List <int> submeshNumbers = new List <int>();

        bool hasFoundMaterial = false;

        //For every material in the mesh (every material is a submesh technically)
        for (int i = 0; i < renderer.sharedMaterials.Length; i++)
        {
            //Is the material at this index in the mesh material array
            if (material.name == renderer.sharedMaterials[i].name)
            {
                //Add submesh number to list and mark flag as true so the function does not exit
                submeshNumbers.Add(i);
                hasFoundMaterial = true;
            }
        }

        //Check if the material has been found
        if (hasFoundMaterial == false)
        {
            //If material was not found in the mesh, then return out
            return(null);
        }

        //Get the submeshes
        CombineInstance[] combine = new CombineInstance[submeshNumbers.Count];

        //Set combine submesh data
        for (int i = 0; i < submeshNumbers.Count; i++)
        {
            combine[i].mesh      = MeshExtension.GetSubMesh(mesh, submeshNumbers[i]);
            combine[i].transform = meshObject.transform.localToWorldMatrix;
        }

        //Combine the meshes
        Mesh combinedMesh = new Mesh();

        combinedMesh.CombineMeshes(combine);

        //Return the combined mesh
        return(combinedMesh);
    }
 protected override void OnCreate()
 {
     removedSubjectQuery = GetEntityQuery(ComponentType.ReadOnly <SpriteRenderSubject>(),
                                          ComponentType.ReadOnly <SpriteSheetPointer>(),
                                          ComponentType.Exclude <SpriteMatrix>());
     spriteSheetUVs          = new NativeArray <float4> [DEFAULT_SHEET_CAPACITY];
     bakedSpriteSheets       = new BakedSpriteSheet[DEFAULT_SHEET_CAPACITY];
     sheetInstanceMatrixs    = new NativeArray <float4> [DEFAULT_SHEET_CAPACITY];
     sheetInstanceColors     = new NativeArray <float4> [DEFAULT_SHEET_CAPACITY];
     sheetInstanceUVPointers = new NativeArray <int> [DEFAULT_SHEET_CAPACITY];
     freeIndexs          = new NativeList <int> [DEFAULT_SHEET_CAPACITY];
     filters             = new NativeArray <SpriteSheetPointer>(DEFAULT_SHEET_CAPACITY, Allocator.Persistent);
     BakedSpriteSheetMap = new Dictionary <string, int>(DEFAULT_SHEET_CAPACITY);
     mesh = MeshExtension.Quad();
     BufferStructureChanged = new NativeList <bool>(DEFAULT_SHEET_CAPACITY, Allocator.Persistent);
 }
Esempio n. 11
0
        public BufferStates(List <BufferSignature> signatures)
        {
            bufferSignatures_             = new List <BufferSignature>(signatures);
            materialBufferMap_.onRemove_ += (l) =>
            {
                foreach (var state in l)
                {
                    state.Dispose();
                }
            };
            mesh_ = MeshExtension.Quad();

            args = new uint[5] {
                6, 0, 0, 0, 0
            };
            argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
        }
Esempio n. 12
0
 protected override void OnCreate()
 {
     mesh = MeshExtension.Quad();
 }
 protected override void OnCreate()
 {
     mesh             = MeshExtension.Quad();
     shaderPropertyId = Shader.PropertyToID("_MainText_UV");
 }
    //Function to generate the position map.
    Texture2D GeneratePositionMap(GameObject mesh, Material material, Vector2Int textureDimensions, Vector3 textureTolerance)
    {
        //Find all gameobjects that have a mesh filter and mesh renderer as children of this gameobject
        GameObject[]      meshObjects = GetAllObjectsWithMeshAttached(mesh);
        List <GameObject> validMeshes = new List <GameObject>();

        //For every object with the mesh attached to it
        for (int i = 0; i < meshObjects.Length; i++)
        {
            //Get the submesh from the main mesh that has this material assigned
            bool isValidMesh = HasMeshGotMaterial(meshObjects[i], material);

            //Check if is valid mesh
            if (isValidMesh == false)
            {
                //If it is not, then skip this object
                continue;
            }

            //If mesh had the material, add to valid meshes array
            validMeshes.Add(meshObjects[i]);
        }

        //If the valid mesh length is 0, if no meshes had the material found
        if (validMeshes.Count == 0)
        {
            Debug.LogError("The object that was entered did not have the matching material anywhere in it's hierarchy.");
            return(null);
        }

        //Combining submeshes into mesh for calculating surface area of triangles and particle mapping
        Mesh combinedMesh = new Mesh();

        CombineInstance[] combineInstances = new CombineInstance[validMeshes.Count];

        //For every valid mesh / combine instance
        for (int i = 0; i < combineInstances.Length; i++)
        {
            //Set combine instance data
            combineInstances[i].mesh      = IsolateMeshByMaterial(validMeshes[i], material);
            combineInstances[i].transform = validMeshes[0].transform.localToWorldMatrix;
        }
        //Combine the meshes
        combinedMesh.CombineMeshes(combineInstances);

        //Null check
        if (combinedMesh == null)
        {
            return(null);
        }

        //Calculating surface area
        float totalMeshSurfaceArea = MeshExtension.SurfaceAreaOfMesh(combinedMesh);

        float[] triangleSurfaceAreas = MeshExtension.SurfaceAreaOfMeshTriangles(combinedMesh);

        //Calculating the number of pixels to dedicate the each triangle on the position map to ensure an even distribution
        int[] numberOfPixelsPerTriangle = new int[triangleSurfaceAreas.Length];
        int   textureSize     = textureDimensions.x * textureDimensions.y;
        int   addedPixelCount = 0;

        //For every triangle surface area
        for (int i = 0; i < triangleSurfaceAreas.Length; i++)
        {
            //If on last index, this is important for making sure the remainder of percentage is filled out
            if (i == triangleSurfaceAreas.Length - 1)
            {
                //Calculate the number of pixels remaining
                numberOfPixelsPerTriangle[i] = textureSize - addedPixelCount;
            }
            else
            {
                //Calculate the multiplier for the pixel count for this triangle
                float multiplierForPixelCount = triangleSurfaceAreas[i] / totalMeshSurfaceArea;
                //Calculate the number of pixels that should be assigned to this triangle
                numberOfPixelsPerTriangle[i] = Mathf.FloorToInt(multiplierForPixelCount * textureSize);
                //Add pixel count on for calculating final triangle pixel count
            }
            addedPixelCount += numberOfPixelsPerTriangle[i];
        }

        //Generating position data
        Vector3[] positions = MeshExtension.RandomPointsWithinMesh(combinedMesh, numberOfPixelsPerTriangle);

        //Randomising position map slightly
        for (int i = 0; i < positions.Length; i++)
        {
            Vector3 position = positions[i];
            //Adding randomness
            position.x += Random.Range(-textureTolerance.x, textureTolerance.x);
            position.y += Random.Range(-textureTolerance.y, textureTolerance.y);
            position.z += Random.Range(-textureTolerance.z, textureTolerance.z);

            //Reassignment
            positions[i] = position;
        }

        //Texture format
        TextureFormat format = TextureFormat.RGBAFloat;

        //Create texture and set wrap mode
        Texture2D positionMap = new Texture2D(textureDimensions.x, textureDimensions.y, format, false)
        {
            //Set texture settings
            wrapMode   = TextureWrapMode.Clamp,
            filterMode = FilterMode.Point,
            name       = mesh.name + " Position Map"
        };

        //Binding position data to the texture
        int positionCounter = 0;

        //For every pixel on the x axis
        for (int x = 0; x < textureDimensions.x; x++)
        {
            //For every pixel on the y axis
            for (int y = 0; y < textureDimensions.y; y++)
            {
                Vector3 pos;

                //Safety catch in order to prevent crash of program
                if (positionCounter >= positions.Length)
                {
                    pos = new Vector3();
                    Debug.LogError("Position Mapping Error: Position array was not long enough for number of pixels in texture dimensions.");
                }
                else
                {
                    //Get the position at the correct index
                    pos = positions[positionCounter];
                }


                //Create new colour from values with alpha of 1
                Color pixelColour = new Color(pos.x, pos.y, pos.z, 1.0f);

                //Set the pixel colour
                positionMap.SetPixel(x, y, pixelColour);
                positionCounter++;
            }
        }

        //Apply texture
        positionMap.Apply();

        //Return the texture
        return(positionMap);
    }