Esempio 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);
    }
Esempio 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;
        }
    }