示例#1
0
        private static Line CreateHilbertCube(Renderer renderer, Scene scene)
        {
            var points         = Mathf.Hilbert3D(Vector3.Zero, 0.25f, 2);
            var spline         = new SplineCurve3(points);
            var geometrySpline = new Geometry();

            geometrySpline.vertexColors = new List <Color>();
            var subdivisions = 6;
            var count        = points.Count * subdivisions;

            for (var i = 0; i < count; i++)
            {
                var index    = i / (float)(points.Count * subdivisions);
                var position = spline.InterpolatedPoint(index);
                geometrySpline.vertices.Add(position);

                var hsl = Color.FromHSV(index, 1, 1);
                geometrySpline.vertexColors.Add(hsl);
            }

            var lines = new Line(geometrySpline, new LineDashedMaterial(renderer)
            {
                //DiffuseColor = Color.Cornflowerblue,
                VertexColors = VertexColorMode.Vertex,
                LineWidth    = 0.01f,
                DashSize     = 0.006f,
                GapSize      = 0.002f,
            });

            return(lines);
        }
示例#2
0
    public void Setup(Color _color, STYLE _style = STYLE.NONE, List <Vector3> trajectory = null, string wellname = null, Material _material = null, Material _shadowMaterial = null)
    {
        List <Vector3> points = new List <Vector3>();

        points = new List <Vector3>(trajectory);

        style = _style;

        // Set materials supplied else use default else crash
        if (_material != null)
        {
            mainMaterial = _material;
        }
        if (_shadowMaterial != null)
        {
            shadowMaterial = _material;
        }

        // Always clone the main material so we can modify it without affecting other swatches
        mainMaterial       = Object.Instantiate(mainMaterial) as Material;
        mainMaterial.color = _color;

        // Basic mesh
        if (true)
        {
            main      = gameObject;
            main.name = wellname;
            totalCount++;
            //gameObject.GetComponent<Renderer>().material = mainMaterial;
            GetComponent <Renderer>().material = new Material(Shader.Find("Diffuse"));
            MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();
            mainMesh = meshFilter.mesh = new Mesh();
        }



        // points.Add(new Vector3(-1000, 0, 0));
        // for (int i = 0; i < 10; i++)
        //  {
        //  points.Add(new Vector3(Random.Range(-1000, 1000), Random.Range(-1000, 1000), Random.Range(-1000, 1000)));


        // }
        // points.Add(new Vector3(1000, 0, 0));

        var path = new SplineCurve3(points);

        TubeGeometry(path, 500, 100, 6);
    }
示例#3
0
    public void Setup(Color _color, STYLE _style = STYLE.NONE, Material _material = null, Material _shadowMaterial = null)
    {
        style = _style;

        // Set materials supplied else use default else crash
        if (_material != null)
        {
            mainMaterial = _material;
        }
        if (_shadowMaterial != null)
        {
            shadowMaterial = _material;
        }

        // Always clone the main material so we can modify it without affecting other swatches
        mainMaterial       = Object.Instantiate(mainMaterial) as Material;
        mainMaterial.color = _color;

        // Basic mesh
        if (true)
        {
            main      = gameObject;
            main.name = "Draw" + totalCount; totalCount++;
            //gameObject.GetComponent<Renderer>().material = mainMaterial;
            GetComponent <Renderer>().material = new Material(Shader.Find("Diffuse"));
            MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();
            mainMesh = meshFilter.mesh = new Mesh();
        }

        List <Vector3> points = new List <Vector3>();

        points.Add(new Vector3(-1000, 0, 0));
        for (int i = 0; i < 10; i++)
        {
            points.Add(new Vector3(Random.Range(-1000, 1000), Random.Range(-1000, 1000), Random.Range(-1000, 1000)));
        }
        points.Add(new Vector3(1000, 0, 0));

// - rather than doing the above - add the points incrementally if they are far away from previous points over a threshhold
// - i guess i can re-run peuker over the whole thing - it seems deterministic
// - then remake the entire spline
// - and remake the entire tube i guess

        var path = new SplineCurve3(points);

        TubeGeometry(path, 500, 100, 6);
    }
    // Use this for initialization
    void Start()
    {
        List <Vector3> vertices = new List <Vector3>();
        List <Vector3> normals  = new List <Vector3>();
        List <Vector2> uvs      = new List <Vector2>();

        float meshSmooth = 60;

        THREE.Geometry testGeometry;

        THREE.ClosedSplineCurve3 closedSpline = new THREE.ClosedSplineCurve3(new List <Vector3>(new Vector3[] {
            new Vector3(-60, -100, 60),
            new Vector3(-60, 20, 60),
            new Vector3(-60, 120, 60),
            new Vector3(60, 20, -60),
            new Vector3(60, -100, -60)
        }));

        THREE.ExtrudeGeometry.Option extrudeSettings = new THREE.ExtrudeGeometry.Option();
        extrudeSettings.steps        = 100;
        extrudeSettings.bevelEnabled = false;
        extrudeSettings.extrudePath  = closedSpline;

        List <Vector2> pts   = new List <Vector2>();
        int            count = 3;

        for (int i = 0; i < count; i++)
        {
            float l = 20;
            float a = 2 * (float)i / count * Mathf.PI;
            pts.Add(new Vector2(Mathf.Cos(a) * l, Mathf.Sin(a) * l));
        }

        THREE.Shape shape = new THREE.Shape(pts);

        testGeometry = new THREE.ExtrudeGeometry(new List <THREE.Shape>(new THREE.Shape[] { shape }), extrudeSettings);
        //testGeometry.computeVertexNormals();

        UnityEngine.Mesh mesh0 = testGeometry.GetMesh(meshSmooth);
        vertices.AddRange(mesh0.vertices);
        normals.AddRange(mesh0.normals);
        uvs.AddRange(mesh0.uv);

        //
        List <Vector3> randomPoints = new List <Vector3>();

        for (int i = 0; i < 10; i++)
        {
            randomPoints.Add(new Vector3((i - 4.5f) * 50, Random.Range(-50.0f, 50.0f), Random.Range(-50.0f, 50.0f)));
        }

        SplineCurve3 randomSpline = new SplineCurve3(randomPoints);

        THREE.ExtrudeGeometry.Option extrude0Settings = new THREE.ExtrudeGeometry.Option();
        extrude0Settings.steps        = 200;
        extrude0Settings.bevelEnabled = false;
        extrude0Settings.extrudePath  = randomSpline;


        List <Vector2> pts0   = new List <Vector2>();
        int            numPts = 5;

        for (int i = 0; i < numPts * 2; i++)
        {
            int   l = i % 2 == 1 ? 10 : 20;
            float a = (float)i / numPts * Mathf.PI;
            pts0.Add(new Vector2(Mathf.Cos(a) * l, Mathf.Sin(a) * l));
        }

        Shape shape0 = new Shape(pts0);

        testGeometry = new THREE.ExtrudeGeometry(new List <Shape>(new Shape[] { shape0 }), extrude0Settings);

        UnityEngine.Mesh mesh1 = testGeometry.GetMesh(meshSmooth);
        vertices.AddRange(mesh1.vertices);
        normals.AddRange(mesh1.normals);
        uvs.AddRange(mesh1.uv);

//		//
        THREE.ExtrudeGeometry.Option extrude1Settings = new THREE.ExtrudeGeometry.Option();
        extrude1Settings.amount         = 20;
        extrude1Settings.steps          = 1;
        extrude1Settings.bevelEnabled   = false;
        extrude1Settings.bevelThickness = 2;
        extrude1Settings.bevelSize      = 4;
        extrude1Settings.bevelSegments  = 1;

        testGeometry = new THREE.ExtrudeGeometry(new List <Shape>(new Shape[] { shape0 }), extrude1Settings);

        UnityEngine.Mesh mesh2 = testGeometry.GetMesh(meshSmooth);
        vertices.AddRange(mesh2.vertices);
        normals.AddRange(mesh2.normals);
        uvs.AddRange(mesh2.uv);


        // unity submesh
        MeshRenderer mr = this.gameObject.AddComponent <MeshRenderer>();
        MeshFilter   mf = this.gameObject.AddComponent <MeshFilter>();

        UnityEngine.Mesh mesh = new UnityEngine.Mesh();

        mesh.vertices = vertices.ToArray();
        mesh.normals  = normals.ToArray();
        mesh.uv       = uvs.ToArray();

        mesh.subMeshCount = 3;

        mesh.SetTriangles(mesh0.triangles, 0);

        int offsetIndex1 = mesh0.vertexCount;

        int[] orgTris = mesh1.triangles;
        int[] tris    = new int[orgTris.Length];
        for (int j = 0; j < tris.Length; j++)
        {
            tris[j] = orgTris[j] + offsetIndex1;
        }
        mesh.SetTriangles(tris, 1);

        int offsetIndex2 = offsetIndex1 + mesh1.vertexCount;

        int[] orgTris2 = mesh2.triangles;
        int[] tris2    = new int[orgTris2.Length];
        for (int j = 0; j < tris2.Length; j++)
        {
            tris2[j] = orgTris2[j] + offsetIndex2;
        }
        mesh.SetTriangles(tris2, 2);

        //mesh.RecalculateNormals();

        mf.mesh      = mesh;
        mr.materials = materials;
    }
示例#5
0
    // Use this for initialization
    protected override void Init()
    {
        base.Init();

        closedSpline = new THREE.ClosedSplineCurve3(new List <Vector3>(new Vector3[] {
            new Vector3(-60, -100, 60),
            new Vector3(-60, 20, 60),
            new Vector3(-60, 120, 60),
            new Vector3(60, 20, -60),
            new Vector3(60, -100, -60)
        }));

        THREE.ExtrudeGeometry.Option extrudeSettings = new THREE.ExtrudeGeometry.Option();
        extrudeSettings.steps        = 100;
        extrudeSettings.bevelEnabled = false;
        extrudeSettings.extrudePath  = closedSpline;

        pts = new List <Vector2>();
        int count = 3;

        for (int i = 0; i < count; i++)
        {
            float l = 20;
            float a = 2 * (float)i / count * Mathf.PI;
            pts.Add(new Vector2(Mathf.Cos(a) * l, Mathf.Sin(a) * l));
        }

        THREE.Shape shape = new THREE.Shape(pts);


        THREE.MeshThreeJs threeMesh;

        testGeometry = new THREE.ExtrudeGeometry(new List <THREE.Shape>(new THREE.Shape[] { shape }), extrudeSettings);
        //THREE.ShapeGeometry.Option op0 = new THREE.ShapeGeometry.Option();
        //op0.curveSegments = 12;
        //THREE.Geometry geometry = new THREE.ShapeGeometry(new List<Shape>( new Shape[]{shape} ), op0);
        threeMesh = new THREE.MeshThreeJs(testGeometry, material);
        scene.Add(threeMesh);

        /////
        List <Vector3> randomPoints = new List <Vector3>();

        for (int i = 0; i < 10; i++)
        {
            randomPoints.Add(new Vector3((i - 4.5f) * 50, Random.Range(-50.0f, 50.0f), Random.Range(-50.0f, 50.0f)));
        }

        SplineCurve3 randomSpline = new SplineCurve3(randomPoints);

        THREE.ExtrudeGeometry.Option extrude0Settings = new THREE.ExtrudeGeometry.Option();
        extrude0Settings.steps        = 200;
        extrude0Settings.bevelEnabled = false;
        extrude0Settings.extrudePath  = randomSpline;


//		List<Vector2> pts0 = new List<Vector2>();
//		int numPts = 5;
//
//		for ( int i = 0; i < numPts * 2; i ++ ) {
//			int l = i % 2 == 1 ? 10 : 20;
//			float a = (float)i / numPts * Mathf.PI;
//			pts0.Add( new Vector2 ( Mathf.Cos( a ) * l, Mathf.Sin( a ) * l ) );
//		}
//
//		Shape shape0 = new Shape( pts0 );


        // star path
        List <Vector2> pts0     = new List <Vector2>();
        List <Vector2> normals0 = new List <Vector2>();
        int            numPts   = 5;

        for (int i = 0; i < numPts * 2; i++)
        {
            int   l = i % 2 == 1 ? 10 : 20;
            float a = (float)i / numPts * Mathf.PI;
            pts0.Add(new Vector2(Mathf.Cos(a) * l, Mathf.Sin(a) * l));
        }
        for (int i = 0; i < pts0.Count; i++)
        {
            int     endI = (i == pts0.Count - 1) ? 0 : i + 1;
            Vector2 vec  = pts0[endI] - pts0[i];
            vec.Normalize();
            normals0.Add(new Vector2(vec.y, -vec.x));
        }

        THREE.Shape shape0 = new Shape(pts0, normals0);

        testGeometry = new THREE.ExtrudeGeometry(new List <Shape>(new Shape[] { shape0 }), extrude0Settings);
        threeMesh    = new THREE.MeshThreeJs(testGeometry, material);
        scene.Add(threeMesh);

        ////////////
        THREE.ExtrudeGeometry.Option extrude1Settings = new THREE.ExtrudeGeometry.Option();
        extrude1Settings.amount         = 20;
        extrude1Settings.steps          = 1;
        extrude1Settings.bevelEnabled   = false;
        extrude1Settings.bevelThickness = 2;
        extrude1Settings.bevelSize      = 4;
        extrude1Settings.bevelSegments  = 1;

        testGeometry       = new THREE.ExtrudeGeometry(new List <Shape>(new Shape[] { shape0 }), extrude1Settings);
        threeMesh          = new THREE.MeshThreeJs(testGeometry, material);
        threeMesh.position = new Vector3(50, 100, 50);
        scene.Add(threeMesh);

        //
        // Sphere
//		threeMesh = new THREE.Mesh( new THREE.SphereGeometry( 75, 20, 10 ), material );
//		threeMesh.position = new Vector3( -400, 0, 200 );
//		scene.Add( threeMesh );

//		//
//		Shape shapeTri = new Shape();
//		shapeTri.moveTo(  0, 100 );
//		shapeTri.lineTo(  100, -50 );
//		shapeTri.lineTo( -100, -50 );
//		shapeTri.lineTo(  0, 100 );
//
//		THREE.ShapeGeometry.Option op = new THREE.ShapeGeometry.Option();
//		op.curveSegments = 12;
//		THREE.Geometry geometryShape = new THREE.ShapeGeometry(new List<Shape>( new Shape[]{shapeTri} ), op);
//		threeMesh = new THREE.Mesh( geometryShape, material);
//		scene.Add( threeMesh );
    }