void addShape(Shape shape, THREE.ExtrudeGeometry.Option extrudeSettings, float x, float y, float z, float rx, float ry, float rz, float s)
    {
        //THREE.Geometry points = shape.createPointsGeometry ();
        //THREE.Geometry spacedPoints = shape.createSpacedPointsGeometry (100);
        Debug.LogWarning("TODO: CHECK use shape.createSpacedPointsGeometry");
        shape.createSpacedPointsGeometry(100);

        // flat shape

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

        THREE.Geometry    geometry;
        THREE.MeshThreeJs threeMesh;

        geometry              = new THREE.ShapeGeometry(new List <Shape> (new Shape[] { shape }), op);
        threeMesh             = new THREE.MeshThreeJs(geometry, material);
        threeMesh.position    = new Vector3(x, y, z - 125);
        threeMesh.eulerAngles = new Vector3(rx, ry, rz) * Mathf.Rad2Deg;
        scene.Add(threeMesh);


//		// 3d shape
//
//		geometry = new THREE.ExtrudeGeometry (new List<Shape> (new Shape[]{shape}), extrudeSettings);
//		threeMesh = new THREE.Mesh (geometry, material);
//		threeMesh.position = new Vector3 (x, y, z);
//		threeMesh.eulerAngles = new Vector3 (rx, ry, rz) * Mathf.Rad2Deg;
//		scene.Add (threeMesh);
    }
    void AddRenderObject(THREE.MeshThreeJs threeMesh)
    {
        UnityEngine.Mesh mesh = threeMesh.GetMesh();

        GameObject gObj = new GameObject();

        gObj.transform.SetParent(this.transform);
        gObj.transform.localPosition = threeMesh.position * 0.01f;
        gObj.transform.localScale    = Vector3.one * 0.01f;

        MeshFilter   mf = gObj.AddComponent <MeshFilter>();
        MeshRenderer mr = gObj.AddComponent <MeshRenderer>();

        mf.mesh     = mesh;
        mr.material = threeMesh.mat;
    }
    // Use this for initialization
    protected override void Init()
    {
        base.Init();

        THREE.Geometry boxGeo = new THREE.BoxGeometry(200, 200, 200, 2, 2, 2);
//		THREE.Mesh threeMesh = new THREE.Mesh( new THREE.BoxGeometry( 200, 200, 200, 2, 2, 2 ), material );
//		threeMesh.position = new Vector3( 0, 0, 0 );
//		//scene.Add( threeMesh );

        int subdivisions = 2;

        THREE.SubdivisionModifier modifier = new THREE.SubdivisionModifier(subdivisions);

        //THREE.Geometry smooth = threeMesh.geo;
        THREE.Geometry smooth = boxGeo;

        modifier.modify(smooth);


        THREE.MeshThreeJs subdivisionMesh = new THREE.MeshThreeJs(smooth, material);
        subdivisionMesh.position = new Vector3(0, 0, 0);

        scene.Add(subdivisionMesh);
    }
Exemplo n.º 4
0
    // Use this for initialization
    protected override void Init()
    {
        base.Init();

        // NURBS curve
        List <Vector4> nurbsControlPoints = new List <Vector4>();
        List <float>   nurbsKnots         = new List <float>();
        int            nurbsDegree        = 3;

        for (int i = 0; i <= nurbsDegree; i++)
        {
            nurbsKnots.Add(0);
        }

        for (int i = 0, j = 20; i < j; i++)
        {
            nurbsControlPoints.Add(
                new Vector4(
                    Random.value * 400 - 200,
                    Random.value * 400,
                    Random.value * 400 - 200,
                    1                     // weight of control point: higher means stronger attraction
                    )
                );

            float knot = (float)(i + 1) / (j - nurbsDegree);
            nurbsKnots.Add(Mathf.Clamp(knot, 0, 1));
        }

        THREE.NURBSCurve nurbsCurve    = new THREE.NURBSCurve(nurbsDegree, nurbsKnots.ToArray(), nurbsControlPoints.ToArray());
        THREE.Geometry   nurbsGeometry = new THREE.Geometry();
        List <Vector3>   pts           = nurbsCurve.getPoints(200);

        nurbsGeometry.vertices = pts;

        THREE.Line nurbsLine = new THREE.Line(nurbsGeometry, wireMaterial);
        nurbsLine.position = Vector3.zero;
        scene.Add(nurbsLine);

        // controlPoints
        THREE.Geometry nurbsControlPointsGeometry = new THREE.Geometry();
        nurbsControlPointsGeometry.vertices = new List <Vector3>(nurbsCurve.getVec3ControlPoints());

        THREE.Line nurbsControlPointsLine = new THREE.Line(nurbsControlPointsGeometry, wireMaterial);
        nurbsControlPointsLine.position = nurbsLine.position;
        scene.Add(nurbsControlPointsLine);


        // NURBS surface

        Vector4[][] nsControlPoints = new Vector4[][] {
            new Vector4[] {
                new Vector4(-200, -200, 100, 1),
                new Vector4(-200, -100, -200, 1),
                new Vector4(-200, 100, 250, 1),
                new Vector4(-200, 200, -100, 1)
            },
            new Vector4[] {
                new Vector4(0, -200, 0, 1),
                new Vector4(0, -100, -100, 5),
                new Vector4(0, 100, 150, 5),
                new Vector4(0, 200, 0, 1)
            },
            new Vector4[] {
                new Vector4(200, -200, -100, 1),
                new Vector4(200, -100, 200, 1),
                new Vector4(200, 100, -250, 1),
                new Vector4(200, 200, 100, 1)
            }
        };

        int degree1 = 2;
        int degree2 = 3;

        float[] knots1 = new float[] { 0, 0, 0, 1, 1, 1 };
        float[] knots2 = new float[] { 0, 0, 0, 0, 1, 1, 1, 1 };
        nurbsSurface = new THREE.NURBSSurface(degree1, degree2, knots1, knots2, nsControlPoints);

        THREE.ParametricGeometry geometry = new THREE.ParametricGeometry(getSurfacePoint, 20, 20);
        THREE.MeshThreeJs        mesh     = new THREE.MeshThreeJs(geometry, material);
        mesh.position = new Vector3(0, 0, 0);
        scene.Add(mesh);


        t_nsControlPoints = nsControlPoints;
    }
Exemplo n.º 5
0
    // Use this for initialization
    protected override void Init()
    {
        base.Init();

        THREE.MeshThreeJs threeMesh;

        float heightScale = 1;
        float p = 2;
        float q = 3;
        float radius = 150, tube = 10;
        int   segmentsR = 50, segmentsT = 20;


        var torus2  = new THREE.TorusKnotGeometry(radius, tube, segmentsR, segmentsT, p, q, heightScale);
        var sphere2 = new THREE.ParametricGeometries.ParaSphereGeometry(75, 20, 10).geo;

        // var torus = new THREE.TorusKnotGeometry( radius, tube, segmentsR, segmentsT, p , q, heightScale );
        // var sphere = new THREE.SphereGeometry( 75, 20, 10 );

        //var GrannyKnot =  new THREE.Curves.GrannyKnot();
        // var tube = new THREE.TubeGeometry( GrannyKnot, 150, 2, 8, true, false );


        // var benchmarkCopies = 1000;
        // var benchmarkObject = tube;
        // var rand = function() { return (Math.random() - 0.5 ) * 600; };
        // for (var b=0;b<benchmarkCopies;b++) {
        //    object = THREE.SceneUtils.createMultiMaterialObject( benchmarkObject, materials );
        //   object.position.set( rand(), rand(), rand() );
        //   scene.add( object );
        // }

        threeMesh          = new THREE.MeshThreeJs(torus2, material);
        threeMesh.position = new Vector3(0, 100, 0);
        scene.Add(threeMesh);

        THREE.Geometry geo;

        // Klein Bottle

        geo                = new THREE.ParametricGeometry(THREE.ParametricGeometries.klein, 20, 20);
        threeMesh          = new THREE.MeshThreeJs(geo, material);
        threeMesh.position = new Vector3(0, 0, 0);
        threeMesh.scale    = Vector3.one * 10;
        scene.Add(threeMesh);

        // Mobius Strip

        geo                = new THREE.ParametricGeometry(THREE.ParametricGeometries.mobius, 20, 20);
        threeMesh          = new THREE.MeshThreeJs(geo, material);
        threeMesh.position = new Vector3(10, 0, 0);
        threeMesh.scale    = Vector3.one * 100;
        scene.Add(threeMesh);

        geo = new THREE.ParametricGeometry(THREE.ParametricGeometries.plane(200, 200), 10, 20);
        //geo = new THREE.ParametricGeometry( THREE.ParametricGeometries.plane, 10, 20 );
        threeMesh          = new THREE.MeshThreeJs(geo, material);
        threeMesh.position = new Vector3(0, 0, 0);
        scene.Add(threeMesh);


//		threeMesh = new THREE.Mesh( torus2, material );
//		threeMesh.position = new Vector3( 0, 100, 0 );
//		scene.Add( threeMesh );

        threeMesh          = new THREE.MeshThreeJs(sphere2, material);
        threeMesh.position = new Vector3(200, 0, 0);
        scene.Add(threeMesh);

        // error
//		var tube2 = new THREE.ParametricGeometries.TubeGeometry( GrannyKnot, 150, 2, 8, true ).geo;
//		threeMesh = new THREE.Mesh( tube2, material );
//		threeMesh.position = new Vector3( 100, 0, 0 );
//		scene.Add( threeMesh );
    }
Exemplo n.º 6
0
    // Use this for initialization
    protected override void Init()
    {
        base.Init();

        THREE.MeshThreeJs drawNormalMesh;

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

        threeMesh          = new THREE.MeshThreeJs(new THREE.IcosahedronGeometry(75, 1), material);
        threeMesh.position = new Vector3(-200, 0, 200);
        scene.Add(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.OctahedronGeometry(75, 2), material);
        threeMesh.position = new Vector3(0, 0, 200);
        scene.Add(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.TetrahedronGeometry(75, 0), material);
        threeMesh.position = new Vector3(200, 0, 200);
        scene.Add(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.PlaneGeometry(100, 100, 4, 4), material);
        threeMesh.position = new Vector3(-400, 0, 0);
        scene.Add(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.BoxGeometry(100, 100, 100, 4, 4, 4), material);
        threeMesh.position = new Vector3(-200, 0, 0);
        scene.Add(threeMesh);

        drawNormalMesh = threeMesh;         // Draw Normal Mesh

        threeMesh          = new THREE.MeshThreeJs(new THREE.CircleGeometry(50, 20, 0, Mathf.PI * 2), material);
        threeMesh.position = new Vector3(0, 0, 0);
        scene.Add(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.RingGeometry(10, 50, 20, 5, 0, Mathf.PI * 2), material);
        threeMesh.position = new Vector3(200, 0, 0);
        scene.Add(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.CylinderGeometry(25, 75, 100, 40, 5, false), material);
        threeMesh.position = new Vector3(400, 0, 0);
        scene.Add(threeMesh);


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

        for (var i = 0; i < 50; i++)
        {
            points.Add(new Vector3(Mathf.Sin(i * 0.2f) * Mathf.Sin(i * 0.1f) * 15 + 50, 0, (i - 5) * 2));
        }

        threeMesh          = new THREE.MeshThreeJs(new THREE.LatheGeometry(points, 20), material);
        threeMesh.position = new Vector3(-400, 0, -200);
        scene.Add(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.TorusGeometry(50, 20, 20, 20), material);
        threeMesh.position = new Vector3(-200, 0, -200);
        scene.Add(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.TorusKnotGeometry(50, 10, 50, 20), material);
        threeMesh.position = new Vector3(0, 0, -200);
        scene.Add(threeMesh);

        /*
         * threeMesh = new THREE.AxisHelper( 50 );
         * threeMesh.position.set( 200, 0, -200 );
         * scene.Add( threeMesh );
         *
         * threeMesh = new THREE.ArrowHelper( new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 0 ), 50 );
         * threeMesh.position.set( 400, 0, -200 );
         * scene.Add( threeMesh );
         */

        THREE.Line lineMesh = new THREE.Line(new THREE.Geometry(), wireMaterial);
        lineMesh.position = drawNormalMesh.position;

        THREE.Geometry geo = drawNormalMesh.geo;
        for (int i = 0; i < geo.faces.Count; i++)
        {
            THREE.Face3 _face = geo.faces[i];
            int[]       tri   = _face.GetTriangles();

            for (int n = 0; n < tri.Length; n++)
            {
                Vector3           normal = _face.vertexNormals[n];
                THREE.ArrowHelper arrow  = new THREE.ArrowHelper(normal, geo.vertices[tri[n]], 10, Color.green);
                lineMesh.Add(arrow);
            }
        }

        scene.Add(lineMesh);
    }
    // Use this for initialization
    void Start()
    {
        THREE.MeshThreeJs drawNormalMesh;

        THREE.MeshThreeJs threeMesh;
        threeMesh          = new THREE.MeshThreeJs(new THREE.SphereGeometry(75, 20, 10), material);
        threeMesh.position = new Vector3(-400, 0, 200);
        AddRenderObject(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.IcosahedronGeometry(75, 1), material);
        threeMesh.position = new Vector3(-200, 0, 200);
        AddRenderObject(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.OctahedronGeometry(75, 2), material);
        threeMesh.position = new Vector3(0, 0, 200);
        AddRenderObject(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.TetrahedronGeometry(75, 0), material);
        threeMesh.position = new Vector3(200, 0, 200);
        AddRenderObject(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.PlaneGeometry(100, 100, 4, 4), material);
        threeMesh.position = new Vector3(-400, 0, 0);
        AddRenderObject(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.BoxGeometry(100, 100, 100, 4, 4, 4), material);
        threeMesh.position = new Vector3(-200, 0, 0);
        AddRenderObject(threeMesh);

        drawNormalMesh = threeMesh;         // Draw Normal Mesh

        threeMesh          = new THREE.MeshThreeJs(new THREE.CircleGeometry(50, 20, 0, Mathf.PI * 2), material);
        threeMesh.position = new Vector3(0, 0, 0);
        AddRenderObject(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.RingGeometry(10, 50, 20, 5, 0, Mathf.PI * 2), material);
        threeMesh.position = new Vector3(200, 0, 0);
        AddRenderObject(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.CylinderGeometry(25, 75, 100, 40, 5, false), material);
        threeMesh.position = new Vector3(400, 0, 0);
        AddRenderObject(threeMesh);


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

        for (var i = 0; i < 50; i++)
        {
            points.Add(new Vector3(Mathf.Sin(i * 0.2f) * Mathf.Sin(i * 0.1f) * 15 + 50, 0, (i - 5) * 2));
        }

        threeMesh          = new THREE.MeshThreeJs(new THREE.LatheGeometry(points, 20), material);
        threeMesh.position = new Vector3(-400, 0, -200);
        AddRenderObject(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.TorusGeometry(50, 20, 20, 20), material);
        threeMesh.position = new Vector3(-200, 0, -200);
        AddRenderObject(threeMesh);

        threeMesh          = new THREE.MeshThreeJs(new THREE.TorusKnotGeometry(50, 10, 50, 20), material);
        threeMesh.position = new Vector3(0, 0, -200);
        AddRenderObject(threeMesh);


//		THREE.Line lineMesh = new THREE.Line( new THREE.Geometry(), wireMaterial);
//
//		THREE.Geometry geo = drawNormalMesh.geo;
//		for(int i = 0; i < geo.faces.Count; i++){
//			THREE.Face3 _face = geo.faces[i];
//			List<int> tri = _face.GetTriangles();
//
//			for(int n = 0; n < tri.Count; n++){
//				Vector3 normal = _face.vertexNormals[n];
//				THREE.ArrowHelper arrow = new THREE.ArrowHelper(normal, geo.vertices[tri[n]] , 10, Color.green);
//				lineMesh.Add( arrow );
//			}
//		}
//
//		AddRenderObject( lineMesh.geo );
    }
Exemplo n.º 8
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 );
    }