Example #1
0
            public override void Rotate(Option <Vector3> target, Vector2 offset, Vector2 influence)
            {
                Vector2 GetMorph(Vector3 t)
                {
                    var rotation = CalculateRotation(t, Transform(), offset) * influence;

                    var horizontal = (1f - YawRange.Ratio(YawRange.Clamp(rotation.x))) * 0.5f;
                    var vertical   = (1f + PitchRange.Ratio(PitchRange.Clamp(rotation.y))) * 0.5f;

                    return(new Vector2(horizontal, vertical));
                }

                var morph = target.Map(GetMorph).IfNone(new Vector2(0.5f, 0.5f));

                HorizontalControl.Position = morph.x;
                VerticalControl.Position   = morph.y;
            }
Example #2
0
            public override void Rotate(Option <Vector3> target, Vector2 offset, Vector2 influence)
            {
                var transform = Transform();

                //FIXME: A temporary workaround until godotengine/godot#33552 gets fixed.
                Skeleton.SetBoneGlobalPoseOverride(Bone, Godot.Transform.Identity, 0f, false);

                target.Iter(t =>
                {
                    var v = CalculateRotation(t, transform, offset) * influence;

                    var h = Basis.Identity.Rotated(Vector3.Up, YawRange.Clamp(v.x));
                    var r = h.Xform(Vector3.Right);

                    var global = Skeleton.GetBoneGlobalPose(Bone);

                    var rotation = h.Rotated(r, PitchRange.Clamp(v.y));
                    var rotated  = new Transform(rotation * global.basis, global.origin);

                    Skeleton.SetBoneGlobalPoseOverride(Bone, rotated, 1f, true);
                });
            }
Example #3
0
        public override object Execute(List <string> args)
        {
            if (args.Count != 0)
            {
                return(false);
            }

            var soundDataAggregate = new byte[0].AsEnumerable();

            int currentFileOffset         = 0;
            int totalSampleCount          = 0;
            int maxPermutationSampleCount = 0;


            int pitchRangeCount = GetPitchRangeCountUser();

            if (pitchRangeCount <= 0)
            {
                return(false);
            }

            //
            // Get basic information on the sounds
            //

            if (pitchRangeCount > 1)
            {
                Definition.ImportType = ImportType.MultiLayer;
            }
            else
            {
                Definition.ImportType = ImportType.SingleLayer;
            }

            Definition.SampleRate.value = GetSoundSampleRateUser();

            Definition.PlatformCodec.Compression = GetSoundCompressionUser();

            Definition.PlatformCodec.Encoding = GetSoundEncodingUser();

            Definition.PitchRanges = new List <PitchRange>();

            //
            // For each pitch range, get all the permutations and append sound data.
            //

            for (int u = 0; u < pitchRangeCount; u++)
            {
                int permutationCount = GetPermutationCountUser();

                if (permutationCount <= 0)
                {
                    return(false);
                }

                var pitchRange = new PitchRange
                {
                    ImportName           = new StringId(5221), //|default|
                    Unknown5             = -1,
                    Unknown6             = -1,
                    Unknown7             = -1,
                    Unknown8             = -1,
                    PermutationCount     = (short)permutationCount,
                    PitchRangeParameters = new PitchRangeParameter()
                };
                pitchRange.PitchRangeParameters.UnknownBounds = new Bounds <short>(-32768, 32767);

                pitchRange.Permutations = new List <Permutation>();

                //
                // Permutation section
                //

                for (int i = 0; i < permutationCount; i++)
                {
                    string soundFile = GetPermutationFileUser(i);
                    if (soundFile == null)
                    {
                        return(false);
                    }

                    int sampleCount = GetPermutationSampleCountUser(i);

                    var perm = new Permutation
                    {
                        ImportName = StringId.Invalid,
                        SampleSize = (uint)sampleCount
                    };

                    if (i != 0)
                    {
                        perm.IsNotFirstPermutation = 1;
                    }

                    perm.PermutationNumber = (uint)i;

                    var permutationData = File.ReadAllBytes(soundFile);

                    perm.PermutationChunks = new List <PermutationChunk>();

                    var chunk = new PermutationChunk(currentFileOffset, permutationData.Length);
                    perm.PermutationChunks.Add(chunk);
                    currentFileOffset += permutationData.Length;
                    totalSampleCount  += sampleCount;

                    if (maxPermutationSampleCount < sampleCount)
                    {
                        maxPermutationSampleCount = sampleCount;
                    }

                    soundDataAggregate = soundDataAggregate.Concat(permutationData);

                    pitchRange.Permutations.Add(perm);
                }

                Definition.PitchRanges.Add(pitchRange);
            }

            Definition.Promotion.LongestPermutationDuration = (uint)(1000 * (double)maxPermutationSampleCount / (Definition.SampleRate.GetSampleRateHz()));
            Definition.Promotion.TotalSampleSize            = (uint)totalSampleCount;


            // remove extra info for now

            Definition.ExtraInfo = new List <ExtraInfo>();

            //
            // Create new resource
            //

            Console.Write("Creating new sound resource...");

            var data = soundDataAggregate.ToArray();

            Definition.Unknown12 = 0;

            using (var dataStream = new MemoryStream(data))
            {
                var fileSize        = (int)dataStream.Length;
                var resourceContext = new ResourceSerializationContext(CacheContext, Definition.Resource);
                CacheContext.Serializer.Serialize(resourceContext,
                                                  new SoundResourceDefinition
                {
                    Data = new TagData(fileSize, new CacheResourceAddress(CacheResourceAddressType.Resource, 0))
                });

                Definition.Resource = new PageableResource
                {
                    Page = new RawPage
                    {
                        Index = -1
                    },
                    Resource = new TagResourceGen3
                    {
                        ResourceType      = TagResourceTypeGen3.Sound,
                        DefinitionData    = new byte[20],
                        DefinitionAddress = new CacheResourceAddress(CacheResourceAddressType.Definition, 536870912),
                        ResourceFixups    = new List <TagResourceGen3.ResourceFixup>
                        {
                            new TagResourceGen3.ResourceFixup
                            {
                                BlockOffset = 12,
                                Address     = new CacheResourceAddress(CacheResourceAddressType.Resource, 1073741824)
                            }
                        },
                        ResourceDefinitionFixups = new List <TagResourceGen3.ResourceDefinitionFixup>(),
                        Unknown2 = 1
                    }
                };

                Definition.Resource.ChangeLocation(ResourceLocation.ResourcesB);
                CacheContext.AddResource(Definition.Resource, dataStream);

                for (int i = 0; i < 4; i++)
                {
                    Definition.Resource.Resource.DefinitionData[i] = (byte)(Definition.Resource.Page.UncompressedBlockSize >> (i * 8));
                }

                Console.WriteLine("done.");
            }
            return(true);
        }
Example #4
0
        public override object Execute(List <string> args)
        {
            if (args.Count != 0)
            {
                return(false);
            }

            var soundDataAggregate = new byte[0].AsEnumerable();

            int currentFileOffset         = 0;
            int totalSampleCount          = 0;
            int maxPermutationSampleCount = 0;


            int pitchRangeCount = GetPitchRangeCountUser();

            if (pitchRangeCount <= 0)
            {
                return(false);
            }

            //
            // Get basic information on the sounds
            //

            if (pitchRangeCount > 1)
            {
                Definition.ImportType = ImportType.MultiLayer;
            }
            else
            {
                Definition.ImportType = ImportType.SingleLayer;
            }

            Definition.SampleRate.value = GetSoundSampleRateUser();

            Definition.PlatformCodec.Compression = GetSoundCompressionUser();

            Definition.PlatformCodec.Encoding = GetSoundEncodingUser();

            Definition.PitchRanges = new List <PitchRange>();

            //
            // For each pitch range, get all the permutations and append sound data.
            //

            for (int u = 0; u < pitchRangeCount; u++)
            {
                int permutationCount = GetPermutationCountUser();

                if (permutationCount <= 0)
                {
                    return(false);
                }

                var pitchRange = new PitchRange
                {
                    ImportName           = new StringId(5221), //|default|
                    Unknown5             = -1,
                    Unknown6             = -1,
                    Unknown7             = -1,
                    Unknown8             = -1,
                    PermutationCount     = (short)permutationCount,
                    PitchRangeParameters = new PitchRangeParameter()
                };
                pitchRange.PitchRangeParameters.UnknownBounds = new Bounds <short>(-32768, 32767);

                pitchRange.Permutations = new List <Permutation>();

                //
                // Permutation section
                //

                for (int i = 0; i < permutationCount; i++)
                {
                    string soundFile = GetPermutationFileUser(i);
                    if (soundFile == null)
                    {
                        return(false);
                    }

                    int sampleCount = GetPermutationSampleCountUser(i);

                    var perm = new Permutation
                    {
                        ImportName = StringId.Invalid,
                        SampleSize = (uint)sampleCount
                    };

                    if (i != 0)
                    {
                        perm.IsNotFirstPermutation = 1;
                    }

                    perm.PermutationNumber = (uint)i;

                    var permutationData = File.ReadAllBytes(soundFile);

                    perm.PermutationChunks = new List <PermutationChunk>();

                    var chunk = new PermutationChunk(currentFileOffset, permutationData.Length);
                    perm.PermutationChunks.Add(chunk);
                    currentFileOffset += permutationData.Length;
                    totalSampleCount  += sampleCount;

                    if (maxPermutationSampleCount < sampleCount)
                    {
                        maxPermutationSampleCount = sampleCount;
                    }

                    soundDataAggregate = soundDataAggregate.Concat(permutationData);

                    pitchRange.Permutations.Add(perm);
                }

                Definition.PitchRanges.Add(pitchRange);
            }

            Definition.Promotion.LongestPermutationDuration = (uint)(1000 * (double)maxPermutationSampleCount / (Definition.SampleRate.GetSampleRateHz()));
            Definition.Promotion.TotalSampleSize            = (uint)totalSampleCount;


            // remove extra info for now

            Definition.ExtraInfo = new List <ExtraInfo>();


            Definition.Unknown12 = 0;

            //
            // Create new resource
            //

            Console.Write("Creating new sound resource...");

            var data = soundDataAggregate.ToArray();
            var resourceDefinition = AudioUtils.CreateSoundResourceDefinition(data);
            var resourceReference  = Cache.ResourceCache.CreateSoundResource(resourceDefinition);

            Definition.Resource = resourceReference;

            Console.WriteLine("done.");

            return(true);
        }