Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        THREE.Geometry geometry;

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

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

        AddRenderObject(new THREE.OctahedronGeometry(75, 2), material, new Vector3(0, 0, 200));

        AddRenderObject(new THREE.TetrahedronGeometry(75, 0), material, new Vector3(200, 0, 200));

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

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

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

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

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

        //
        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));
        }
        AddRenderObject(new THREE.LatheGeometry(points, 20), material, new Vector3(-400, 0, -200));

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

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


        THREE.Line     lineMesh = new THREE.Line(new THREE.Geometry(), wireMaterial);
        THREE.Geometry geo      = geometry;
        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);
            }
        }

        AddRenderLineObject(lineMesh.geo, wireMaterial, new Vector3(-200, 0, 0));
    }
Exemplo n.º 2
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.º 3
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);
    }