Example #1
0
    // Use this for initialization
    void Start()
    {
        THREE.Geometry testGeometry;

        // ---------------
        // closed path
        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.SplineCurve3 closedSpline = new THREE.SplineCurve3( new List<Vector3>(new Vector3[]{
//			new Vector3( 0, 0, 0 ),
//			new Vector3( 150, 0, 0 ),
//			new Vector3( 0, 150, 0 ),
//		}));

        extrudeSettings               = new THREE.ExtrudeGeometry.Option();
        extrudeSettings.steps         = 30; // 30, 100
        extrudeSettings.bevelEnabled  = false;
        extrudeSettings.extrudePath   = closedSpline;
        extrudeSettings.curveSegments = 4;

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

        float normOffset = Mathf.PI / count;

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

            normals.Add(new Vector2(Mathf.Cos(a + normOffset), Mathf.Sin(a + normOffset)));
        }

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

        THREE.ShapeGeometry.Option op = new THREE.ShapeGeometry.Option();
        op.curveSegments = 12;

        // test
        THREE.Geometry shapeGeo;
        shapeGeo = new THREE.ShapeGeometry(shape, op);
        AddRenderObject(shapeGeo, materials[0], Vector3.zero);

//		// Fish
//		THREE.Shape fishShape = new THREE.Shape ();
//		fishShape.moveTo (0, 0);
//		fishShape.quadraticCurveTo (50, 80, 90, 10);
//		fishShape.quadraticCurveTo (100, 10, 115, 40);
//		fishShape.quadraticCurveTo (115, 0, 115, 40);
//		fishShape.quadraticCurveTo (100, 10, 90, 10);
//		fishShape.quadraticCurveTo (50, 80, 0, 0);


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

        //THREE.ShapeGeometry.Option op0 = new THREE.ShapeGeometry.Option();
        //op0.curveSegments = 12;
        //THREE.Geometry geometry = new THREE.ShapeGeometry(new List<Shape>( new Shape[]{shape} ), op0);

        AddRenderObject(testGeometry, materials[0], Vector3.zero);


        // random path
        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 ) ) );
            randomPoints.Add(new Vector3((i) * 50, Random.Range(-50.0f, 50.0f), Random.Range(-50.0f, 50.0f)));
            //randomPoints.Add( new Vector3( i * 50, i, i*2 ) );
        }
//		for ( int i = 0; i < 3; i ++ ) {
//			randomPoints.Add( new Vector3( 0, i * 30, i * 40 ) );
//		}
        randomSpline = new SplineCurve3(randomPoints);

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

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

//		normOffset = Mathf.PI / numPts + Mathf.PI / 2.0f;
//		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 ) );
//
//			normals0.Add( new Vector2 ( Mathf.Cos( a + normOffset ), Mathf.Sin( a + normOffset ) ) );
//		}

        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));
        }

        Shape startShape = new Shape(pts0, normals0);

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

        AddRenderObject(testGeometry, materials[1], Vector3.zero);


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

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

        AddRenderObject(testGeometry, materials[2], new Vector3(50, 100, 50), 0.0f);

        // test
        THREE.Geometry startShapeGeo;
        startShapeGeo = new THREE.ShapeGeometry(startShape, op);
        AddRenderObject(startShapeGeo, materials[0], Vector3.zero);
    }
    // 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;
    }
Example #3
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 );
    }