コード例 #1
0
 public void Dispose()
 {
     if (_data != null)
     {
         _data.Dispose();
         _data = null;
     }
 }
コード例 #2
0
 public void Dispose()
 {
     if (_sampleBuffer != null)
     {
         _sampleBuffer.Dispose();
         _sampleBufferPtr  = null;
         _workingSamplePtr = null;
     }
 }
コード例 #3
0
 public override void Dispose()
 {
     if (_dataBuffer != null)
     {
         _dataBuffer.Dispose();
         _dataBuffer = null;
     }
     base.Dispose();
 }
コード例 #4
0
ファイル: Polygon.cs プロジェクト: soopercool101/brawltools1
 public void Dispose()
 {
     if (_indices != null)
     {
         _indices.Dispose();
         _indices = null;
     }
     if (_data != null)
     {
         _data.Dispose();
         _data = null;
     }
 }
コード例 #5
0
        public void Dispose()
        {
            for (int i = 0; i < 12; i++)
            {
                if (_faceData[i] != null)
                {
                    _faceData[i].Dispose(); _faceData[i] = null;
                }
            }

            if (_graphicsBuffer != null)
            {
                _graphicsBuffer.Dispose(); _graphicsBuffer = null;
            }
        }
コード例 #6
0
        public unsafe int Process(byte *compressed, int compressedCount, short *outBuffer, int outBufferCount)
        {
            //Allocate memory for our info struct
            UnsafeBuffer       infoP = UnsafeBuffer.Create(1, sizeof(NeAACDecFrameInfo));
            NeAACDecFrameInfo *info  = (NeAACDecFrameInfo *)infoP;

            //Process
            short *data = NeAACDecDecode(ctx, (IntPtr)infoP.Address, compressed, compressedCount);

            //Read what we need from the struct and then clean up
            int error   = info->error;
            int samples = info->samples;

            infoP.Dispose();
            info = null;

            //Validate that there were no errors
            if (error > 0)
            {
                throw new Exception($"FAAD reported an error while decoding: " + NeAACDecGetErrorMessageManaged(info->error));
            }

            //Validate we have space to copy
            if (samples > outBufferCount)
            {
                throw new Exception($"Output buffer was not large enough for the number of incoming samples, {info->samples}!");
            }

            //Copy
            Utils.Memcpy(outBuffer, data, samples * sizeof(short));

            return(samples);
        }
コード例 #7
0
 protected override void EndBenchmark()
 {
     //Clean up buffers
     iqBuffer.Dispose();
     audioABuffer.Dispose();
     audioBBuffer.Dispose();
 }
コード例 #8
0
        internal unsafe List <Vertex3> Finish(Vector3 *pVert, IMatrixNode[] nodeTable)
        {
            //Create vertex list from remap table
            List <Vertex3> list = new List <Vertex3>(RemapSize);

            if (Weighted)
            {
                ushort *pMap = (ushort *)RemapTable.Address;
                for (int i = 0; i < RemapSize; i++)
                {
                    //Create new vertex, assigning the value + influence from the remap table
                    Vertex3 v = new Vertex3(pVert[*pMap++], nodeTable[*pMap++]);
                    //Add vertex to list
                    list.Add(v);
                }
            }
            else
            {
                //Add vertex to list using raw value.
                int *pMap = (int *)RemapTable.Address;
                for (int i = 0; i < RemapSize; i++)
                {
                    list.Add(new Vertex3(pVert[*pMap++]));
                }
            }

            //Clean up
            RemapTable.Dispose();
            RemapTable = null;

            return(list);
        }
コード例 #9
0
ファイル: AptDemodulator.cs プロジェクト: Roman-Port/LibSDR
        public void Configure(float sampleRate, int bufferSize)
        {
            //Complain if too low
            if (sampleRate < BAUD_RATE)
            {
                throw new Exception($"The sample rate specified, {sampleRate}, is too low to be useful. Must be >= {BAUD_RATE}.");
            }

            //Create parts
            fmDemod = new FmBasebandDemodulator();
            fmDemod.Configure(bufferSize, sampleRate);
            amDemod          = new AmBasebandDemodulator();
            osc              = new Oscillator(sampleRate, -2400);
            symbolsPerSample = BAUD_RATE / sampleRate;

            //Make filter
            var filterBuilder = new LowPassFilterBuilder(sampleRate, 2080)
                                .SetAutomaticTapCount(200)
                                .SetWindow();

            filter = RealFirFilter.CreateFirFilter(filterBuilder);

            //Create buffer
            buffer?.Dispose();
            buffer = UnsafeBuffer.Create(bufferSize, out bufferPtr);
        }
コード例 #10
0
        static PrimitiveManager DecodePrimitivesUnweighted(GeometryEntry geo)
        {
            PrimitiveManager manager = DecodePrimitives(geo);

            Vector3 *      pVert    = null;
            ushort *       pVInd    = (ushort *)manager._indices.Address;
            int            vCount   = 0;
            List <Vertex3> vertList = new List <Vertex3>(manager._pointCount);

            manager._vertices = vertList;

            //Find vertex source
            foreach (SourceEntry s in geo._sources)
            {
                if (s._id == geo._verticesInput._source)
                {
                    UnsafeBuffer b = s._arrayData as UnsafeBuffer;
                    pVert  = (Vector3 *)b.Address;
                    vCount = b.Length / 12;
                    break;
                }
            }

            UnsafeBuffer remap  = new UnsafeBuffer(vCount * 2);
            ushort *     pRemap = (ushort *)remap.Address;

            //Create remap table
            for (int i = 0; i < vCount; i++)
            {
                //Create Vertex and look for match
                Vertex3 v = new Vertex3(pVert[i]);

                int index = 0;
                while (index < vertList.Count)
                {
                    if (v.Equals(vertList[index]))
                    {
                        break;
                    }
                    index++;
                }
                if (index == vertList.Count)
                {
                    vertList.Add(v);
                }

                pRemap[i] = (ushort)index;
            }

            //Remap vertex indices
            for (int i = 0; i < manager._pointCount; i++, pVInd++)
            {
                *pVInd = pRemap[*pVInd];
            }

            remap.Dispose();

            //manager.MergeTempData();
            return(manager);
        }
コード例 #11
0
        protected override void RedrawView()
        {
            //Save or rerender buffer
            if (backgroundBuffer == null || backgroundBuffer.Length != Width * Height)
            {
                backgroundBuffer?.Dispose();
                backgroundBuffer = UnsafeBuffer.Create(Width * Height, out backgroundBufferPtr);
                byte *bufferPtr = (byte *)GetPixelPointer(0, 0);
                for (int i = 0; i < Width * Height * 4; i++)
                {
                    bufferPtr[i] /= 2;
                }
                Utils.Memcpy(backgroundBufferPtr, GetPixelPointer(0, 0), Width * Height * sizeof(DisplayPixel));
            }
            else
            {
                Utils.Memcpy(GetPixelPointer(0, 0), backgroundBufferPtr, Width * Height * sizeof(DisplayPixel));
            }

            //Calculate offsets
            int y = (Height - WINDOW_HEIGHT) / 2;
            int x = (Width - WINDOW_WIDTH) / 2;

            //Draw background
            UtilFill(DisplayPixel.BLACK, x, y, WINDOW_WIDTH, WINDOW_HEIGHT);
            UtilFill(DisplayPixel.RED, x, y + 40, WINDOW_WIDTH, 1);
            UtilOutline(DisplayPixel.RED, x, y, WINDOW_WIDTH, WINDOW_HEIGHT, 1);

            //Draw text
            FontStore.SYSTEM_REGULAR_15.RenderPretty(GetOffsetContext(x + WINDOW_PADDING, y), title.ToCharArray(), DisplayPixel.RED, AlignHorizontal.Left, AlignVertical.Center, WINDOW_WIDTH - WINDOW_PADDING - WINDOW_PADDING, 40);
            FontStore.SYSTEM_REGULAR_15.RenderPretty(GetOffsetContext(x + WINDOW_PADDING, y + 42 + WINDOW_PADDING), message.ToCharArray(), DisplayPixel.WHITE, AlignHorizontal.Left, AlignVertical.Top, WINDOW_WIDTH - WINDOW_PADDING - WINDOW_PADDING, WINDOW_HEIGHT - WINDOW_PADDING - 42);
        }
コード例 #12
0
        public void AddScaledFrame(float *ptr, int width)
        {
            //Ensure
            if (width != Width)
            {
                return;
            }

            //If the array size is incorrect, create
            if (fftBuffer == null || fftBuffer.Length - 2 != width)
            {
                fftBuffer?.Dispose();
                fftBuffer = UnsafeBuffer.Create(width + 2, sizeof(int));
                fftPtr    = ((float *)fftBuffer) + 1;
            }

            //Copy FFT frame
            Utils.Memcpy(fftPtr, ptr, Width * sizeof(float));

            //Convert and fill padding
            for (int i = 0; i < Width; i++)
            {
                fftPtr[i] = ((Math.Abs(fftPtr[i]) + fftOffset) / fftRange) * Height;
            }
            fftPtr[-1]    = fftPtr[0];
            fftPtr[Width] = fftPtr[Width - 1];

            //Invalidate
            Invalidate();
        }
コード例 #13
0
 public void Dispose()
 {
     if (_indices != null)
     {
         _indices.Dispose();
         _indices = null;
     }
 }
コード例 #14
0
ファイル: XmlReader.cs プロジェクト: 0000duck/brawltools
 public void Dispose()
 {
     if (_stringBuffer != null)
     {
         _stringBuffer.Dispose();
         _stringBuffer = null;
     }
 }
コード例 #15
0
        private void SendSYSMagic(ushort offset, uint length, byte[] magic)
        {
            UnsafeBuffer data    = UnsafeBuffer.Create(magic);
            byte *       dataPtr = (byte *)data;

            NativeMethods.RTK_SYS_Byte_Write(offset, length, dataPtr);

            data.Dispose();
        }
コード例 #16
0
        private void SendDemodMagic(byte page, ushort offset, uint length, byte[] magic)
        {
            UnsafeBuffer data    = UnsafeBuffer.Create(magic);
            byte *       dataPtr = (byte *)data;

            NativeMethods.RTK_Demod_Byte_Write(page, offset, length, dataPtr);

            data.Dispose();
        }
コード例 #17
0
ファイル: Aeron.cs プロジェクト: yksi7417/Aeron.NET
 /// <summary>
 /// Clean up all resources that the client uses to communicate with the Media Driver.
 /// </summary>
 public void Dispose()
 {
     if (_isClosed.CompareAndSet(false, true))
     {
         _cncMetaDataBuffer?.Dispose();
         _countersMetaDataBuffer?.Dispose();
         _countersValuesBuffer?.Dispose();
         _cncByteBuffer?.Dispose();
     }
 }
コード例 #18
0
        private void RecreateBuffers()
        {
            //Destory buffers
            waterfallBuffer?.Dispose();
            waterfallQueueBuffer?.Dispose();

            //Create buffers
            waterfallBuffer         = UnsafeBuffer.Create(Width * Height, sizeof(DisplayPixel));
            waterfallBufferPtr      = (DisplayPixel *)waterfallBuffer;
            waterfallQueueBuffer    = UnsafeBuffer.Create(Width, sizeof(DisplayPixel));
            waterfallQueueBufferPtr = (DisplayPixel *)waterfallQueueBuffer;
        }
コード例 #19
0
        public void Close()
        {
            if (!_publication.IsClosed)
            {
                _log.InfoFormat("Closing transport for channel [{0}] and stream [{1}]", _channel, _stream);
                _publication.Dispose();
                _buffer.Dispose();
                _log.InfoFormat("Closed transport for channel [{0}] and stream [{1}]", _channel, _stream);
            }
            else
            {
                var message = string.Format(
                    "Cannot close transport for channel [{0}] and stream [{1}]; transport is already closed",
                    _channel,
                    _stream
                    );

                _log.Warn(message);
                throw new InvalidOperationException(message);
            }
        }
コード例 #20
0
 public void Dispose()
 {
     if (m_iqBuffer != null)
     {
         m_iqBuffer.Dispose();
         m_iqBuffer    = null;
         m_iqBufferPtr = null;
     }
     if (m_gui != null)
     {
         m_gui.Dispose();
     }
     GC.SuppressFinalize(this);
 }
コード例 #21
0
        private void CanvasPreview_SizeChanged(object sender, EventArgs e)
        {
            //Set settings
            imageBufferWidth  = previewCanvas.Width;
            imageBufferHeight = previewCanvas.Height;

            //Create new image buffer
            imageBuffer?.Dispose();
            imageBuffer = UnsafeBuffer.Create(imageBufferWidth * imageBufferHeight, out imageBufferPtr);

            //Configure scroll
            ConfigureScrollbar();

            //Apply
            previewCanvas.Image = new Bitmap(imageBufferWidth, imageBufferHeight, imageBufferWidth * sizeof(UnsafeColor), System.Drawing.Imaging.PixelFormat.Format32bppArgb, (IntPtr)imageBufferPtr);
        }
コード例 #22
0
ファイル: CodecTests.cs プロジェクト: mpvyard/Minotaur
        private static void CheckCodec <T>(ICodec <T> codec, int count)
            where T : unmanaged
        {
            var data    = Factory.CreateRandomBytes(count * sizeof(T));
            var encoded = new UnsafeBuffer(codec.GetMaxEncodedSize(data.Length));
            var decoded = new UnsafeBuffer(data.Length);

            int length;

            fixed(byte *p = data)
            length = codec.Encode((T *)p, count, encoded.Ptr);

            var result = codec.Decode(encoded.Ptr, length, (T *)decoded.Ptr);

            Assert.AreEqual(count, result, "Mismatch number of decoded data");
            data.Check(decoded.Data);

            decoded.Dispose();
            encoded.Dispose();
        }
コード例 #23
0
        public override void Dispose()
        {
            if (_audioSource != null)
            {
                _audioSource.Close();
            }

            if (_stream != null)
            {
                _stream.Dispose();
                _stream = null;
            }

            if (_streamBuffer != null)
            {
                _streamBuffer.Dispose();
                _streamBuffer = null;
            }

            base.Dispose();
        }
コード例 #24
0
ファイル: Primitive.cs プロジェクト: KingAtreyu/super-sawndz
 public void Dispose()
 {
     if (_precVertices != null)
     {
         _precVertices.Dispose(); _precVertices = null;
     }
     if (_precNormals != null)
     {
         _precNormals.Dispose(); _precNormals = null;
     }
     if (_precColors != null)
     {
         _precColors.Dispose(); _precColors = null;
     }
     for (int i = 0; i < 8; i++)
     {
         if (_precUVs[i] != null)
         {
             _precUVs[i].Dispose(); _precUVs[i] = null;
         }
     }
 }
コード例 #25
0
        static PrimitiveManager DecodePrimitivesWeighted(GeometryEntry geo, SkinEntry skin, SceneEntry scene, InfluenceManager infManager, ref string Error)
        {
            PrimitiveManager manager = DecodePrimitives(geo);

            MDL0BoneNode[] boneList;
            MDL0BoneNode   bone = null;
            int            boneCount;

            string[]       jointStrings = null;
            byte *         pCmd = stackalloc byte[4];
            int            cmdCount = skin._weightInputs.Count;
            float          weight = 0;
            float *        pWeights = null;
            Vector3 *      pVert = null, pNorms = null;
            ushort *       pVInd    = (ushort *)manager._indices.Address;
            List <Vertex3> vertList = new List <Vertex3>(skin._weightCount);
            Matrix *       pMatrix  = null;

            UnsafeBuffer remap  = new UnsafeBuffer(skin._weightCount * 2);
            ushort *     pRemap = (ushort *)remap.Address;

            pNorms = (Vector3 *)manager._faceData[1].Address;
            //List<int> FixedIndices = new List<int>();

            manager._vertices = vertList;

            //Find vertex source
            foreach (SourceEntry s in geo._sources)
            {
                if (s._id == geo._verticesInput._source)
                {
                    pVert = (Vector3 *)((UnsafeBuffer)s._arrayData).Address;
                    break;
                }
            }

            //Find joint source
            foreach (InputEntry inp in skin._jointInputs)
            {
                if (inp._semantic == SemanticType.JOINT)
                {
                    foreach (SourceEntry src in skin._sources)
                    {
                        if (src._id == inp._source)
                        {
                            jointStrings = src._arrayData as string[];
                            break;
                        }
                    }
                }
                else if (inp._semantic == SemanticType.INV_BIND_MATRIX)
                {
                    foreach (SourceEntry src in skin._sources)
                    {
                        if (src._id == inp._source)
                        {
                            pMatrix = (Matrix *)((UnsafeBuffer)src._arrayData).Address;
                            break;
                        }
                    }
                }
            }

            Error = "There was a problem creating the list of bones for geometry entry " + geo._name;

            //Populate bone list
            boneCount = jointStrings.Length;
            boneList  = new MDL0BoneNode[boneCount];
            for (int i = 0; i < boneCount; i++)
            {
                boneList[i] = scene.FindNode(jointStrings[i])._node as MDL0BoneNode;
            }

            //Build command list
            foreach (InputEntry inp in skin._weightInputs)
            {
                switch (inp._semantic)
                {
                case SemanticType.JOINT:
                    pCmd[inp._offset] = 1;
                    break;

                case SemanticType.WEIGHT:
                    pCmd[inp._offset] = 2;

                    //Get weight source
                    foreach (SourceEntry src in skin._sources)
                    {
                        if (src._id == inp._source)
                        {
                            pWeights = (float *)((UnsafeBuffer)src._arrayData).Address;
                            break;
                        }
                    }

                    break;

                default:
                    pCmd[inp._offset] = 0;
                    break;
                }
            }

            Error = "There was a problem creating vertex influences for geometry entry " + geo._name;

            //Build vertex list and remap table
            for (int i = 0; i < skin._weightCount; i++)
            {
                //Create influence
                int       iCount = skin._weights[i].Length / cmdCount;
                Influence inf    = new Influence(iCount);
                fixed(int *p = skin._weights[i])
                {
                    int *iPtr = p;

                    for (int x = 0; x < iCount; x++)
                    {
                        for (int z = 0; z < cmdCount; z++, iPtr++)
                        {
                            if (pCmd[z] == 1)
                            {
                                bone = boneList[*iPtr];
                            }
                            else if (pCmd[z] == 2)
                            {
                                weight = pWeights[*iPtr];
                            }
                        }
                        //if (bone != null)
                        //    if (bone.Name == "TopN" || bone.Name == "XRotN" || bone.Name == "YRotN" || bone.Name == "TransN" || bone.Name == "ThrowN" || bone.Name == "FacePattern")
                        //        Console.WriteLine(bone.Name);
                        //    else if (bone.Parent != null)
                        //        if (bone.Parent.Name == "FacePattern")
                        //            Console.WriteLine(bone.Name);
                        inf._weights[x] = new BoneWeight(bone, weight);
                    }
                }

                inf.CalcMatrix();

                Error = "There was a problem creating a vertex from the geometry entry " + geo._name + ".\nMake sure that all the vertices are weighted properly.";

                Vertex3 v;
                if (inf._weights.Length > 1)
                {
                    //Match with manager
                    inf = infManager.AddOrCreate(inf);
                    v   = new Vertex3(skin._bindMatrix * pVert[i], inf); //World position
                }
                else
                {
                    bone = inf._weights[0].Bone;
                    v    = new Vertex3(bone._inverseBindMatrix * skin._bindMatrix * pVert[i], bone); //Local position
                }

                ////Create Vertex, set to world position.
                //v = new Vertex3(skin._bindMatrix * pVert[i], inf);
                ////Fix single-bind vertices
                //v.Position = inf._weights[0].Bone._inverseBindMatrix * v.Position;

                ushort index = 0;
                while (index < vertList.Count)
                {
                    if (v.Equals(vertList[index]))
                    {
                        break;
                    }
                    index++;
                }
                if (index == vertList.Count)
                {
                    vertList.Add(v);
                }

                pRemap[i] = index;
            }

            Error = "There was a problem fixing normal rotations for geometry entry " + geo._name;

            //Remap vertex indices and fix normals
            for (int i = 0; i < manager._pointCount; i++, pVInd++)
            {
                *       pVInd = pRemap[*pVInd];
                Vertex3 v     = null;
                if (*pVInd < vertList.Count)
                {
                    v = vertList[*pVInd];
                }
                if (v != null && v._influence != null)
                {
                    if (v._influence.Weights.Length > 1)
                    {
                        pNorms[i] = skin._bindMatrix.GetRotationMatrix() * pNorms[i];
                    }
                    else
                    {
                        pNorms[i] = skin._bindMatrix.GetRotationMatrix() * v._influence.Weights[0].Bone._inverseBindMatrix.GetRotationMatrix() * pNorms[i];
                    }
                }
            }

            remap.Dispose();

            //manager.MergeTempData();
            return(manager);
        }
コード例 #26
0
        private void PatchPointers()
        {
            _buffer?.Dispose();

            //Make a copy of the file's data that we can patch with offsets
            _buffer = new UnsafeBuffer(WorkingUncompressed.Length);
            Memory.Move(_buffer.Address, WorkingUncompressed.Address, (uint)WorkingUncompressed.Length);

            HKXHeader *           header  = (HKXHeader *)_buffer.Address;
            PhysicsOffsetSection *section = header->OffsetSections;

            for (int i = 0; i < header->_sectionCount; i++, section++)
            {
                int     dataOffset = section->_dataOffset;
                VoidPtr data = _buffer.Address + dataOffset;
                int     local = section->LocalPatchesLength, global = section->GlobalPatchesLength;

                if (section->ExportsLength > 0)
                {
                    Console.WriteLine("Has exports");
                }

                if (section->ImportsLength > 0)
                {
                    Console.WriteLine("Has imports");
                }

                //Global patches have to be made before local ones
                if (global > 0)
                {
                    //Global patches set offsets from this section to data in another section (or this one)
                    VoidPtr      start = data + section->_globalPatchesOffset;
                    GlobalPatch *patch = (GlobalPatch *)start;
                    while ((int)patch - (int)start < global && patch->_dataOffset >= 0 && patch->_pointerOffset >= 0)
                    {
                        //Make the pointer offset relative to itself so it's self-contained
                        int   ptrOffset = patch->_pointerOffset;
                        bint *ptr       = (bint *)(data + ptrOffset);
                        PhysicsOffsetSection *otherSection = &header->OffsetSections[patch->_sectionIndex];
                        int dOffset = patch->_dataOffset + otherSection->_dataOffset - dataOffset;
                        int offset  = dOffset - ptrOffset;
                        *   ptr     = offset;
                        patch++;
                    }
                }

                if (local > 0)
                {
                    //Local patches set offsets to data located elsewhere in this section
                    VoidPtr     start = data + section->_localPatchesOffset;
                    LocalPatch *patch = (LocalPatch *)start;
                    while ((int)patch - (int)start < local && patch->_dataOffset >= 0)
                    {
                        //Make the pointer offset relative to itself so it's self-contained
                        int   ptrOffset = patch->_pointerOffset;
                        bint *ptr       = (bint *)(data + ptrOffset);
                        *     ptr       = patch->_dataOffset - ptrOffset;
                        patch++;
                    }
                }
            }
        }
コード例 #27
0
 public void OnClosed()
 {
     backgroundBuffer.Dispose();
     backgroundBuffer = null;
 }
コード例 #28
0
 public override void Dispose()
 {
     _internalBuffer?.Dispose();
     _internalBuffer = null;
     base.Dispose();
 }
コード例 #29
0
        private static PrimitiveManager DecodePrimitivesWeighted(
            Matrix bindMatrix,
            GeometryEntry geo,
            SkinEntry skin,
            SceneEntry scene,
            InfluenceManager infManager,
            Type boneType)
        {
            PrimitiveManager manager = DecodePrimitives(geo);

            IBoneNode[] boneList;
            IBoneNode   bone = null;
            int         boneCount;

            string[] jointStringArray = null;
            string   jointString      = null;

            byte *         pCmd = stackalloc byte[4];
            int            cmdCount = skin._weightInputs.Count;
            float          weight = 0;
            float *        pWeights = null;
            Vector3 *      pVert = null, pNorms = null;
            ushort *       pVInd    = (ushort *)manager._indices.Address;
            List <Vertex3> vertList = new List <Vertex3>(skin._weightCount);
            Matrix *       pMatrix  = null;

            UnsafeBuffer remap  = new UnsafeBuffer(skin._weightCount * 2);
            ushort *     pRemap = (ushort *)remap.Address;

            if (manager._faceData[1] != null)
            {
                pNorms = (Vector3 *)manager._faceData[1].Address;
            }

            manager._vertices = vertList;

            //Find vertex source
            foreach (SourceEntry s in geo._sources)
            {
                if (s._id == geo._verticesInput._source)
                {
                    pVert = (Vector3 *)((UnsafeBuffer)s._arrayData).Address;
                    break;
                }
            }

            //Find joint source
            foreach (InputEntry inp in skin._jointInputs)
            {
                if (inp._semantic == SemanticType.JOINT)
                {
                    foreach (SourceEntry src in skin._sources)
                    {
                        if (src._id == inp._source)
                        {
                            jointStringArray = src._arrayData as string[];
                            jointString      = src._arrayDataString;
                            break;
                        }
                    }
                }
                else if (inp._semantic == SemanticType.INV_BIND_MATRIX)
                {
                    foreach (SourceEntry src in skin._sources)
                    {
                        if (src._id == inp._source)
                        {
                            pMatrix = (Matrix *)((UnsafeBuffer)src._arrayData).Address;
                            break;
                        }
                    }
                }
            }

            Error = "There was a problem creating the list of bones for geometry entry " + geo._name;

            //Populate bone list
            boneCount = jointStringArray.Length;
            boneList  = new IBoneNode[boneCount];
            for (int i = 0; i < boneCount; i++)
            {
                NodeEntry entry = scene.FindNode(jointStringArray[i]);
                if (entry != null && entry._node != null)
                {
                    boneList[i] = entry._node as IBoneNode;
                }
                else
                {
                    //Search in reverse!
                    foreach (NodeEntry node in scene._nodes)
                    {
                        if ((entry = RecursiveTestNode(jointString, node)) != null)
                        {
                            if (entry._node != null)
                            {
                                boneList[i] = entry._node as IBoneNode;
                            }

                            break;
                        }
                    }

                    //Couldn't find the bone
                    if (boneList[i] == null)
                    {
                        boneList[i] = Activator.CreateInstance(boneType) as IBoneNode;
                    }
                }
            }

            //Build command list
            foreach (InputEntry inp in skin._weightInputs)
            {
                switch (inp._semantic)
                {
                case SemanticType.JOINT:
                    pCmd[inp._offset] = 1;
                    break;

                case SemanticType.WEIGHT:
                    pCmd[inp._offset] = 2;

                    //Get weight source
                    foreach (SourceEntry src in skin._sources)
                    {
                        if (src._id == inp._source)
                        {
                            pWeights = (float *)((UnsafeBuffer)src._arrayData).Address;
                            break;
                        }
                    }

                    break;

                default:
                    pCmd[inp._offset] = 0;
                    break;
                }
            }

            Error = "There was a problem creating vertex influences for geometry entry " + geo._name;

            //Build vertex list and remap table
            for (int i = 0; i < skin._weightCount; i++)
            {
                //Create influence
                int       iCount = skin._weights[i].Length / cmdCount;
                Influence inf    = new Influence();
                fixed(int *p = skin._weights[i])
                {
                    int *iPtr = p;

                    for (int x = 0; x < iCount; x++)
                    {
                        for (int z = 0; z < cmdCount; z++, iPtr++)
                        {
                            if (pCmd[z] == 1)
                            {
                                bone = boneList[*iPtr];
                            }
                            else if (pCmd[z] == 2)
                            {
                                weight = pWeights[*iPtr];
                            }
                        }

                        inf.AddWeight(new BoneWeight(bone, weight));
                    }
                }

                inf.CalcMatrix();

                Error = "There was a problem creating a vertex from the geometry entry " + geo._name +
                        ".\nMake sure that all the vertices are weighted properly.";

                Vector3 worldPos = bindMatrix * skin._bindMatrix * pVert[i];
                Vertex3 v;
                if (inf.Weights.Count > 1)
                {
                    //Match with manager
                    inf = infManager.FindOrCreate(inf);
                    v   = new Vertex3(worldPos, inf); //World position
                }
                else
                {
                    bone = inf.Weights[0].Bone;
                    v    = new Vertex3(bone.InverseBindMatrix * worldPos, bone); //Local position
                }

                ushort index = 0;
                while (index < vertList.Count)
                {
                    if (v.Equals(vertList[index]))
                    {
                        break;
                    }

                    index++;
                }

                if (index == vertList.Count)
                {
                    vertList.Add(v);
                }

                pRemap[i] = index;
            }

            Error = "There was a problem fixing normal rotations for geometry entry " + geo._name;

            //Remap vertex indices and fix normals
            for (int i = 0; i < manager._pointCount; i++, pVInd++)
            {
                *pVInd = pRemap[*pVInd];

                if (pNorms != null)
                {
                    Vertex3 v = null;
                    if (*pVInd < vertList.Count)
                    {
                        v = vertList[*pVInd];
                    }

                    if (v != null && v.MatrixNode != null)
                    {
                        if (v.MatrixNode.Weights.Count > 1)
                        {
                            pNorms[i] =
                                (bindMatrix *
                                 skin._bindMatrix).GetRotationMatrix() *
                                pNorms[i];
                        }
                        else
                        {
                            pNorms[i] =
                                (v.MatrixNode.Weights[0].Bone.InverseBindMatrix *
                                 bindMatrix *
                                 skin._bindMatrix).GetRotationMatrix() *
                                pNorms[i];
                        }
                    }
                }
            }

            remap.Dispose();
            return(manager);
        }
コード例 #30
0
 public void Dispose()
 {
     fir_kernel_buffer.Dispose();
     fir_queue_buffer.Dispose();
     delay_line_buffer.Dispose();
 }