public static void AddPColliders(bool setDanLength)
        {
            if (hScene == null)
            {
                return;
            }

            male_list = hScene.GetMales().Where(male => male != null).ToArray();
            fem_list  = hScene.GetFemales().Where(female => female != null).ToArray();

            danCollider           = new DynamicBoneCollider();
            referenceLookAtTarget = null;
            constrainPoints       = new ConstrainPoints();
            kokanBones            = new List <DynamicBone>();

            bDansFound = false;
            foreach (var male in male_list.Where(male => male != null))
            {
                if (!bDansFound)
                {
                    Transform dan101 = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(dan_base)).FirstOrDefault();
                    Transform dan109 = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(dan_head)).FirstOrDefault();
                    Transform danTop = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(dan_sack)).FirstOrDefault();
                    Transform index  = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(index_finger)).FirstOrDefault();
                    Transform middle = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(middle_finger)).FirstOrDefault();
                    Transform ring   = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(ring_finger)).FirstOrDefault();

                    bDanPenetration = false;
                    if (dan101 != null && dan109 != null && danTop != null)
                    {
                        if (setDanLength)
                        {
                            baseDanLength = Vector3.Distance(dan101.position, dan109.position);
                            if (Geometry.ApproximatelyZero(baseDanLength))
                            {
                                baseDanLength = 1.8f;
                            }
                        }

                        danPoints      = new DanPoints(dan101, dan109, danTop);
                        lastDanPostion = new Vector3(0, 0, 0);
                        bDansFound     = true;

                        danCollider = dan101.GetComponent <DynamicBoneCollider>();

                        if (danCollider == null)
                        {
                            danCollider = dan101.gameObject.AddComponent(typeof(DynamicBoneCollider)) as DynamicBoneCollider;
                        }

                        danCollider.m_Direction = DynamicBoneColliderBase.Direction.Z;
                        danCollider.m_Bound     = DynamicBoneColliderBase.Bound.Outside;
                        danCollider.m_Center    = new Vector3(0, _dan_collider_verticalcenter.Value, baseDanLength / 2);
                        danCollider.m_Radius    = _dan_collider_radius.Value;
                        danCollider.m_Height    = baseDanLength + (_dan_collider_headlength.Value * 2);
                    }

                    if (index != null && middle != null && ring != null)
                    {
                        indexCollider  = index.GetComponent <DynamicBoneCollider>();
                        middleCollider = middle.GetComponent <DynamicBoneCollider>();
                        ringCollider   = ring.GetComponent <DynamicBoneCollider>();

                        if (indexCollider == null)
                        {
                            indexCollider = index.gameObject.AddComponent(typeof(DynamicBoneCollider)) as DynamicBoneCollider;
                        }

                        if (middleCollider == null)
                        {
                            middleCollider = middle.gameObject.AddComponent(typeof(DynamicBoneCollider)) as DynamicBoneCollider;
                        }

                        if (ringCollider == null)
                        {
                            ringCollider = ring.gameObject.AddComponent(typeof(DynamicBoneCollider)) as DynamicBoneCollider;
                        }

                        indexCollider.m_Direction = DynamicBoneColliderBase.Direction.X;
                        indexCollider.m_Center    = new Vector3(0, 0, 0);
                        indexCollider.m_Bound     = DynamicBoneColliderBase.Bound.Outside;
                        indexCollider.m_Radius    = _finger_collider_radius.Value;
                        indexCollider.m_Height    = _finger_collider_length.Value;

                        middleCollider.m_Direction = DynamicBoneColliderBase.Direction.X;
                        middleCollider.m_Center    = new Vector3(0, 0, 0);
                        middleCollider.m_Bound     = DynamicBoneColliderBase.Bound.Outside;
                        middleCollider.m_Radius    = _finger_collider_radius.Value;
                        middleCollider.m_Height    = _finger_collider_length.Value;

                        ringCollider.m_Direction = DynamicBoneColliderBase.Direction.X;
                        ringCollider.m_Center    = new Vector3(0, 0, 0);
                        ringCollider.m_Bound     = DynamicBoneColliderBase.Bound.Outside;
                        ringCollider.m_Radius    = _finger_collider_radius.Value;
                        ringCollider.m_Height    = _finger_collider_length.Value;
                    }

                    Console.WriteLine("bDansFound " + bDansFound);
                }
            }

            bHPointsFound = false;
            foreach (var female in fem_list.Where(female => female != null))
            {
                if (!bHPointsFound)
                {
                    List <Transform> frontHPoints = new List <Transform>();
                    List <Transform> backHPoints  = new List <Transform>();
                    Transform        hPointBackOfHead;

                    for (int index = 0; index < frontHPointsList.Count; index++)
                    {
                        frontHPoints.Add(female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(frontHPointsList[index])).FirstOrDefault());
                    }

                    for (int index = 0; index < backHPointsList.Count; index++)
                    {
                        backHPoints.Add(female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(backHPointsList[index])).FirstOrDefault());
                    }

                    hPointBackOfHead = female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(headHPoint)).FirstOrDefault();

                    bpKokanTarget = female.GetComponentsInChildren <Transform>(true).Where(x => x.name.Equals(bp_kokan_target)).FirstOrDefault();
                    if (bpKokanTarget != null)
                    {
                        if (bpKokanTarget.gameObject.activeSelf == false)
                        {
                            bpKokanTarget.gameObject.SetActive(true);
                        }

                        Console.WriteLine("BP Target Found " + bpKokanTarget.name);
                        frontHPoints[0] = bpKokanTarget;
                    }

                    if (frontHPoints.Count == frontHPointsList.Count && backHPoints.Count == backHPointsList.Count && hPointBackOfHead != null)
                    {
                        bHPointsFound   = true;
                        constrainPoints = new ConstrainPoints(frontHPoints, backHPoints, hPointBackOfHead);
                    }

                    foreach (DynamicBone db in female.GetComponentsInChildren <DynamicBone>(true).Where(x => x.name.Contains("cf_J_Vagina")))
                    {
                        db.m_Colliders.Clear();
                    }

                    Console.WriteLine("bHPointsFound " + bHPointsFound);

                    Transform          kokanBone = female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains("cf_J_Kokan")).FirstOrDefault();
                    List <DynamicBone> dbList    = new List <DynamicBone>();
                    foreach (DynamicBone db in female.GetComponentsInChildren <DynamicBone>(true).Where(x => x.name.Contains("cf_J_Vagina")))
                    {
                        if (db == null)
                        {
                            continue;
                        }

                        if (db.enabled == false)
                        {
                            db.enabled = true;
                        }

                        if (db.m_Root != null)
                        {
                            int colliderIndex = dynamicBonesList.IndexOf(db.m_Root.name);
                            if (colliderIndex >= 0)
                            {
                                //    DynamicBoneCollider dbc = female.GetComponentsInChildren<DynamicBoneCollider>().Where(x => x.name.Contains(colliderList[colliderIndex])).FirstOrDefault();
                                //   if (dbc == null)
                                //   {
                                Transform colliderTransform = female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(colliderList[colliderIndex])).FirstOrDefault();

                                if (colliderTransform != null)
                                {
                                    Console.WriteLine("collider " + colliderTransform.name);

                                    //     dbc = colliderTransform.gameObject.AddComponent(typeof(DynamicBoneCollider)) as DynamicBoneCollider;
                                    //     dbc.m_Bound = DynamicBoneColliderBase.Bound.Inside;
                                    //     dbc.m_Direction = DynamicBoneColliderBase.Direction.Y;

                                    if (kokanBone == null)
                                    {
                                        //          dbc.m_Height = colliderHeightList[colliderIndex];
                                        //          dbc.m_Radius = colliderRadiusList[colliderIndex];
                                    }
                                    else
                                    {
                                        if (colliderIndex < 3)
                                        {
                                            //                dbc.m_Height = colliderHeightList[colliderIndex] * kokanBone.lossyScale.z;
                                            //              dbc.m_Radius = colliderRadiusList[colliderIndex] * kokanBone.lossyScale.z;
                                            db.m_Radius *= kokanBone.lossyScale.z;
                                        }
                                        else
                                        {
                                            //                dbc.m_Height = colliderHeightList[colliderIndex] * (kokanBone.lossyScale.x + kokanBone.lossyScale.z) / 2;
                                            //                dbc.m_Radius = colliderRadiusList[colliderIndex] * (kokanBone.lossyScale.x + kokanBone.lossyScale.z) / 2;
                                            db.m_Radius *= (kokanBone.lossyScale.x + kokanBone.lossyScale.z) / 2;
                                        }
                                    }
                                }
                                //     }

                                //       if (_use_bounding_colliders.Value && dbc != null)
                                //             db.m_Colliders.Add(dbc);
                            }
                            else if (kokanBone != null)
                            {
                                db.m_Radius *= kokanBone.lossyScale.x;
                            }

                            db.UpdateParameters();
                            dbList.Add(db);
                        }
                    }

                    kokanBones = dbList;
                }

                kokanBoneAdjustTarget = fem_list[0].GetComponentsInChildren <Transform>().Where(x => x.name.Contains("cf_J_Kokan")).FirstOrDefault();
            }
            Console.WriteLine("AddColliders done.");
        }
Exemplo n.º 2
0
        public static void AddPColliders()
        {
            if (hScene == null)
            {
                return;
            }

            male_list = hScene.GetMales().Where(male => male != null).ToArray();
            fem_list  = hScene.GetFemales().Where(female => female != null).ToArray();

            danCollider     = new DynamicBoneCollider();
            constrainPoints = new ConstrainPoints();
            kokanBones      = new List <DynamicBone>();

            bDansFound = false;
            foreach (var male in male_list.Where(male => male != null))
            {
                if (!bDansFound)
                {
                    Transform dan101 = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(dan_base)).FirstOrDefault();
                    Transform dan109 = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(dan_head)).FirstOrDefault();
                    Transform danTop = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(dan_sack)).FirstOrDefault();

                    bDanPenetration = false;
                    if (dan101 != null && dan109 != null && danTop != null)
                    {
                        danPoints = new DanPoints(dan101, dan109, danTop);

                        bDansFound        = true;
                        dan101.localScale = new Vector3(_dan_girth.Value, _dan_girth.Value, 1);

                        danCollider = dan101.GetComponent <DynamicBoneCollider>();

                        if (danCollider == null)
                        {
                            danCollider = dan101.gameObject.AddComponent(typeof(DynamicBoneCollider)) as DynamicBoneCollider;
                        }

                        danCollider.m_Direction = DynamicBoneColliderBase.Direction.Z;
                        danCollider.m_Center    = new Vector3(0, _dan_collider_verticalcenter.Value, _dan_length.Value / 2);
                        danCollider.m_Bound     = DynamicBoneColliderBase.Bound.Outside;
                        danCollider.m_Radius    = _dan_collider_radius.Value;
                        danCollider.m_Height    = _dan_length.Value + (_dan_collider_headlength.Value * 2);

                        danPoints.danTop.localScale = new Vector3(_dan_sack_size.Value, _dan_sack_size.Value, _dan_sack_size.Value);
                        lastDan109Position          = danPoints.danEnd.position;
                        lastDanRotation             = danPoints.danEnd.rotation;
                        lastAdjustTime = Time.time;
                    }

                    referenceLookAtTarget    = danPoints.danEnd;
                    lastDan101TargetDistance = Vector3.Distance(referenceLookAtTarget.position, danPoints.danStart.position);
                    Console.WriteLine("bDansFound " + bDansFound);
                }
            }

            bHPointsFound = false;
            foreach (var female in fem_list.Where(female => female != null))
            {
                if (!bHPointsFound)
                {
                    List <Transform> frontHPoints = new List <Transform>();
                    List <Transform> backHPoints  = new List <Transform>();
                    Transform        hPointBackOfHead;

                    for (int index = 0; index < frontHPointsList.Length; index++)
                    {
                        frontHPoints.Add(female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(frontHPointsList[index])).FirstOrDefault());
                    }

                    for (int index = 0; index < backHPointsList.Length; index++)
                    {
                        backHPoints.Add(female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(backHPointsList[index])).FirstOrDefault());
                    }

                    hPointBackOfHead = female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(headHPoint)).FirstOrDefault();

                    bpKokanTarget = female.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(bp_kokan_target)).FirstOrDefault();
                    if (bpKokanTarget != null)
                    {
                        Console.WriteLine("BP Target Found " + bpKokanTarget.name);
                        frontHPoints[0] = bpKokanTarget;
                    }

                    if (frontHPoints.Count == frontHPointsList.Length && backHPoints.Count == backHPointsList.Length && hPointBackOfHead != null)
                    {
                        bHPointsFound   = true;
                        constrainPoints = new ConstrainPoints(frontHPoints, backHPoints, hPointBackOfHead);
                    }

                    foreach (DynamicBone db in female.GetComponentsInChildren <DynamicBone>().Where(x => x.name.Contains("cf_J_Vagina")))
                    {
                        db.m_Colliders.Clear();
                    }

                    Console.WriteLine("bHPointsFound " + bHPointsFound);

                    /*         for (int i = 0; i < colliderList.Length; i++)
                     *       {
                     *           DynamicBone db = female.GetComponentsInChildren<DynamicBone>().Where(x => x.m_Root.name.Equals(dynamicBonesList[i])).FirstOrDefault();
                     *           DynamicBoneCollider dbc = female.GetComponentsInChildren<DynamicBoneCollider>().Where(x => x.name.Equals(colliderList[i])).FirstOrDefault();
                     *
                     *           if (dbc == null)
                     *           {
                     *               Transform colliderTransform = female.GetComponentsInChildren<Transform>().Where(x => x.name.Contains(colliderList[i])).FirstOrDefault();
                     *
                     *               if (colliderTransform != null)
                     *               {
                     *                   dbc = colliderTransform.gameObject.AddComponent(typeof(DynamicBoneCollider)) as DynamicBoneCollider;
                     *                   dbc.m_Bound = DynamicBoneColliderBase.Bound.Inside;
                     *                   dbc.m_Direction = DynamicBoneColliderBase.Direction.Y;
                     *                   dbc.m_Height = colliderHeightList[i];
                     *                   dbc.m_Radius = colliderRadiusList[i];
                     *               }
                     *           }
                     *
                     *           if (db != null && dbc != null)
                     *           {
                     *               db.m_Colliders.Add(dbc);
                     *
                     *               Console.WriteLine(dbc.name + " collider radius " + dbc.m_Radius + ", height: " + dbc.m_Height);
                     *
                     *               foreach (DynamicBoneColliderBase dbcb in db.m_Colliders)
                     *                   Console.WriteLine(db.m_Root.name + " collider " + dbcb.name);
                     *           }
                     *           else
                     *           {
                     *               if (db == null)
                     *                   Console.WriteLine(dynamicBonesList[i] + " bone not found for " + female.name);
                     *               if (dbc == null)
                     *                   Console.WriteLine(colliderList[i] + " collider not found for " + female.name);
                     *           }
                     *       }
                     */
                    List <DynamicBone> dbList = new List <DynamicBone>();
                    foreach (DynamicBone db in female.GetComponentsInChildren <DynamicBone>().Where(x => x.name.Contains("cf_J_Vagina")))
                    {
                        if (db != null)
                        {
                            dbList.Add(db);
                        }
                    }
                    kokanBones = dbList;
                }
            }

            kokanBone = fem_list[0].GetComponentsInChildren <Transform>().Where(x => x.name.Contains("cf_J_Kokan")).FirstOrDefault();

            Console.WriteLine("AddColliders done.");
        }
Exemplo n.º 3
0
        public static void AddPColliders(HScene __instance)
        {
            hScene    = __instance;
            male_list = __instance.GetMales().Where(male => male != null).ToArray();
            fem_list  = __instance.GetFemales().Where(female => female != null).ToArray();

            danCollider     = new DynamicBoneCollider();
            constrainPoints = new ConstrainPoints();
            kokanBones      = new List <DynamicBone>();

            bDansFound = false;
            foreach (var male in male_list.Where(male => male != null))
            {
                if (!bDansFound)
                {
                    Transform dan101 = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(dan_base)).FirstOrDefault();
                    Transform dan109 = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(dan_head)).FirstOrDefault();
                    Transform danTop = male.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(dan_sack)).FirstOrDefault();

                    bDanPenetration = false;
                    if (dan101 != null && dan109 != null && danTop != null)
                    {
                        danPoints = new DanPoints(dan101, dan109, danTop);

                        bDansFound        = true;
                        dan101.localScale = new Vector3(_dan_girth.Value, _dan_girth.Value, 1);

                        danCollider = dan101.GetComponent <DynamicBoneCollider>();

                        if (danCollider == null)
                        {
                            danCollider = dan101.gameObject.AddComponent(typeof(DynamicBoneCollider)) as DynamicBoneCollider;
                        }

                        danCollider.m_Direction     = DynamicBoneColliderBase.Direction.Z;
                        danCollider.m_Center        = new Vector3(0, 0, _dan_length.Value / 2);
                        danCollider.m_Bound         = DynamicBoneColliderBase.Bound.Outside;
                        danCollider.m_Radius        = _dan_collider_radius.Value;
                        danCollider.m_Height        = _dan_length.Value + (_dan_collider_headlength.Value * 2);
                        danPoints.danTop.localScale = new Vector3(_dan_sack_size.Value, _dan_sack_size.Value, _dan_sack_size.Value);
                        lastDan109Position          = danPoints.danEnd.position;
                        lastDanRotation             = danPoints.danEnd.rotation;
                        lastDanVector  = danPoints.danEnd.position - danPoints.danStart.position;
                        lastDanLength  = _dan_length.Value;
                        lastAdjustTime = Time.time;
                    }

                    referenceLookAtTarget    = danPoints.danEnd;
                    lastDan101TargetDistance = Vector3.Distance(referenceLookAtTarget.position, danPoints.danStart.position);
                    Console.WriteLine("bDansFound " + bDansFound);
                }
            }

            bHPointsFound = false;
            foreach (var female in fem_list.Where(female => female != null))
            {
                if (!bHPointsFound)
                {
                    List <Transform> frontHPoints = new List <Transform>();
                    List <Transform> backHPoints  = new List <Transform>();
                    Transform        hPointBackOfHead;

                    for (int index = 0; index < frontHPointsList.Length; index++)
                    {
                        frontHPoints.Add(female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(frontHPointsList[index])).FirstOrDefault());
                    }

                    for (int index = 0; index < backHPointsList.Length; index++)
                    {
                        backHPoints.Add(female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(backHPointsList[index])).FirstOrDefault());
                    }

                    hPointBackOfHead = female.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(headHPoint)).FirstOrDefault();

                    if (frontHPoints.Count == frontHPointsList.Length && backHPoints.Count == backHPointsList.Length && hPointBackOfHead != null)
                    {
                        bHPointsFound   = true;
                        constrainPoints = new ConstrainPoints(frontHPoints, backHPoints, hPointBackOfHead);
                    }

                    Console.WriteLine("bHPointsFound " + bHPointsFound);

                    List <DynamicBone> dbList = new List <DynamicBone>();

                    foreach (DynamicBone db in female.GetComponentsInChildren <DynamicBone>().Where(x => x.name.Contains("cf_J_Vagina")))
                    {
                        if (db != null)
                        {
                            Console.WriteLine(db.m_Root.name + " found, adding collilders");

                            dbList.Add(db);


                            if (db.m_Colliders.Contains(danCollider))
                            {
                                Console.WriteLine("Instance of " + danCollider.name + " already exists in list for DB " + db.name);
                            }
                            else
                            {
                                db.m_Colliders.Add(danCollider);
                                Console.WriteLine(danCollider.name + " added to " + female.name + " for bone " + db.name);
                            }
                        }
                    }

                    kokanBones = dbList;
                }
            }
            inHScene = true;
            Console.WriteLine("AddColliders done.");
        }