Ejemplo n.º 1
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;
    }
Ejemplo n.º 2
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 );
    }