Пример #1
0
 /// <inheritdoc/>
 protected override void CreateJointEndModels(string modelName, JointConfig config)
 {
     base.CreateJointEndModels(modelName, config);
     if (modelName == ProceduralTargetJointObjectName)
     {
         var partAtTransform = new GameObject(ParkAtPartObjectName).transform;
         Hierarchy.MoveToParent(partAtTransform, partModelTransform,
                                newPosition: parkAtPart.pos,
                                newRotation: parkAtPart.rot);
     }
 }
Пример #2
0
        public static void CreateJoints(Transform root, HumanBodyBoneReferenceData r, bool isReal)
        {
            // Hip
            // Spine
            // Chest
            // Shoulder
            // Arm
            // Leg

            // Clear Colliders
            LineSphereCollider[] preColliders = root.gameObject.GetComponentsInChildren <LineSphereCollider>(true);
            for (int i = 0; i < preColliders.Length; i++)
            {
                GameObject.DestroyImmediate(preColliders[i]);
            }
            RootColliderManager[] mgs = root.gameObject.GetComponentsInChildren <RootColliderManager>(true);
            for (int i = 0; i < mgs.Length; i++)
            {
                GameObject.DestroyImmediate(mgs[i]);
            }

            Transform trsLeftUpperArm  = r._dicBones[(int)HumanBodyBones.LeftUpperArm];
            Transform trsRightUpperArm = r._dicBones[(int)HumanBodyBones.RightUpperArm];
            Transform trsLeftLowerArm  = r._dicBones[(int)HumanBodyBones.LeftLowerArm];
            Transform trsLeftUpperLeg  = r._dicBones[(int)HumanBodyBones.LeftUpperLeg];
            Transform trsLeftLowerLeg  = r._dicBones[(int)HumanBodyBones.LeftLowerLeg];

            float   upperArmDis = Vector3.Distance(trsLeftUpperArm.position, trsLeftLowerArm.position);
            float   legDis      = Vector3.Distance(trsLeftUpperLeg.position, trsLeftLowerLeg.position);
            Vector3 v2          = trsLeftUpperArm.position - trsRightUpperArm.position;
            float   torsoWidth  = v2.magnitude;

            // check Optional JointConfig
            bool hasChest    = r.CheckBone(HumanBodyBones.Chest);
            bool hasShoulder = r.CheckBone(HumanBodyBones.LeftShoulder);
            bool hasNeck     = r.CheckBone(HumanBodyBones.Neck);

            _cacheList.Clear();
            if (!hasChest)
            {
                if (hasShoulder)
                {
                    _cacheList.Add(optionalSpineWithOutChestJoint);
                }
                else
                {
                    _cacheList.Add(optionalSpineWithOutCheckShoulderJoint);
                }
                if (!hasNeck)
                {
                    _cacheList.Add(optionaSpineWithOutNeck);
                }
            }
            else
            {
                if (!hasShoulder)
                {
                    _cacheList.Add(optionalChestWithOutShoulderJoint);
                }
                if (!hasNeck)
                {
                    _cacheList.Add(optionalCheckWithOutNeck);
                }
            }

            _cacheList.AddRange(_listJointConfigs007);
            for (int i = 0; i < _cacheList.Count; i++)
            {
                JointConfig    jc       = _cacheList[i];
                HumanBodyBones rootBone = jc._rootBone;
                if (!r._dicBones.ContainsKey((int)rootBone) || (r._dicBones[(int)rootBone] == null))
                {
                    continue;
                }
                List <HumanBodyBones> jointBones = jc._bones;
                Transform             rootTrs    = r._dicBones[(int)rootBone];

                bool hasCollider = false;
                for (int boneIndex = 0; boneIndex < jointBones.Count; boneIndex++)
                {
                    HumanBodyBones bone = jointBones[boneIndex];
                    if (!r._dicBones.ContainsKey((int)jointBones[boneIndex]) ||
                        (r._dicBones[(int)jointBones[boneIndex]]) == null)
                    {
                        continue;
                    }
                    Transform          boneTrs  = r._dicBones[(int)jointBones[boneIndex]];
                    LineSphereCollider collider = rootTrs.gameObject.AddComponent <LineSphereCollider>();
                    collider._startBone = rootBone;
                    collider._endBone   = jointBones[boneIndex];
                    collider.WorldA     = rootTrs.position;
                    collider.WorldB     = boneTrs.position;

                    float a = GetRadius(upperArmDis, legDis, torsoWidth, rootBone);
                    float b = GetRadius(upperArmDis, legDis, torsoWidth, bone);

                    collider.RadiusA = a;
                    collider.RadiusB = b;
                    hasCollider      = true;
                }

                if (hasCollider)
                {
                    RootColliderManager mg = rootTrs.gameObject.AddComponent <RootColliderManager>();
                    mg.InitRootColliderManagerWhenCreate();
                }
            }
            // Debug.Log("## Create Joints Point collider over ##");
        }
Пример #3
0
 /// <summary>Creates a node.</summary>
 /// <param name="name">The string to use when making model object name.</param>
 /// <param name="config">The settings of the node.</param>
 public ModelPipeEndNode(string name, JointConfig config)
 {
     this.name   = name;
     this.config = config;
 }
Пример #4
0
        /// <summary>Builds a model for the joint end basing on the procedural configuration.</summary>
        /// <param name="modelName">Joint transform name.</param>
        /// <param name="config">Joint configuration from the part's config.</param>
        protected virtual void CreateJointEndModels(string modelName, JointConfig config)
        {
            // FIXME: Prefix the model name with the renderer name.
            // Make or get the root.
            Transform root = null;

            if (config.type == PipeEndType.PrefabModel)
            {
                root = Hierarchy.FindTransformByPath(partModelTransform, config.modelPath);
                if (root != null)
                {
                    root.parent = partModelTransform; // We need the part's model to be the root.
                    var partAttach = new GameObject(PartJointTransformName).transform;
                    Hierarchy.MoveToParent(partAttach, root,
                                           newPosition: config.partAttachAt.pos,
                                           newRotation: config.partAttachAt.rot);
                    var pipeAttach = new GameObject(PipeJointTransformName);
                    Hierarchy.MoveToParent(pipeAttach.transform, root,
                                           newPosition: config.pipeAttachAt.pos,
                                           newRotation: config.pipeAttachAt.rot);
                }
                else
                {
                    HostedDebugLog.Error(this, "Cannot find model: {0}", config.modelPath);
                    config.type = PipeEndType.Simple; // Fallback.
                }
            }
            if (root == null)
            {
                root = new GameObject().transform;
                Hierarchy.MoveToParent(root, partModelTransform);
                var partJoint = new GameObject(PartJointTransformName).transform;
                Hierarchy.MoveToParent(partJoint, root);
                partJoint.rotation = Quaternion.LookRotation(Vector3.forward);
                if (config.type == PipeEndType.ProceduralModel)
                {
                    // Create procedural models at the point where the pipe connects to the part's node.
                    var material = CreateMaterial(
                        GetTexture(config.texture),
                        mainTexNrm: config.textureNrm != "" ? GetTexture(config.textureNrm) : null);
                    var sphere = Meshes.CreateSphere(config.sphereDiameter, material, root,
                                                     colliderType: Colliders.PrimitiveCollider.Shape);
                    sphere.name = PipeJointTransformName;
                    sphere.transform.rotation = Quaternion.LookRotation(Vector3.back);
                    RescaleTextureToLength(sphere, samplesPerMeter: config.textureSamplesPerMeter);
                    if (Mathf.Abs(config.sphereOffset) > float.Epsilon)
                    {
                        sphere.transform.localPosition += new Vector3(0, 0, config.sphereOffset);
                        if (config.armDiameter > float.Epsilon)
                        {
                            var arm = Meshes.CreateCylinder(
                                config.armDiameter, config.sphereOffset, material, root,
                                colliderType: Colliders.PrimitiveCollider.Shape);
                            arm.transform.localPosition += new Vector3(0, 0, config.sphereOffset / 2);
                            arm.transform.LookAt(sphere.transform.position);
                            RescaleTextureToLength(arm, samplesPerMeter: config.textureSamplesPerMeter);
                        }
                    }
                }
                else
                {
                    // No extra models are displayed at the joint, just attach the pipe to the part's node.
                    if (config.type != PipeEndType.Simple)
                    {
                        // Normally, this error should never pop up.
                        HostedDebugLog.Error(this, "Unknown joint type: {0}", config.type);
                    }
                    var pipeJoint = new GameObject(PipeJointTransformName);
                    Hierarchy.MoveToParent(pipeJoint.transform, root);
                    pipeJoint.transform.rotation = Quaternion.LookRotation(Vector3.back);
                }
            }
            Colliders.UpdateColliders(root.gameObject, isPhysical: config.colliderIsPhysical);
            root.gameObject.SetActive(false);
            root.name = modelName;
        }