Пример #1
0
    public void ConstructMutatedBodyFromDNA()
    {
        for (int i = 0; i < myDNA.nodePositions.Count; i++)
        {
            nodes.Add(gd.lb.GetNode(myDNA.nodePositions[i] + origin));
        }

        for (int i = 0; i < myDNA.designInstructions.Count; i++)
        {
            GameObject newNode = nodes.ElementAt(myDNA.designInstructions[i].targetNode);
            GameObject oldNode = nodes.ElementAt(myDNA.designInstructions[i].baseNode);

            Physics.SyncTransforms();

            myDNA.designInstructions[i] = MutateDNAInstruction(myDNA.designInstructions[i]);

            Vector3    vector            = (newNode.transform.position - oldNode.transform.position);
            GameObject newlyCreatedJoint = gd.lb.GetJoint(oldNode.transform.position + vector.normalized * .9f);
            joints.Add(newlyCreatedJoint);
            newlyCreatedJoint.transform.rotation  = Quaternion.FromToRotation(Vector3.right, vector);
            newlyCreatedJoint.transform.rotation *= Quaternion.Euler(myDNA.designInstructions[i].GetRotation(), 0, 0);

            JointScript js = newlyCreatedJoint.GetComponent <JointScript>();
            js.SetBoneSize(vector.magnitude - 2.5f);
            js.ConnectBaseToNode(oldNode);
            js.ConnectEdgeToNode(newNode);


            js.SetSineFactors(myDNA.designInstructions[i].GetSineFactors());
        }
    }
Пример #2
0
    private bool GetValidConnectionToNode(int a, int b)
    {
        GameObject newNode = nodes[a];
        GameObject oldNode = nodes[b];

        Vector3 vector = (newNode.transform.position - oldNode.transform.position);

        if (vector.magnitude < 3.1f)
        {
            return(false);
        }

        Physics.SyncTransforms();
        Ray ray = new Ray(oldNode.transform.position + vector.normalized * 1.5f, vector.normalized);

        RaycastHit[] rch = Physics.SphereCastAll(ray, .5f, vector.magnitude - 3f);

        if (rch.Length > 0)
        {
            return(false);
        }

        GameObject newlyCreatedJoint = gd.lb.GetJoint(oldNode.transform.position + vector.normalized * .9f);

        joints.Add(newlyCreatedJoint);
        newlyCreatedJoint.transform.rotation = Quaternion.FromToRotation(Vector3.right, vector);

        JointScript js = newlyCreatedJoint.GetComponent <JointScript>();

        js.SetBoneSize(vector.magnitude - 2.5f);
        js.ConnectBaseToNode(oldNode);
        js.ConnectEdgeToNode(newNode);
        js.SetSineFactors(GetRandomSineFactors());

        myDNA.AddToInstructions(new Instruction(b, a, js.GetSineFactors(), GetRandomRotFactor()));
        return(true);
    }