Пример #1
0
        public HumLegChain(BodyPart part, IComplexHumanDefinition definition) : base(part)
        {
            _part       = part;
            _isRight    = part == BodyPart.LegR;
            _definition = definition;
            _model      = definition.Model;
            var modelFw = _model.forward;
            var modelUp = _model.up;
//            var modelSide = _isRight ? _model.right : -_model.right;
            var leg = part == BodyPart.LegL ? definition.LegL : definition.LegR;

            Pelvis = leg.ThighBend.parent;

            AutoPositionFoot = true;
            AutoPositionToes = false;

            ThighBend  = leg.ThighBend;
            ThighTwist = leg.ThighTwist;
            Shin       = leg.Shin;

            Foot        = leg.FootHolder ?? leg.Foot;
            Metatarsals = leg.Metatarsals;
            Toe         = leg.ToeHolder ?? leg.Toe;

            FootHandler = new HumBoneHandler(_isRight ? BodyPart.FootR : BodyPart.FootL, _model, Foot);
            ToeHandler  = new HumBoneHandler(_isRight ? BodyPart.ToesR : BodyPart.ToesL, _model, Toe);

            _handle = CreateHandle(Pelvis, _part, false, Foot.position, modelFw, modelUp);

            BigToe     = leg.BigToe;
            BigToe2    = leg.BigToe2;
            SmallToe11 = leg.SmallToe11;
            SmallToe12 = leg.SmallToe12;
            SmallToe21 = leg.SmallToe21;
            SmallToe22 = leg.SmallToe22;
            SmallToe31 = leg.SmallToe31;
            SmallToe32 = leg.SmallToe32;
            SmallToe41 = leg.SmallToe41;
            SmallToe42 = leg.SmallToe42;

            _toeInitialY = Toe.position.y - _model.position.y;
            _leftPlaneNormalModelSpace  = _model.InverseTransformDirection((_model.right).RotateAbout(_model.forward, -35));
            _rightPlaneNormalModelSpace = _model.InverseTransformDirection((-_model.right).RotateAbout(_model.forward, 35));
            _topPlaneNormalModelSpace   = _model.InverseTransformDirection((-_model.up).RotateAbout(_model.right, -20));
            _footToKneeLength           = fun.distance.Between(Foot.position, Shin.position);
            _kneeToHipLength            = fun.distance.Between(Shin.position, ThighBend.position);
//dbg.DrawChain(this.GetHashCode(), Color.cyan, Foot.position, Shin.position, ThighBend.position);
            _maxStretch = _footToKneeLength + _kneeToHipLength;

            IniLocalPos = _handle.localPosition;
            IniModelPos = _handle.position.AsLocalPoint(_model);
            IniLocalRot = _handle.localRotation;
            IniModelRot = lookAt(_handle.forward.AsLocalDir(_model), _handle.up.AsLocalDir(_model));
        }
Пример #2
0
        public HumSpineChain(IComplexHumanDefinition definition) : base(BodyPart.Spine)
        {
            _definition = definition;
            var spine = _definition.Spine;

            _model = _definition.Model;
            var modelFw = _model.forward;
            var modelUp = _model.up;

            Root = spine.AbdomenLower.parent;

            AbdomenLower = spine.AbdomenLower;
            AbdomenUpper = spine.AbdomenUpper;
            ChestLower   = spine.ChestLower;
            ChestUpper   = spine.ChestUpper;
            NeckLower    = spine.NeckLower;

            _locRootUp       = Root.DirTo(AbdomenLower).GetRealUp(-_model.forward).AsLocalDir(Root);
            _locRootFw       = Root.DirTo(AbdomenLower).AsLocalDir(Root);
            _handle          = CreateHandle(Root, BodyPart.Spine, false, NeckLower.position, modelFw, modelUp);
            NeckLowerHandler = new HumBoneHandler(BodyPart.Neck, _model, NeckLower);

            _handle.position = NeckLower.position;
            _handle.rotation = NeckLower.rotation;

            _prevHanPosInRootSpace = _handle.localPosition;
            _prevHanRotInRootSpace = _handle.localRotation;
            IniLocalPos            = _handle.localPosition;
            IniModelPos            = _handle.position.AsLocalPoint(_model);
            IniLocalRot            = _handle.localRotation;
            IniModelRot            = lookAt(_handle.forward.AsLocalDir(_model), _handle.up.AsLocalDir(_model));

            _allNodes = new[] { AbdomenLower, AbdomenUpper, ChestLower };
            _initialPositionsInRootSpace = new Vector3[]
            {
                AbdomenLower.position.AsLocalPoint(Root),
                AbdomenUpper.position.AsLocalPoint(Root),
                ChestLower.position.AsLocalPoint(Root),
                NeckLower.position.AsLocalPoint(Root)
            };
            _tempPositions = new Vector3[_initialPositionsInRootSpace.Length];//hip,AbdomenLower,AbdomenUpper,ChestLower,ChestUpper,NeckLower(handle)
            _tempFw        = new Vector3[_initialPositionsInRootSpace.Length];
            _handleBk      = new Vector3[_initialPositionsInRootSpace.Length];
            _rootUp        = new Vector3[_initialPositionsInRootSpace.Length];
            _joinLengths   = new []
            {
                vDist(AbdomenLower, AbdomenUpper),
                vDist(AbdomenUpper, ChestLower),
                vDist(ChestLower, NeckLower)
            };
            _defaultDistRootToNeck = vDist(Root.position, NeckLower.position);
        }
Пример #3
0
        IComplexHuman IComplexHuman.Set(IComplexHumanDefinition definition, params IHumanExtender[] extenders)
        {
            _definition = definition;
            var m = _definition.Model;

            _id = (ulong)m.GetHashCode();
//            foreach (var e in _definition.BonesByName.Values) e.gameObject.layer = layers.BitNumber_Characters;

            _sourceNeckUpper = _definition.NeckUpper.Bone;
            _sourceHead      = _definition.Head.Bone;
            _root            = _definition.Root.Bone;
            _hip             = new HumBoneHandler(m, _definition.Hip.Bone);
            _pelvis          = new HumBoneHandler(m, _definition.Pelvis.Bone);
            _spine           = new HumSpineChain(_definition);
            _neckUpper       = new HumBoneHandler(m, _definition.NeckUpper.Bone);
            _head            = new HumBoneHandler(m, _definition.Head.Bone);
            _tongue          = new HumBoneHandler(m, _definition.Tongue.Tongue2);
            //            _tongue = new GenTongueChain(_definition);
            if (_definition.HumanoidType == HumanoidType.Genesis8)
            {
                _armL = new Gen8ArmChain(BodyPart.ArmL, _definition);
                _armR = new Gen8ArmChain(BodyPart.ArmR, _definition);
            }
            else //if (_definition.HumanoidType == HumanoidType.MakeHuman)
            {
                _armL = new MHArmChain(BodyPart.ArmL, _definition);
                _armR = new MHArmChain(BodyPart.ArmR, _definition);
            }


            _legL = new HumLegChain(BodyPart.LegL, _definition);
            _legR = new HumLegChain(BodyPart.LegR, _definition);
            var humFaceConfigSource = extenders.FirstOrDefault(e => e is HumanFaceConfigSource) as HumanFaceConfigSource;

            if (_definition.HumanoidType == HumanoidType.Genesis8)
            {
                _genFace = new GenFaceGroup(this, humFaceConfigSource);
            }
            else if (_definition.HumanoidType == HumanoidType.MakeHuman)
            {
                _mhFace = new MHFaceGroup(this, humFaceConfigSource);
            }
            _collarL = new HumBoneHandler(BodyPart.CollarL, m, _definition.ArmL.Collar);
            _collarR = new HumBoneHandler(BodyPart.CollarR, m, _definition.ArmR.Collar);

            if (_definition.HasCompletedImport)
            {
                _updatables.Add(_spine);
                _updatables.Add(_legL);
                _updatables.Add(_legR);
                _updatables.Add(_armL);
                _updatables.Add(_armR);
            }

            var modelRt = m.right;
            var modelLt = -modelRt;

            if (_definition.HasCompletedImport)
            {
                if (_definition.HasBreasts)
                {
                    var breastConfigSource = extenders.FirstOrDefault(e => e is BreastConfigSource) as BreastConfigSource;
                    _breastL = new HumBreastGroup(definition.Persona, BodySide.LT, this, _definition.BreastL.Bone, _nippleL, breastConfigSource).AddTo(_updatables);
                    _breastR = new HumBreastGroup(definition.Persona, BodySide.RT, this, _definition.BreastR.Bone, _nippleR, breastConfigSource).AddTo(_updatables);
                }
            }


            foreach (var ext in (extenders ?? new IHumanExtender[0]))
            {
                ext.Setup(this);

                if (ext is IUpdatable upd)
                {
                    _updatables.Add(upd);
                }
                if (ext is IDisposable dis)
                {
                    _disposables.Add(dis);
                }
                if (ext is INamedObjectSource nts)
                {
                    _objectSources.Add(nts);
                }
            }

            _initialStats = new HumanInitialStats(this);

            return(this);
        }
Пример #4
0
        public HumBreastGroup(
            string persona,
            BodySide side,
            IComplexHuman human,
            Transform pectoral,
            HumBoneHandler nipple,
            BreastConfigSource configSource)
        {
            _persona           = persona;
            _side              = side;
            _human             = human;
            _pectoral          = pectoral;
            _nipple            = nipple;
            Part               = side == BodySide.LT ? BodyPart.BreastL : BodyPart.BreastR;
            _iniBreastLocFw    = _pectoral.forward.AsLocalDir(_pectoral.parent);
            _iniBreastLocUp    = _pectoral.up.AsLocalDir(_pectoral.parent);
            _iniWorldUpAsLocal = v3.up.AsLocalDir(_pectoral.parent);
            if (_nipple != null)
            {
                _iniNippleLocPos = _nipple.position.AsLocalPoint(_pectoral.parent);
            }
            _iniBreastLocPos = _pectoral.localPosition;

            var softBodyConfig = configSource?.GetConfig() ??
                                 new SoftBodyConfig
            {
                MaxStretch        = 0.10,
                MaxSqueeze        = 0.05,
                MaxDegrees        = 30,
                RelTargetAt       = 0.26,
                Stiffness         = 0.01,
                Mass              = 0.20,
                Damping           = 0.10,
                Gravity           = 0.05,
                RelDownResistance = 0.70
            };

            softBodyConfig.Bone = _pectoral;

//            var softBodyConfig = new SoftBodyConfig
//            {
//                Bone = _pectoral,
//                MaxStretch = 0.10,
//                MaxSqueeze = 0.05,
//                MaxDegrees = 25,
//                RelTargetAt = 0.26,
//                Stiffness = 0.05,
//                Mass = 0.50,
//                Damping = 0.50,
//                Gravity = 0.05,
//                RelDownResistance = 0.80
//            };

            fire(new RegisterSoftBodyConfig(human, side, Part, softBodyConfig));

            _jiggle = new SoftBodyJiggleAgent(softBodyConfig);

            subscribe <CancelInertia>(human, e =>
            {
                _jiggle.Pendulum.CancelInertia();
            }, this);
        }