Exemplo n.º 1
0
    public TxNodeHandle CreateNode(Vector3 _position, float _mass)
    {
        TxNodeHandle handle = TxNodeHandle.CreateInstance();

        handle.index    = nodes.Length;
        handle.name     = string.Format("N({0})", handle.index);
        handle.position = _position;
        handle.mass     = _mass;
        System.Array.Resize(ref nodes, nodes.Length + 1);
        nodes[handle.index] = handle;
        return(handle);
    }
Exemplo n.º 2
0
    void CreateHandles()
    {
        TxTruss data = trussData;

        if (data == null)
        {
            return;
        }

        nodes = new TxNodeHandle[data.nodeCount];
        for (int i = 0; i < data.nodeCount; ++i)
        {
            TxNodeHandle node = TxNodeHandle.CreateInstance();
            node.index    = i;
            node.name     = string.Format("N({0})", i);
            node.position = data.nodePosition[i];
            node.mass     = data.nodeMass[i];
            nodes[i]      = node;
        }

        links = new TxLinkHandle[data.linkCount];
        for (int i = 0; i < data.linkCount; ++i)
        {
            TxLinkHandle link = TxLinkHandle.CreateInstance();
            link.index      = i;
            link.node0      = data.linkNodes[i * 2 + 0];
            link.node1      = data.linkNodes[i * 2 + 1];
            link.name       = string.Format("L({0},{1})", link.node0, link.node1);
            link.stiffness  = data.linkStiffness[i];
            link.damping    = data.linkDamping[i];
            link.elastic    = data.linkElastic[i];
            link.breaking   = data.linkBreaking[i];
            link.stretching = data.linkStretching.Length > 0 ? data.linkStretching[i] : 1.0f;
            link.resist     = (TxLinkHandle.Resist)(data.linkFlags[i] & 0x3);
            links[i]        = link;
        }

        faces = new TxFaceHandle[data.faceCount];
        for (int i = 0; i < data.faceCount; ++i)
        {
            TxFaceHandle face = TxFaceHandle.CreateInstance();
            face.index     = i;
            face.node0     = data.faceNodes[i * 3 + 0];
            face.node1     = data.faceNodes[i * 3 + 1];
            face.node2     = data.faceNodes[i * 3 + 2];
            face.name      = string.Format("F({0},{1},{2})", face.node0, face.node1, face.node2);
            face.collision = (data.faceFlags[i] & (1 << 0)) != 0;
            face.skinning  = (data.faceFlags[i] & (1 << 1)) != 0;
            face.matter    = data.faceMatter.Length > 0 ? data.faceMatter[i] : 0;
            face.envelope  = data.faceEnvelope[i];
            faces[i]       = face;
        }
    }
Exemplo n.º 3
0
 public void DeleteNode(int _index, DestroyFn destroyFn = null)
 {
     if (destroyFn != null)
     {
         destroyFn(nodes[_index]);
     }
     else
     {
         DestroyImmediate(nodes[_index]);
     }
     for (int i = _index + 1; i < nodes.Length; ++i)
     {
         TxNodeHandle node = nodes[i];
         nodes[--node.index] = node;
     }
     System.Array.Resize(ref nodes, nodes.Length - 1);
     foreach (TxTruss.NamedSet s in trussData.nodesSet)
     {
         List <int> newIndices = new List <int>();
         for (int i = 0; i < s.indices.Length; ++i)
         {
             if (s.indices[i] < _index)
             {
                 newIndices.Add(s.indices[i]);
             }
             else if (s.indices[i] > _index)
             {
                 newIndices.Add(s.indices[i] - 1);
             }
         }
         s.indices = newIndices.ToArray();
     }
     for (int i = links.Length - 1; i >= 0; --i)
     {
         TxLinkHandle link = links[i];
         if (link.node0 == _index || link.node1 == _index)
         {
             DeleteLink(i, destroyFn);
         }
         else
         {
             if (link.node0 > _index)
             {
                 --link.node0;
             }
             if (link.node1 > _index)
             {
                 --link.node1;
             }
         }
     }
     for (int i = faces.Length - 1; i >= 0; --i)
     {
         TxFaceHandle face = faces[i];
         if (face.node0 == _index || face.node1 == _index || face.node2 == _index)
         {
             DeleteFace(i, destroyFn);
         }
         else
         {
             if (face.node0 > _index)
             {
                 --face.node0;
             }
             if (face.node1 > _index)
             {
                 --face.node1;
             }
             if (face.node2 > _index)
             {
                 --face.node2;
             }
         }
     }
 }