Esempio n. 1
0
	public BackgroundWorldProcessor(bool useThreadPool) {
		if (useThreadPool) {
			int workerThreads = 0;
			int completionPortThreads = 0;
		
			ThreadPool.SetMaxThreads(400, 300);
			ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);

			UnityEngine.Debug.Log ("workerThreads = " + workerThreads + ", completionPortThreads = " + completionPortThreads);
			
			// process batches in parallel
			sharedProcessor = new ThreadPoolBatchProcessor<Chunk>();
			// the mesh processor will have its own processor which can take a data parameter
			// this will allow us to use the same mesh processor to process different meshes on different layers simultaneously
			meshProcessor = new MeshProcessor(new ThreadPoolBatchProcessor<Chunk, BlockLayer>());
		}
		else {
			// process batches synchronously
			sharedProcessor = new BatchProcessor<Chunk>();
			
			// the mesh processor will have its own processor which can take a data parameter
			// this will allow us to use the same mesh processor to process different meshes on different layers simultaneously
			meshProcessor = new MeshProcessor(new BatchProcessor<Chunk, BlockLayer>());
		}
		
		terrainProcessor = new TerrainProcessor(sharedProcessor);
		colliderProcessor = new ColliderProcessor(sharedProcessor);
	}
    public static MeshGenerator Refine(MeshGenerator mesh)
    {
        List <Vector3> newVertices = new List <Vector3>();
        List <MeshGenerator.Triangle> newTriangles = new List <MeshGenerator.Triangle>();
        int verticesCpt = 0;

        foreach (MeshGenerator.Triangle t in mesh.triangles)
        {
            Vector3 AB = (mesh.vertices[t.A] + mesh.vertices[t.B]) / 2f;
            Vector3 BC = (mesh.vertices[t.B] + mesh.vertices[t.C]) / 2f;
            Vector3 CA = (mesh.vertices[t.C] + mesh.vertices[t.A]) / 2f;

            newVertices.Add(AB);
            newVertices.Add(mesh.vertices[t.B]);
            newVertices.Add(BC);
            newVertices.Add(mesh.vertices[t.C]);
            newVertices.Add(CA);
            newVertices.Add(mesh.vertices[t.A]);

            newTriangles.Add(new MeshGenerator.Triangle(verticesCpt, verticesCpt + 1, verticesCpt + 2));
            newTriangles.Add(new MeshGenerator.Triangle(verticesCpt + 2, verticesCpt + 3, verticesCpt + 4));
            newTriangles.Add(new MeshGenerator.Triangle(verticesCpt + 4, verticesCpt + 5, verticesCpt + 0));
            newTriangles.Add(new MeshGenerator.Triangle(verticesCpt + 0, verticesCpt + 2, verticesCpt + 4));

            verticesCpt += 6;
        }

        MeshGenerator newMesh = new MeshGenerator();

        newMesh.vertices  = newVertices;
        newMesh.triangles = newTriangles;
        return(MeshProcessor.Clean(newMesh));
    }
    public void ApplyTo(ref MeshGenerator mg, MeshFilter mf)
    {
        mg.vertices  = new List <Vector3>(mf.sharedMesh.vertices);
        mg.triangles = new List <MeshGenerator.Triangle>(MeshGenerator.Triangle.FromInt(mf.sharedMesh.triangles));

        if (activeClustering && fParameter1 > 0f)
        {
            mg = MeshProcessor.VertexClustering(mg, fParameter1);
        }
        if (activeRefining && iParameter1 > 0)
        {
            mg = MeshProcessor.Refine(mg, iParameter1);
        }
    }
    void Start()
    {
        foreach (GameObject o in g)
        {
            Mesh m = o.GetComponent <MeshFilter>().mesh;

            Mesh r = MeshProcessor.processForOutlineMesh(m);

            GameObject f = new GameObject();
            f.transform.position   = o.transform.position;
            f.transform.rotation   = o.transform.rotation;
            f.transform.localScale = o.transform.localScale;
            f.name = o.name + " processed outline";

            f.AddComponent <MeshFilter>().mesh       = r;
            f.AddComponent <MeshRenderer>().material = mat;
            f.GetComponent <MeshRenderer>().material.SetFloat("_Width", 0.05f / o.transform.localScale.x);
        }
    }
Esempio n. 5
0
        public MeshNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA) : base()
        {
            Name = "Mesh";

            Id = Guid.NewGuid().ToString();

            width  = w;
            height = h;

            tileX = tileY = 1;

            meshtileX = meshtileY = 1;

            scale      = new MVector(1, 1, 1);
            rotation   = new MVector(0, 0, 0);
            position   = new MVector(0, 0, 0);
            cameraZoom = 3;

            previewProcessor = new BasicImageRenderer();
            processor        = new MeshProcessor();

            internalPixelType = p;

            inputAlbedo    = new NodeInput(NodeType.Color, this, "Albedo");
            inputHeight    = new NodeInput(NodeType.Gray, this, "Height");
            inputMetallic  = new NodeInput(NodeType.Gray, this, "Metallic");
            inputRoughness = new NodeInput(NodeType.Gray, this, "Roughness");
            inputOcclusion = new NodeInput(NodeType.Gray, this, "Occlusion");
            inputNormal    = new NodeInput(NodeType.Color, this, "Normal");
            inputThickness = new NodeInput(NodeType.Gray, this, "Thickness");

            Inputs.Add(inputAlbedo);
            Inputs.Add(inputMetallic);
            Inputs.Add(inputRoughness);
            Inputs.Add(inputNormal);
            Inputs.Add(inputHeight);
            Inputs.Add(inputOcclusion);
            Inputs.Add(inputThickness);

            Output = new NodeOutput(NodeType.Gray, this);
            Outputs.Add(Output);
        }
Esempio n. 6
0
        public MeshNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA)
        {
            Name = "Mesh";

            Id = Guid.NewGuid().ToString();

            width  = w;
            height = h;

            tileX = tileY = 1;

            meshtileX = meshtileY = 1;

            scaleZ     = scaleY = scaleX = 1;
            rotationX  = RotationY = rotationZ = 0;
            xOffset    = yOffset = zOffset = 0;
            cameraZoom = 3;

            previewProcessor = new BasicImageRenderer();
            processor        = new MeshProcessor();

            internalPixelType = p;

            Inputs = new List <NodeInput>();

            inputAlbedo    = new NodeInput(NodeType.Color, this, "Albedo");
            inputHeight    = new NodeInput(NodeType.Gray, this, "Height");
            inputMetallic  = new NodeInput(NodeType.Gray, this, "Metallic");
            inputRoughness = new NodeInput(NodeType.Gray, this, "Roughness");
            inputOcclusion = new NodeInput(NodeType.Gray, this, "Occlusion");
            inputNormal    = new NodeInput(NodeType.Color, this, "Normal");

            Inputs.Add(inputAlbedo);
            Inputs.Add(inputMetallic);
            Inputs.Add(inputRoughness);
            Inputs.Add(inputNormal);
            Inputs.Add(inputHeight);
            Inputs.Add(inputOcclusion);

            inputAlbedo.OnInputAdded   += Input_OnInputAdded;
            inputAlbedo.OnInputChanged += Input_OnInputChanged;
            inputAlbedo.OnInputRemoved += Input_OnInputRemoved;

            inputNormal.OnInputAdded   += Input_OnInputAdded;
            inputNormal.OnInputChanged += Input_OnInputChanged;
            inputNormal.OnInputRemoved += Input_OnInputRemoved;

            inputOcclusion.OnInputAdded   += Input_OnInputAdded;
            inputOcclusion.OnInputChanged += Input_OnInputChanged;
            inputOcclusion.OnInputRemoved += Input_OnInputRemoved;

            inputRoughness.OnInputAdded   += Input_OnInputAdded;
            inputRoughness.OnInputChanged += Input_OnInputChanged;
            inputRoughness.OnInputRemoved += Input_OnInputRemoved;

            inputMetallic.OnInputAdded   += Input_OnInputAdded;
            inputMetallic.OnInputChanged += Input_OnInputChanged;
            inputMetallic.OnInputRemoved += Input_OnInputRemoved;

            inputHeight.OnInputAdded   += Input_OnInputAdded;
            inputHeight.OnInputChanged += Input_OnInputChanged;
            inputHeight.OnInputRemoved += Input_OnInputRemoved;

            Output = new NodeOutput(NodeType.Gray, this);

            Outputs = new List <NodeOutput>();
            Outputs.Add(Output);

            HdriManager.OnHdriLoaded += HdriManager_OnHdriLoaded;
        }