Beispiel #1
0
 // Use this for initialization
 void Start()
 {
     data              = new BodySegmentMeshData(length, radiusA, radiusB, roundnessA, roundnessB, angleA, angleB, heightSegments, radialSegments);
     script            = gameObject.AddComponent <BodySegmentMesh>();
     filter            = gameObject.AddComponent <MeshFilter>();
     renderer          = gameObject.AddComponent <MeshRenderer>();
     renderer.material = new Material(Shader.Find("Diffuse"));
     filter.sharedMesh = script.BuildMesh(data);
 }
Beispiel #2
0
    public SpineData(BodySegmentMeshData torso, BodySegmentMeshData waist, BodySegmentMeshData pelvis, float pelvisAngleOffset, float waistAngleOffset)
    {
        m_torsoData         = torso;
        m_waistData         = waist;
        m_pelvisData        = pelvis;
        m_pelvisAngleOffset = pelvisAngleOffset;
        m_waistAngleOffset  = waistAngleOffset;

        m_spineLength = m_torsoData.length + m_waistData.length + m_pelvisData.length;
    }
Beispiel #3
0
    /*
     * GameObject BuildLeg(string objectName, Transform parentHipNode, LegData data) {return BuildLeg(objectName, parentHipNode, Vector3.zero,data);}
     *
     * GameObject BuildLeg(string objectName, Transform parentHipNode, Vector3 offset, LegData data) {
     *
     *      GameObject newLeg = new GameObject(objectName);
     *      newLeg.transform.parent = gameObject.transform;
     *      newLeg.transform.localPosition = Vector3.zero;
     *
     *      LegScript newLegScript = newLeg.AddComponent<LegScript>();
     *      newLegScript.InitialiseLeg(offset,data);
     *
     *      return newLeg;
     * }
     */
    GameObject NewBodySegment(BodySegmentMeshData data, string name)
    {
        GameObject      newObject  = new GameObject(name);
        BodySegmentMesh meshScript = newObject.AddComponent <BodySegmentMesh>();
        MeshFilter      filter     = newObject.AddComponent <MeshFilter>();
        MeshRenderer    renderer   = newObject.AddComponent <MeshRenderer>();

        renderer.material = defaultMat;
        filter.sharedMesh = meshScript.BuildMesh(data);
        return(newObject);
    }
Beispiel #4
0
 // Update is called once per frame
 void Update()
 {
     filter.sharedMesh.Clear();
     if (useSimplified)
     {
         data = new BodySegmentMeshData(length, radiusA, radiusB, simple_roundness, simple_segments);
     }
     else
     {
         data = new BodySegmentMeshData(length, radiusA, radiusB, roundnessA, roundnessB, angleA, angleB, heightSegments, radialSegments);
     }
     filter.sharedMesh = script.BuildMesh(data);
 }
Beispiel #5
0
    void AttachBodyPart(Transform parent, BodySegmentMeshData data)
    {
        MeshFilter      filter     = parent.GetComponent <MeshFilter>();
        MeshRenderer    renderer   = parent.GetComponent <MeshRenderer>();
        BodySegmentMesh meshScript = parent.GetComponent <BodySegmentMesh>();

        if (filter == null)
        {
            filter = parent.gameObject.AddComponent <MeshFilter>();
        }
        if (renderer == null)
        {
            renderer = parent.gameObject.AddComponent <MeshRenderer>();
        }
        if (meshScript == null)
        {
            meshScript = parent.gameObject.AddComponent <BodySegmentMesh>();
        }
        filter.sharedMesh = meshScript.BuildMesh(data);
        renderer.material = defaultMat;
    }
Beispiel #6
0
    public LegData(BodySegmentMeshData thigh, BodySegmentMeshData calf, BodySegmentMeshData foot, BodySegmentMeshData toe)
    {
        m_thighData = thigh;
        m_calfData  = calf;
        m_footData  = foot;
        m_toeData   = toe;

        m_legLength   = m_thighData.length + m_calfData.length + m_footData.length;
        m_standHeight = m_legLength * standStraightness;

        float legUpperWidth = 1.0f;
        float legMid1Width  = 0.8f;
        float legMid2Width  = 0.7f;
        float legLowerWidth = 0.3f;

        /*
         * m_legWidthCurve = new Bezier3D(new Vector3(0.0f,legUpperWidth,0.0f),
         *                                                         new Vector3(0.33f,legMid1Width,0.0f),
         *                                                         new Vector3(0.67f,legMid2Width,0.0f),
         *                                                         new Vector3(1.0f,legLowerWidth,0.0f));
         */
    }
Beispiel #7
0
 public Mesh BuildMesh(BodySegmentMeshData data)
 {
     return(BuildMesh(data.length, data.radiusA, data.radiusB, data.roundnessA, data.roundnessB, data.angleA, data.angleB, data.heightSegments, data.radialSegments));
 }
Beispiel #8
0
    public void CreateNewSpecies()
    {
        // First we must generate all random variables

        // First, define leg dimensions
        // Note, radii should always be less than length for stability, and ideally much less
        float frontHipRadius = 0.5f;
        float frontThighLength = 0.7f;  float frontThighRoundness = 0.6f;
        float frontKneeRadius = 0.4f;
        float frontCalfLength = 0.7f;   float frontCalfRoundness = 0.3f;
        float frontAnkleRadius = 0.3f;
        float frontFootLength = 0.6f;   float frontFootRoundness = 0.6f;
        float frontFootRadius = 0.4f;
        float frontToeLength = 0.5f;    float frontToeRoundness = 0.5f;
        float frontToeRadius = 0.3f;

        float backHipRadius = 0.7f;
        float backThighLength = 1.3f;   float backThighRoundness = 0.3f;
        float backKneeRadius = 0.4f;
        float backCalfLength = 1.2f;    float backCalfRoundness = 0.6f;
        float backAnkleRadius = 0.3f;
        float backFootLength = 0.6f;    float backFootRoundness = 0.7f;
        float backFootRadius = 0.2f;
        float backToeLength = 0.3f;             float backToeRoundness = 0.9f;
        float backToeRadius = 0.1f;

        // Data containers must be created for each segment
        BodySegmentMeshData fr_thighData = new BodySegmentMeshData(frontThighLength, frontHipRadius, frontKneeRadius, frontThighRoundness, 12);
        BodySegmentMeshData fr_calfData  = new BodySegmentMeshData(frontCalfLength, frontKneeRadius, frontAnkleRadius, frontCalfRoundness, 12);
        BodySegmentMeshData fr_footData  = new BodySegmentMeshData(frontFootLength, frontAnkleRadius, frontFootRadius, frontFootRoundness, 12);
        BodySegmentMeshData fr_toeData   = new BodySegmentMeshData(frontToeLength, frontFootRadius, frontToeRadius, frontToeRoundness, 12);

        BodySegmentMeshData bk_thighData = new BodySegmentMeshData(backThighLength, backHipRadius, backKneeRadius, backThighRoundness, 12);
        BodySegmentMeshData bk_calfData  = new BodySegmentMeshData(backCalfLength, backKneeRadius, backAnkleRadius, backCalfRoundness, 12);
        BodySegmentMeshData bk_footData  = new BodySegmentMeshData(backFootLength, backAnkleRadius, backFootRadius, backFootRoundness, 12);
        BodySegmentMeshData bk_toeData   = new BodySegmentMeshData(backToeLength, backFootRadius, backToeRadius, backToeRoundness, 12);

        // LegData objects can now be created by passing in segment data
        // Front and back legs have separate leg data
        m_frontLegData             = new LegData(fr_thighData, fr_calfData, fr_footData, fr_toeData);
        m_frontLegData.reverseKnee = true;         // Front legs bend the opposite way
        m_backLegData = new LegData(bk_thighData, bk_calfData, bk_footData, bk_toeData);

        // Creating the leg data has also defined the height at which each leg stands
        // Use this to set the default heights for the spine
        float shoulderHeight = m_frontLegData.legLength;
        float pelvisHeight   = m_backLegData.legLength;

        // Define other random variables for the spine
        float shoulderRadius = 0.8f;
        float torsoLength = 1.2f;       float torsoRoundness = 0.8f;
        float chestRadius = 1.0f;
        float waistLength = 1.5f;       float waistRoundness = 0.2f;
        float waistRadius = 0.8f;
        float pelvisLength = 1.2f;      float pelvisRoundness = 0.4f;
        float hipRadius = 0.6f;

        BodySegmentMeshData torsoData  = new BodySegmentMeshData(torsoLength, chestRadius, shoulderRadius, torsoRoundness, 20);
        BodySegmentMeshData waistData  = new BodySegmentMeshData(waistLength, waistRadius, chestRadius, waistRoundness, 20);
        BodySegmentMeshData pelvisData = new BodySegmentMeshData(pelvisLength, hipRadius, waistRadius, pelvisRoundness, 20);

        m_spineData = new SpineData(torsoData, waistData, pelvisData, 0.0f, 0.0f);
        Debug.Log("Checking, spine length is " + m_spineData.spineLength);
        m_legSeparation  = Mathf.Sqrt(m_spineData.spineLength * m_spineData.spineLength - (shoulderHeight - pelvisHeight) * (shoulderHeight - pelvisHeight));
        m_spineElevation = Mathf.Rad2Deg * Mathf.Asin((shoulderHeight - pelvisHeight) / m_spineData.spineLength);
        Debug.Log("Leg separation: " + m_legSeparation + ", Spine elevation: " + m_spineElevation);


        // Define tail dimensions
        m_tailLength   = 5.0f;
        m_tailTaper    = 0.8f;
        m_tailSegments = 6;



        // Create animations
        // Animations are based only on species variables defined above
        //AnimationGenerator animGenerator = new AnimationGenerator(this);
        //m_clips = animGenerator.GenerateAnimation();
        m_clips = new ClipContainer(this);
        m_clips.EnableAnimationGroup(ClipContainer.AnimType.IDLE);
        //ClipContainer clips = new ClipContainer(species);
        //clips.EnableAnimationGroup(ClipContainer.AnimType.IDLE);
        Debug.Log("m_clips = " + m_clips);
    }
Beispiel #9
0
    //GameObject AttachNewBodyPart(string name, Vector3 offset, Quaternion rotation, float length, float upperWidth, float lowerWidth,
    //							 float roundnessA, float roundnessB, float angleA, float angleB, int heightSegments, int radialSegments) {
    public GameObject AttachNewBodyPart(string name, Vector3 offset, Quaternion rotation, BodySegmentMeshData data)
    {
        GameObject newPart = NewChild(name);

        newPart.transform.localPosition = offset;
        newPart.transform.rotation      = rotation;
        MeshFilter      filter     = newPart.AddComponent <MeshFilter>();
        MeshRenderer    renderer   = newPart.AddComponent <MeshRenderer>();
        BodySegmentMesh meshScript = newPart.AddComponent <BodySegmentMesh>();

        filter.sharedMesh = meshScript.BuildMesh(data);
        renderer.material = new Material(Shader.Find("Diffuse"));
        return(newPart);
    }
Beispiel #10
0
    // This function must be called first to set up variables
    public void InitialiseLeg(Vector3 offset, LegData data)
    {
        thData = data.thighData;
        cData  = data.calfData;
        fData  = data.footData;
        toData = data.toeData;

        // Get variables from creature species
        //
        //
        //
        //

        MeshFilter      filter;
        MeshRenderer    renderer;
        BodySegmentMesh meshScript;
        Material        mat = new Material(Shader.Find("Diffuse"));

        thighLength = thData.length;
        calfLength  = cData.length;
        footLength  = fData.length;
        toeLength   = toData.length;

        legPivot = new GameObject("legPivot");
        //legPivot.transform.position = new Vector3(0.0f,data.standHeight,0.0f);
        legPivot.transform.parent        = transform;
        legPivot.transform.localPosition = Vector3.zero;

        // Create leg segments

        thighJoint                  = new GameObject("thighJoint");
        filter                      = thighJoint.AddComponent <MeshFilter>();
        renderer                    = thighJoint.AddComponent <MeshRenderer>();
        meshScript                  = thighJoint.AddComponent <BodySegmentMesh>();
        filter.sharedMesh           = meshScript.BuildMesh(thData);
        renderer.material           = mat;
        thighJoint.transform.parent = legPivot.transform;

        calfJoint = new GameObject("calfJoint");
        calfJoint.transform.parent = thighJoint.transform;
        filter            = calfJoint.AddComponent <MeshFilter>();
        renderer          = calfJoint.AddComponent <MeshRenderer>();
        meshScript        = calfJoint.AddComponent <BodySegmentMesh>();
        filter.sharedMesh = meshScript.BuildMesh(cData);
        renderer.material = mat;

        footJoint = new GameObject("footJoint");
        footJoint.transform.parent = calfJoint.transform;
        filter            = footJoint.AddComponent <MeshFilter>();
        renderer          = footJoint.AddComponent <MeshRenderer>();
        meshScript        = footJoint.AddComponent <BodySegmentMesh>();
        filter.sharedMesh = meshScript.BuildMesh(fData);
        renderer.material = mat;

        toeJoint = new GameObject("toeJoint");
        toeJoint.transform.parent = footJoint.transform;
        filter            = toeJoint.AddComponent <MeshFilter>();
        renderer          = toeJoint.AddComponent <MeshRenderer>();
        meshScript        = toeJoint.AddComponent <BodySegmentMesh>();
        filter.sharedMesh = meshScript.BuildMesh(toData);
        renderer.material = mat;

        // Set up initial positions
        thighJoint.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
        thighJoint.transform.Rotate(0.0f, 0.0f, 180.0f);
        calfJoint.transform.Translate(0.0f, thighLength, 0.0f);
        footJoint.transform.Translate(0.0f, calfLength, 0.0f);
        toeJoint.transform.Translate(0.0f, footLength, 0.0f);
        toeJoint.transform.Rotate(0.0f, 0.0f, 90.0f);
    }
Beispiel #11
0
 public void RandomizeDataFromReference(BodySegmentMeshData dataRef)
 {
 }
Beispiel #12
0
 public BodySegmentMeshData(BodySegmentMeshData referenceData)
 {
     RandomizeDataFromReference(referenceData);
 }