示例#1
0
    public override Tes.Maths.Vector3[] Normals(int stream = 0)
    {
        if (CachedNormals == null && UnityMesh.normals != null)
        {
            CachedNormals = new Tes.Maths.Vector3[UnityMesh.vertexCount];
            for (int i = 0; i < UnityMesh.vertexCount; ++i)
            {
                CachedNormals[i] = new Tes.Maths.Vector3(UnityMesh.vertices[i].x, UnityMesh.vertices[i].y, UnityMesh.vertices[i].z);
            }
        }

        return(CachedNormals);
    }
示例#2
0
 public static Vector3 FromTes(Tes.Maths.Vector3 v)
 {
     return(new Vector3(v.X, v.Y, v.Z));
 }
示例#3
0
    void Start()
    {
        Dynamic = false;
        if (Shape == null)
        {
            // Resolve the appropriate shape.
            Collider collider = GetComponent <Collider>();
            UpdatePosition = UpdateRotation = UpdateScale = false;
            if (collider != null)
            {
                BoxCollider     box     = null;
                CapsuleCollider capsule = null;
                MeshCollider    mesh    = null;
                SphereCollider  sphere  = null;
                TerrainCollider terrain = null;
                WheelCollider   wheel   = null;

                // Note: colour is set using LookupColour() in TesServer.Add()

                // FIXME: isStatic doesn't do well to highlight static collision geometry.
                // Mark everything as dynamic for now.
                //if (!collider.gameObject.isStatic)
                //{
                UpdatePosition = UpdateRotation = UpdateScale = true;
                //}

                Tes.Maths.Vector3 scale = ToTes(transform.lossyScale);
                Tes.Maths.Vector3 pos   = ToTes(transform.position);
                if ((box = collider as BoxCollider) != null)
                {
                    pos     += ToTes(PositionOffset);
                    scale.X *= box.size.x;
                    scale.Y *= box.size.y;
                    scale.Z *= box.size.z;
                    Shape    = new Tes.Shapes.Box(NextId(), pos, scale, ToTes(transform.rotation));
                }
                else if ((capsule = collider as CapsuleCollider) != null)
                {
                    UpdateScale    = false;
                    Shape          = new Tes.Shapes.Capsule(NextId(), ToTes(transform.position), Tes.Maths.Vector3.AxisY, scale.Y * capsule.height, scale.X * capsule.radius);
                    _shapeRotation = FromTes(Shape.Rotation);
                    Shape.Rotation = ToTes(transform.rotation * _shapeRotation);
                }
                else if ((mesh = collider as MeshCollider) != null)
                {
                    var meshShape = new Tes.Shapes.MeshSet(NextId());
                    Shape = meshShape;
                    meshShape.AddPart(new TesMeshWrapper(mesh.sharedMesh));
                    meshShape.Position = ToTes(transform.position);
                    meshShape.Rotation = ToTes(transform.rotation);
                    meshShape.Scale    = scale;
                }
                else if ((sphere = collider as SphereCollider) != null)
                {
                    UpdateRotation = false;
                    UpdateScale    = false;
                    Shape          = new Tes.Shapes.Sphere(NextId(), ToTes(transform.localPosition), transform.lossyScale.x * sphere.radius);
                }
                else if ((terrain = collider as TerrainCollider) != null)
                {
                    Debug.LogWarning(string.Format("TerrainCollider not yet supported ({0}).", gameObject.name));
                }
                else if ((wheel = collider as WheelCollider) != null)
                {
                    Debug.LogWarning(string.Format("WheelCollider not yet supported ({0}).", gameObject.name));
                }
                else
                {
                    Debug.LogError(string.Format("Unsupported collider type for object {0}: {1}.", gameObject.name, collider.GetType().Name));
                }
            }
        }

        Dynamic = UpdatePosition || UpdateRotation || UpdateScale;
    }