Beispiel #1
0
        IEnumerator GenerateSolidTexture()
        {
            int i = 0;

            foreach (var tex in _generator.Generate(SideSize, SlicesPerDispatch, TextureInside))
            {
                Debug.Log("Loop " + i);
                i++;

                if (!tex.Done)
                {
                    yield return(new WaitForSeconds(CooldownTime));

                    GetComponent <MeshRenderer>().material.SetTexture("_SolidTex", tex.SolidTexture);
                }
                else
                {
                    if (CreateAsset)
                    {
                        var transformer = new RenderCubeToTexture3DTransformer(_unityThreadComputeShaderExecutorObject);
                        var tex3D       = transformer.Transform(tex.SolidTexture, SideSize, SideSize);
                        GetComponent <MeshRenderer>().material.SetTexture("_SolidTex", tex3D);
                        MyAssetDatabase.CreateAndSaveAsset(tex3D, Path);
                    }
                }
            }
        }
Beispiel #2
0
        public static void CreateAndSave(UnaliasedMesh mesh, string path, int radius = 5, bool useKring = true)
        {
            MeshCurvatureDetailGenerator detailGenerator = new MeshCurvatureDetailGenerator();
            var detail = detailGenerator.Generate(mesh, radius, useKring);

            MyAssetDatabase.CreateAndSaveAsset(detail, path);
        }
Beispiel #3
0
        public void Start0()
        {
            var tonesCount  = 5;
            var levelsCount = 5;

            TaskUtils.SetGlobalMultithreading(false);
            var tones = TAMTone.CreateList(tonesCount, new Dictionary <int, TAMStrokeOrientation>()
            {
                { 0, TAMStrokeOrientation.Horizontal },
                { 3, TAMStrokeOrientation.Vertical },
                { 5, TAMStrokeOrientation.Both }
            });
            var levels = TAMMipmapLevel.CreateList(levelsCount);

            var fileManager    = new TAMPackFileManager();
            var soleImagesPack = fileManager.Load(@"C:\mgr\tmp\tam1\", tones, levels);

            var generator  = new TAMArrayGenerator();
            var tex2DArray = generator.Generate(soleImagesPack, tones, levels);

            var go       = GameObject.CreatePrimitive(PrimitiveType.Plane);
            var material = new Material(Shader.Find("Custom/Debug/TextureArrayLod"));

            material.SetTexture("_MainTex", tex2DArray);
            go.GetComponent <MeshRenderer>().material = material;
            MyAssetDatabase.CreateAndSaveAsset(tex2DArray, "Assets/Generated/TAM1.asset");
        }
Beispiel #4
0
        public void Start()
        {
            var mesh = TorusGenerator.GenerateTorus(Radius1, Radius2, RadSeg, Sides);
            var go   = GameObject.CreatePrimitive(PrimitiveType.Cube);

            go.GetComponent <MeshFilter>().mesh = mesh;
            if (WriteToFile)
            {
                MyAssetDatabase.CreateAndSaveAsset(mesh, Path);
            }
        }
Beispiel #5
0
        public ComputeBuffer CreateAndSave(string path, Mesh mesh, Dictionary <MyShaderBufferType, ComputeBuffer> createdBuffers)
        {
            var generator = new NPRAdjacencyBufferGenerator();
            var detail    = generator.GenerateTriangleAdjacencyBuffer(mesh);
            var buffer    = ScriptableObject.CreateInstance <ShaderBufferSE>();

            buffer.Data = detail.SelectMany(c => c.ToArray()).ToArray();
            MyAssetDatabase.CreateAndSaveAsset(buffer, path);

            var computeBuffer = new ComputeBuffer(detail.Length, sizeof(float) * 3);

            computeBuffer.SetData(buffer.Data);
            return(computeBuffer);
        }
Beispiel #6
0
        public void Start()
        {
            Debug.Log(OriginalMesh.normals.Select(c => c.ToString()).Aggregate((a, b) => a + " " + b));
            Debug.Log(OriginalMesh.vertices.Select(c => c.ToString()).Aggregate((a, b) => a + " " + b));

            var newUvArray = new Vector2[OriginalMesh.uv.Length];

            for (var i = 0; i < OriginalMesh.vertexCount; i++)
            {
                var vertexPosition = OriginalMesh.vertices[i];
                var normal         = OriginalMesh.normals[i];
                var EPSILON        = 0.0001f;

                if ((normal - Vector3.up).magnitude < EPSILON)
                {
                    newUvArray[i] = PlaceOnGrid(0, 3, GenerateUvOn2DSpace(new Vector2(vertexPosition.x, vertexPosition.z)));
                }
                else if ((normal - Vector3.down).magnitude < EPSILON)
                {
                    newUvArray[i] = PlaceOnGrid(1, 3, GenerateUvOn2DSpace(new Vector2(vertexPosition.x, vertexPosition.z)));
                }
                else if ((normal - Vector3.left).magnitude < EPSILON)
                {
                    newUvArray[i] = PlaceOnGrid(2, 3, GenerateUvOn2DSpace(new Vector2(vertexPosition.y, vertexPosition.z)));
                }
                else if ((normal - Vector3.right).magnitude < EPSILON)
                {
                    newUvArray[i] = PlaceOnGrid(3, 3, GenerateUvOn2DSpace(new Vector2(vertexPosition.y, vertexPosition.z)));
                }
                else if ((normal - Vector3.back).magnitude < EPSILON)
                {
                    newUvArray[i] = PlaceOnGrid(4, 3, GenerateUvOn2DSpace(new Vector2(vertexPosition.x, vertexPosition.y)));
                }

                if ((normal - Vector3.forward).magnitude < EPSILON)
                {
                    newUvArray[i] = PlaceOnGrid(5, 3, GenerateUvOn2DSpace(new Vector2(vertexPosition.x, vertexPosition.y)));
                }
            }

            var newMesh = new Mesh {
                vertices = OriginalMesh.vertices, triangles = OriginalMesh.triangles, tangents = OriginalMesh.tangents, uv = newUvArray, normals = OriginalMesh.normals
            };

            newMesh.RecalculateBounds();

            MyAssetDatabase.CreateAndSaveAsset(newMesh, $"Assets/NPRResources/{NewMeshName}.asset");
        }
        public ComputeBuffer CreateAndSave(string path, Mesh mesh, Dictionary <MyShaderBufferType, ComputeBuffer> createdBuffers)
        {
            var generator = new NPRPrincipalCurvatureBufferGenerator();

            var array = generator.Generate(mesh);

            var buffer = ScriptableObject.CreateInstance <ShaderBufferSE>();

            buffer.Data = array;
            MyAssetDatabase.CreateAndSaveAsset(buffer, path);

            var computeBuffer = new ComputeBuffer(array.Length / 8, sizeof(float) * 8);

            computeBuffer.SetData(buffer.Data);
            return(computeBuffer);
        }
Beispiel #8
0
        public ComputeBuffer CreateAndSave(string path, Mesh mesh, Dictionary <MyShaderBufferType, ComputeBuffer> createdBuffers)
        {
            var bufferGenerator = new EdgeAngleBufferGenerator(_shaderExecutorObject);

            var dataArray = bufferGenerator.Generate(mesh, createdBuffers[MyShaderBufferType.Adjacency]).Result;

            var buffer = ScriptableObject.CreateInstance <ShaderBufferSE>();

            buffer.Data = dataArray;
            MyAssetDatabase.CreateAndSaveAsset(buffer, path);

            var computeBuffer = new ComputeBuffer(dataArray.Length / 1, sizeof(float) * 1);

            computeBuffer.SetData(buffer.Data);
            return(computeBuffer);
        }
        public ComputeBuffer CreateAndSave(string path, Mesh mesh, Dictionary <MyShaderBufferType, ComputeBuffer> createdBuffers)
        {
            var generator = new NPRInterpolatedNormalsBufferGenerator();

            var array = generator.Generate(mesh);

            var buffer = ScriptableObject.CreateInstance <ShaderBufferSE>();

            buffer.Data = array.SelectMany(c => c.ToArray()).ToArray();
            MyAssetDatabase.CreateAndSaveAsset(buffer, path);

            var floatsPerVertex = (3);
            var computeBuffer   = new ComputeBuffer(array.Length, sizeof(float) * floatsPerVertex);

            computeBuffer.SetData(buffer.Data);
            return(computeBuffer);
        }
Beispiel #10
0
        public void Start()
        {
            var sw = new MyStopWatch();

            sw.StartSegment("TamIdGeneration");
            TaskUtils.SetGlobalMultithreading(false);
            var tonesCount  = 5;
            var levelsCount = 5;
            var layersCount = 1;

            var tamTones = TAMTone.CreateList(tonesCount, new Dictionary <int, TAMStrokeOrientation>()
            {
                { 0, TAMStrokeOrientation.Horizontal },
                { 3, TAMStrokeOrientation.Vertical },
                { 5, TAMStrokeOrientation.Both }
            });
            var tamMipmapLevels = TAMMipmapLevel.CreateList(levelsCount);

            var configuration = TamIdPackGenerationConfiguration
                                .GetDefaultTamIdConfiguration(tamTones, tamMipmapLevels, ExclusionZoneMultiplier, layersCount, StrokeImagePath, BlankImagePath);

            ScaleStrokesGenerationConfiguration(configuration);
            configuration.UseSmoothAlpha = SmoothAlpha;

            var packGenerator = new TamIdPackGenerator();
            var pack          = packGenerator.GenerateTamPack(configuration, false, FindObjectOfType <ComputeShaderContainerGameObject>());

            DrawDebugPlates(pack);
            var fileManager = new TamIdPackFileManager();

            Debug.Log("Sw: " + sw.CollectResults());

            if (SaveToFile)
            {
                fileManager.Save(TemporaryImagesPath, tamTones, tamMipmapLevels, layersCount, pack);
                var generator  = new TamIdArrayGenerator();
                var tex2DArray = generator.Generate(pack, tamTones, tamMipmapLevels, layersCount);
                tex2DArray.wrapMode = TextureWrapMode.Repeat;
                if (SmoothAlpha)
                {
                    tex2DArray.filterMode = FilterMode.Trilinear;
                }
                MyAssetDatabase.CreateAndSaveAsset(tex2DArray, $"Assets/Generated/{AssetName}.asset");
            }
        }
Beispiel #11
0
        public ComputeBuffer CreateAndSave(string path, Mesh mesh, Dictionary <MyShaderBufferType, ComputeBuffer> createdBuffers)
        {
            var bufferGenerator = new BarycentricCoordinatesBufferGenerator(
                "npr_barycentricBufferGenerator_comp",
                new UnityThreadComputeShaderExecutorObject());

            var barycentricDataArray = bufferGenerator.Generate(mesh).Result;

            var buffer = ScriptableObject.CreateInstance <ShaderBufferSE>();

            buffer.Data = barycentricDataArray;
            MyAssetDatabase.CreateAndSaveAsset(buffer, path);

            var computeBuffer = new ComputeBuffer(barycentricDataArray.Length / 2, sizeof(float) * 2);

            computeBuffer.SetData(buffer.Data);
            return(computeBuffer);
        }
        public void Start3()
        {
            var length = 50;

            float[,] heightArray = new float[length, length];
            for (int x = 0; x < length; x++)
            {
                for (int y = 0; y < length; y++)
                {
                    var ax = x / (float)length * 2 * Mathf.PI;
                    var ay = y / (float)length * 2 * Mathf.PI;

                    heightArray[x, y] = Mathf.Sin(ax) / 10;
                }
            }
            var mesh = PlaneGenerator.CreatePlaneMesh(1, 1, heightArray);

            MyAssetDatabase.CreateAndSaveAsset(mesh, "Assets/NPRResources/SimpleMesh1.asset");
        }
Beispiel #13
0
        public void Start()
        {
            TaskUtils.SetGlobalMultithreading(false);
            var generator     = new UniqueVertexArrayBufferGenerator("npr_uniqueVertexGenerator_comp", new UnityThreadComputeShaderExecutorObject());
            var mesh          = GetComponent <MeshFilter>().mesh;
            var verticesArray = generator.Generate(mesh).Result;

            var newMesh = new Mesh();

            newMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
            newMesh.vertices    = Enumerable.Range(0, mesh.triangles.Length)
                                  .Select(c => new Vector3(verticesArray[c * 3 + 0], verticesArray[c * 3 + 1], verticesArray[c * 3 + 2])).ToArray();

            newMesh.triangles = Enumerable.Range(0, mesh.triangles.Length).ToArray();
            newMesh.RecalculateNormals();
            newMesh.RecalculateTangents();
            newMesh.RecalculateBounds();

            MyAssetDatabase.CreateAndSaveAsset(newMesh, TargetPath);
            //GetComponent<MeshFilter>().mesh = newMesh;
            //Debug.Log("Created asset at "+TargetPath);
        }
        private ShaderBufferSE RetriveShaderBuffer(MyShaderBufferType type)
        {
            ShaderBufferSE shaderBuffer = null;

            var bufferAssetName = $"{BaseName}.{type.Details().BufferFileSuffix}";

            if (Application.isEditor)
            {
                var path = $"Assets/NPRResources/BuffersCache/{bufferAssetName}.asset";
                shaderBuffer = MyAssetDatabase.LoadAssetAtPath <ShaderBufferSE>(path);
                Preconditions.Assert(shaderBuffer != null, $"Cannot find buffer of path " + path);
            }
            else
            {
                var listing = FindObjectOfType <MyBufferCacheAssetListingGO>();
                Preconditions.Assert(listing != null, "Cannot find object of type MyBufferCacheAssetListingGO");
                shaderBuffer = listing.RetriveAssetOfName(bufferAssetName) as ShaderBufferSE;
                Preconditions.Assert(shaderBuffer != null, $"Cannot find buffer of  name " + bufferAssetName);
            }

            return(shaderBuffer);
        }
 void Start()
 {
     instance = this;
 }
        public void Start()
        {
            var newMesh = CombineMeshes(Mesh1, Mesh2);

            MyAssetDatabase.CreateAndSaveAsset(newMesh, OutPath);
        }