コード例 #1
0
        /// <summary>
        /// Loads part data from the given suffix and model name.
        /// This will attach the part to a joint of the current actor model and add to the PartActors list.
        /// </summary>
        public void LoadPart(string suffix, string modelName)
        {
            string path = $"{GlobalSettings.GamePath}\\ObjectData\\{modelName}.szs";

            if (!File.Exists(path))
            {
                Console.WriteLine($"Failed to find part at path {path}!");
                return;
            }

            //Init parameter data
            var partParams = Files[$"InitPartsFixInfo{suffix}.byml"];
            var partModel  = new PartsModel(ByamlFile.LoadN(partParams.FileData).RootNode);

            var actor = new ActorBase();

            actor.LoadActor(path);
            PartActors.Add(modelName, actor);

            if (actor.ModelFile == null)
            {
                Console.WriteLine($"Failed to find model for {modelName}!");
                return;
            }
            //Parts attach to joints of the current model from the part model
            AttachJoint(partModel, actor.ModelFile);
        }
コード例 #2
0
        private void AttachJoint(PartsModel partInfo, IRenderableFile actorRender)
        {
            var modelPart = actorRender.Renderer.Models[0];

            foreach (ModelAsset model in ModelFile.Renderer.Models)
            {
                var bone = model.ModelData.Skeleton.SearchBone(partInfo.JointName);

                if (bone != null)
                {
                    //Setup local transform
                    var localPosition = new OpenTK.Vector3(
                        partInfo.LocalTranslate.X,
                        partInfo.LocalTranslate.Y,
                        partInfo.LocalTranslate.Z);
                    var localRotation = STMath.FromEulerAngles(new OpenTK.Vector3(
                                                                   partInfo.LocalRotate.X,
                                                                   partInfo.LocalRotate.Y,
                                                                   partInfo.LocalRotate.Z) * STMath.Deg2Rad);
                    var localScale = new OpenTK.Vector3(
                        partInfo.LocalScale.X,
                        partInfo.LocalScale.Y,
                        partInfo.LocalScale.Z);

                    modelPart.ModelData.Skeleton.LocalTransform =
                        OpenTK.Matrix4.CreateScale(localScale) *
                        OpenTK.Matrix4.CreateFromQuaternion(localRotation) *
                        OpenTK.Matrix4.CreateTranslation(localPosition);

                    //Attach bone children
                    bone.AttachSkeleton(modelPart.ModelData.Skeleton);
                    model.ModelData.Skeleton.Update();
                    break;
                }
            }
        }