Esempio n. 1
0
    private void ConformToBBox(BoundingBox bbox)
    {
        //transform.position = bbox.position;
        transform.localPosition = bbox.vertices[0];
        if (bbox.vects[2].magnitude > 0)
        {
            //transform.LookAt(bbox.vertices[3]);
            transform.LookAt(bbox.vertices[0] + bbox.vects[2]);
        }
        else
        {
            Vector3 n = Vector3.Cross(bbox.vects[0].normalized, bbox.vects[1].normalized);
            transform.LookAt(bbox.vertices[0] + n);
        }
        Vector3 signedSize = bbox.GetSignedSize();

        for (int i = 0; i < 3; i++)
        {
            if (signedSize[i] == 0)
            {
                signedSize[i] = 1;
            }
        }
        transform.localScale = signedSize;

        Mesh mesh = meshable.GetNormalizedMesh(bbox);

        meshable.bbox = bbox;
        GetComponent <MeshFilter>().mesh = mesh;
    }
Esempio n. 2
0
    public void SetMeshable(Meshable imeshable, Vector3?direction = null)
    {
        meshable = imeshable;
        Vector3 vectu;

        if (direction.HasValue)
        {
            vectu = direction.Value;
        }
        else
        {
            vectu = new Vector3(1, 0, 0);
        }
        BoundingBox bbox = meshable.GetBoundingBox(vectu);



        transform.position = bbox.vertices[0];
        transform.LookAt(bbox.vertices[3]);
        Size = bbox.size;

        Mesh mesh = meshable.GetNormalizedMesh(bbox);

        GetComponent <MeshFilter>().mesh = mesh;
        print("mesh.verticeCount=" + mesh.vertexCount.ToString());
    }