private static unsafe void WriteNormalGroup(StreamWriter writer, UnsafeBuffer norms) { writer.WriteLine(); writer.WriteLine("#Normals"); Vector3* pVert = (Vector3*)norms.Address; for (int i = 0; i < norms.Length / 12; i++) { writer.WriteLine("vn {0} {1} {2}", pVert->_x, pVert->_y, pVert->_z); pVert++; } }
public override bool OnInitialize() { base.OnInitialize(); _dataBuffer = new UnsafeBuffer(Header->_dataLength); Memory.Move(_dataBuffer.Address, Header->Data, (uint)Header->_dataLength); SetSizeInternal(Header->_dataLength); _cmds = MMLParser.Parse(Header->Data + 12); return true; }
public override void Parse(VoidPtr address) { _nameID = _name; if (_size == 0) throw new Exception("Nothing to read"); CharacterInfo cInfo = Manager.SelectedInfo; SectionParamInfo data = null; if (_name != null && cInfo._parameters.ContainsKey(_name)) { data = cInfo._parameters[_name]; _info = data._attributes; if (!String.IsNullOrEmpty(data._newName)) _name = data._newName; } else _info = new List<AttributeInfo>(); if (_size > 0) { attributeBuffer = new UnsafeBuffer(_size); byte* pOut = (byte*)attributeBuffer.Address; byte* pIn = (byte*)address; for (int i = 0; i < _size; i++) { if (i % 4 == 0) { if (data == null) { AttributeInfo info = new AttributeInfo(); //Guess if the value is a an integer or float if (((((uint)*((buint*)pIn)) >> 24) & 0xFF) != 0 && *((bint*)pIn) != -1 && !float.IsNaN(((float)*((bfloat*)pIn)))) info._type = 0; else info._type = 1; info._name = (info._type == 1 ? "*" : "") + "0x" + i.ToString("X"); info._description = "No Description Available."; _info.Add(info); } } *pOut++ = *pIn++; } } }
private UnsafeBuffer _stringBuffer; // = new UnsafeBuffer(_nameMax + _valueMax); #endregion Fields #region Constructors public XmlReader(void* pSource, int length) { _position = 0; _length = length; _base = _ptr = (byte*)pSource; _ceil = _ptr + length; _stringBuffer = new UnsafeBuffer(_nameMax + _valueMax + 2); _namePtr = (byte*)_stringBuffer.Address; _valPtr = _namePtr + _nameMax + 1; //Find start of Xml file if (BeginElement() && Name.Equals("?xml")) { while ((_ptr < _ceil) && (*_ptr++ != '>')) ; _inTag = false; } else throw new IOException("File is not a valid XML file."); }
public AssetStorage(ModelLinker linker) { int index; //Vertices if (linker.Vertices != null) { Assets[0] = new UnsafeBuffer[linker.Vertices->_numEntries]; index = 0; foreach (ResourcePair p in *linker.Vertices) Assets[0][index++] = VertexCodec.Decode((MDL0VertexData*)p.Data); } //Normals if (linker.Normals != null) { Assets[1] = new UnsafeBuffer[linker.Normals->_numEntries]; index = 0; foreach (ResourcePair p in *linker.Normals) Assets[1][index++] = VertexCodec.Decode((MDL0NormalData*)p.Data); } //Colors if (linker.Colors != null) { Assets[2] = new UnsafeBuffer[linker.Colors->_numEntries]; index = 0; foreach (ResourcePair p in *linker.Colors) Assets[2][index++] = ColorCodec.Decode((MDL0ColorData*)p.Data); } //UVs if (linker.UVs != null) { Assets[3] = new UnsafeBuffer[linker.UVs->_numEntries]; index = 0; foreach (ResourcePair p in *linker.UVs) Assets[3][index++] = VertexCodec.Decode((MDL0UVData*)p.Data); } }
public static UnsafeBuffer Decode(MDL0ColorData* header) { int count = header->_numEntries; UnsafeBuffer buffer = new UnsafeBuffer(count * 4); byte* pIn = (byte*)header + header->_dataOffset; byte* pOut = (byte*)buffer.Address; ColorCodecConverter dec; switch (header->Type) { case WiiColorComponentType.RGB565: dec = Color_wRGB565_RGBA; break; case WiiColorComponentType.RGB8: dec = Color_RGB_RGBA; break; case WiiColorComponentType.RGBA4: dec = Color_wRGBA4_RGBA; break; case WiiColorComponentType.RGBA6: dec = Color_wRGBA6_RGBA; break; case WiiColorComponentType.RGBA8: dec = Color_RGBA_RGBA; break; case WiiColorComponentType.RGBX8: dec = Color_RGBX_RGBA; break; default: return null; } while (count-- > 0) dec(ref pIn, ref pOut); return buffer; }
/** * Extracts image pixels into byte array "pixels" */ protected unsafe void GetImagePixels() { int w = image.Width; int h = image.Height; // int type = image.GetType().; if ((w != width) || (h != height) ) { // create new image with right size/format Image temp = new Bitmap(width, height ); Graphics g = Graphics.FromImage( temp ); g.DrawImage(image, 0, 0); image = temp; g.Dispose(); } pixels = new UnsafeBuffer(3 * image.Width * image.Height); byte* addr = (byte*)pixels.Address; Bitmap tempBitmap = new Bitmap( image ); for (int th = 0; th < image.Height; th++) { for (int tw = 0; tw < image.Width; tw++) { Color color = tempBitmap.GetPixel(tw, th); *addr++ = color.R; *addr++ = color.G; *addr++ = color.B; } } //pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); }
public void Dispose() { if (_graphicsBuffer != null) { _graphicsBuffer.Dispose(); _graphicsBuffer = null; } if (_faceData != null) { for (int i = 0; i < _faceData.Length; i++) if (_faceData[i] != null) { _faceData[i].Dispose(); _faceData[i] = null; } _faceData = null; } if (_indices != null) { _indices.Dispose(); _indices = null; } }
private void Apply() { if (hexBox1.ByteProvider == null) return; try { if (_section._isBSSSection != chkBSSSection.Checked || _section._isCodeSection != chkCodeSection.Checked) { _section._isBSSSection = chkBSSSection.Checked; _section._isCodeSection = chkCodeSection.Checked; _section.SignalPropertyChange(); } if (_section.Root is RELNode) { RELNode r = _section.Root as RELNode; if (r._prologReloc != _prologReloc && _prologReloc != null) { if (r._prologReloc != null) r._prologReloc._prolog = false; r._prologReloc = _prologReloc; r.SignalPropertyChange(); } if (r._epilogReloc != _epilogReloc && _epilogReloc != null) { if (r._epilogReloc != null) r._epilogReloc._epilog = false; r._epilogReloc = _epilogReloc; r.SignalPropertyChange(); } if (r._unresReloc != _unresReloc && _unresReloc != null) { if (r._unresReloc != null) r._unresReloc._unresolved = false; r._unresReloc = _unresReloc; r.SignalPropertyChange(); } } DynamicFileByteProvider d = hexBox1.ByteProvider as DynamicFileByteProvider; if (!d.HasChanges()) return; UnsafeBuffer newBuffer = new UnsafeBuffer((int)d.Length); int amt = Math.Min(_section._dataBuffer.Length, newBuffer.Length); if (amt > 0) { Memory.Move(newBuffer.Address, _section._dataBuffer.Address, (uint)amt); if (newBuffer.Length - amt > 0) Memory.Fill(newBuffer.Address + amt, (uint)(newBuffer.Length - amt), 0); } if (d._stream != null) d._stream.Dispose(); d._stream = new UnmanagedMemoryStream((byte*)newBuffer.Address, newBuffer.Length, newBuffer.Length, FileAccess.ReadWrite); d.ApplyChanges(); _section._dataBuffer.Dispose(); _section._dataBuffer = newBuffer; _section.SignalPropertyChange(); if (_relocationsChanged) { Relocation[] temp = new Relocation[_relocations.Count]; _relocations.CopyTo(temp); List<Relocation> temp2 = temp.ToList(); _section._relocations = temp2; _section._firstCommand = _firstCommand; ResourceNode a = _section.Root; if (a != null && a != _section.Root) a.SignalPropertyChange(); } hexBox1.Invalidate(); hexBox1.Focus(); } catch (Exception e) { MessageBox.Show(e.ToString()); } finally { EnableButtons(); } }
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(); }
static PrimitiveManager DecodePrimitivesUnweighted(NodeEntry n, GeometryEntry geo) { PrimitiveManager manager = DecodePrimitives(n._matrix, 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(n._matrix * 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(); return manager; }
public UnsafeBuffer GeneratePreview(Bitmap bmp) { //_blockCache.Clear(); int w = bmp.Width, h = bmp.Height; int aw = w.Align(BlockWidth), ah = h.Align(BlockHeight); UnsafeBuffer buffer = new UnsafeBuffer((aw / 4) * (ah / 4) * 8); CMPRBlock* bPtr = (CMPRBlock*)buffer.Address; //using (Bitmap bmp = src.Clone(new Rectangle(0, 0, aw, ah), PixelFormat.Format32bppArgb)) //{ // BitmapData data = bmp.LockBits(new Rectangle(0,0,aw,ah), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); // for (int y1 = 0; y1 < ah; y1 += 8) // for (int x1 = 0; x1 < aw; x1 += 8) // for (int y = 0; y < 8; y += 4) // for (int x = 0; x < 8; x += 4) // { // ARGBPixel* ptr = (ARGBPixel*)dib.Scan0 + (((y1 + y) * aw) + (x1 + x)); // CMPBlock block = CMPBlock.Encode(ptr, aw, false); // _blockCache.Add(block); // block.Decode(ptr, aw); // } //} using (DIB dib = DIB.FromBitmap(bmp, BlockWidth, BlockHeight, PixelFormat.Format32bppArgb)) { ARGBPixel* img = (ARGBPixel*)dib.Scan0; for (int y1 = 0; y1 < ah; y1 += 8) for (int x1 = 0; x1 < aw; x1 += 8) for (int y = 0; y < 8; y += 4) for (int x = 0; x < 8; x += 4) { *bPtr = NVDXT.compressDXT1a(img, x1 + x, y1 + y, aw, ah); bPtr->Decode(img, x1 + x, y1 + y, aw, ah); bPtr++; } dib.WriteBitmap(bmp, w, h); } return buffer; }
//private void ApplyTags() //{ // if (HasCode) // { // int i = 0; // foreach (Relocation r in Relocations) // { // PPCOpCode op = r.Code; // if (op is BranchOpcode) // { // BranchOpcode b = op as BranchOpcode; // if (!b.Absolute) // { // int offset = b.Offset; // int iOff = offset.RoundDown(4) / 4; // int index = i + iOff; // if (index >= 0 && index < _relocations.Count) // Relocations[index].Tags.Add(String.Format("Sub 0x{0}", PPCFormat.Hex(ASMOffset + (uint)i * 4))); // } // } // i++; // } // } //} //public void RemoveAtIndex(int index) //{ // if (_dataBuffer.Length < 4) // return; // UnsafeBuffer newBuffer = new UnsafeBuffer(_dataBuffer.Length - 4); // _relocations.RemoveAt(index); // for (int i = index; i < _relocations.Count; i++) // { // Relocation r = _relocations[i]; // foreach (Relocation l in r.Linked) // if (l.Command != null && l.Command.TargetRelocation._section == this) // l.Command._addend -= 4; // r._index--; // } // int offset = index * 4; // //Move memory before the removed value // if (offset > 0) // Memory.Move(newBuffer.Address, _dataBuffer.Address, (uint)offset); // //Move memory after the removed value // if (offset + 4 < _dataBuffer.Length) // Memory.Move(newBuffer.Address + offset, _dataBuffer.Address + offset + 4, (uint)_dataBuffer.Length - (uint)(offset + 4)); // _dataBuffer.Dispose(); // _dataBuffer = newBuffer; //} //public void InsertAtIndex(int index, Relocation r) //{ // UnsafeBuffer newBuffer = new UnsafeBuffer(_dataBuffer.Length + 4); // _relocations.Insert(index, r); // r._index = index; // for (int i = index + 1; i < _relocations.Count; i++) // { // Relocation e = _relocations[i]; // foreach (Relocation l in e.Linked) // if (l.Command != null && l.Command.TargetRelocation._section == this) // l.Command._addend += 4; // e._index++; // } // int offset = index * 4; // //Move memory before the inserted value // if (offset > 0) // Memory.Move(newBuffer.Address, _dataBuffer.Address, (uint)offset); // //Move memory after the inserted value // if (offset + 4 < _dataBuffer.Length) // Memory.Move(newBuffer.Address + offset + 4, _dataBuffer.Address + offset + 4, (uint)_dataBuffer.Length - (uint)(offset + 4)); // //Clear the new value // *(uint*)(newBuffer.Address + offset) = 0; // _dataBuffer.Dispose(); // _dataBuffer = newBuffer; //} public void Resize(int newSize) { int diff = (newSize.RoundDown(4) - _dataBuffer.Length) / 4; if (diff == 0) return; if (diff > 0) for (int i = 0; i < diff; i++) _relocations.Add(new Relocation(this, _relocations.Count)); else if (diff < 0) _relocations.RemoveRange(_relocations.Count + diff, -diff); UnsafeBuffer newBuffer = new UnsafeBuffer(newSize); int max = Math.Min(_dataBuffer.Length, newBuffer.Length); if (max > 0) Memory.Move(newBuffer.Address, _dataBuffer.Address, (uint)max); _dataBuffer.Dispose(); _dataBuffer = newBuffer; }
public override void Dispose() { if (_dataBuffer != null) { _dataBuffer.Dispose(); _dataBuffer = null; } base.Dispose(); }
private SourceEntry ParseSource() { SourceEntry src = new SourceEntry(); while (_reader.ReadAttribute()) if (_reader.Name.Equals("id", true)) src._id = (string)_reader.Value; while (_reader.BeginElement()) { if (_reader.Name.Equals("float_array", true)) { if (src._arrayType == SourceType.None) { src._arrayType = SourceType.Float; while (_reader.ReadAttribute()) if (_reader.Name.Equals("id", true)) src._arrayId = (string)_reader.Value; else if (_reader.Name.Equals("count", true)) src._arrayCount = int.Parse((string)_reader.Value); UnsafeBuffer buffer = new UnsafeBuffer(src._arrayCount * 4); src._arrayData = buffer; float* pOut = (float*)buffer.Address; for (int i = 0; i < src._arrayCount; i++) if (!_reader.ReadValue(pOut++)) break; } } else if (_reader.Name.Equals("int_array", true)) { if (src._arrayType == SourceType.None) { src._arrayType = SourceType.Int; while (_reader.ReadAttribute()) if (_reader.Name.Equals("id", true)) src._arrayId = (string)_reader.Value; else if (_reader.Name.Equals("count", true)) src._arrayCount = int.Parse((string)_reader.Value); UnsafeBuffer buffer = new UnsafeBuffer(src._arrayCount * 4); src._arrayData = buffer; int* pOut = (int*)buffer.Address; for (int i = 0; i < src._arrayCount; i++) if (!_reader.ReadValue(pOut++)) break; } } else if (_reader.Name.Equals("Name_array", true)) { if (src._arrayType == SourceType.None) { src._arrayType = SourceType.Name; while (_reader.ReadAttribute()) if (_reader.Name.Equals("id", true)) src._arrayId = (string)_reader.Value; else if (_reader.Name.Equals("count", true)) src._arrayCount = int.Parse((string)_reader.Value); string[] list = new string[src._arrayCount]; src._arrayData = list; for (int i = 0; i < src._arrayCount; i++) if (!_reader.ReadStringSingle()) break; else list[i] = (string)_reader.Value; } } else if (_reader.Name.Equals("technique_common", true)) { while (_reader.BeginElement()) { if (_reader.Name.Equals("accessor", true)) { while (_reader.ReadAttribute()) if (_reader.Name.Equals("source", true)) src._accessorSource = _reader.Value[0] == '#' ? (string)(_reader.Value + 1) : (string)_reader.Value; else if (_reader.Name.Equals("count", true)) src._accessorCount = int.Parse((string)_reader.Value); else if (_reader.Name.Equals("stride", true)) src._accessorStride = int.Parse((string)_reader.Value); //Ignore params } _reader.EndElement(); } } _reader.EndElement(); } return src; }
public void Dispose() { if (_stringBuffer != null) { _stringBuffer.Dispose(); _stringBuffer = null; } }
private static unsafe void WriteVertexGroup(StreamWriter writer, UnsafeBuffer verts) { writer.WriteLine(); writer.WriteLine("#Vertices"); Vector3* pVert = (Vector3*)verts.Address; for (int i = 0; i < verts.Length / 12; i++) { writer.WriteLine("v {0} {1} {2}", pVert->_x, pVert->_y, pVert->_z); pVert++; } }
private static unsafe void WriteUVGroup(StreamWriter writer, UnsafeBuffer uvs) { writer.WriteLine(); writer.WriteLine("#UVs"); Vector2* pVert = (Vector2*)uvs.Address; for (int i = 0; i < uvs.Length / 8; i++) { //Reverse T component to a top-down form writer.WriteLine("vt {0} {1}", pVert->_x, 1.0 - pVert->_y); pVert++; } }
/// <summary> /// Fills the data buffer with the specified amount of zerobytes. /// </summary> public void InitBuffer(uint size) { _dataBuffer = new UnsafeBuffer((int)size.RoundUp(4)); _relocations = new List<Relocation>(); for (int x = 0; x < _dataBuffer.Length / 4; x++) _relocations.Add(new Relocation(this, x)); Memory.Fill(_dataBuffer.Address, size, 0); }
public override bool OnInitialize() { base.OnInitialize(); if (WorkingUncompressed.Length == 0) SetSizeInternal(4); attributeBuffer = new UnsafeBuffer(WorkingUncompressed.Length); byte* pOut = (byte*)attributeBuffer.Address; byte* pIn = (byte*)Header; //_info = new List<AttributeInfo>(); //for (int i = 0; i < WorkingUncompressed.Length; i++) //{ // if (i % 4 == 0) // { // AttributeInfo info = new AttributeInfo(); // //Guess // if (((((uint)*((buint*)pIn)) >> 24) & 0xFF) != 0 && *((bint*)pIn) != -1 && !float.IsNaN(((float)*((bfloat*)pIn)))) // info._type = 0; // else // info._type = 1; // info._name = (info._type == 1 ? "*" : "" + (info._type > 3 ? "+" : "")) + "0x" + i.ToString("X"); // info._description = "No Description Available."; // _info.Add(info); // } // *pOut++ = *pIn++; //} return false; }
public FileMap EncodeREFTTextureCached(Bitmap src, int mipLevels, UnsafeBuffer blockBuffer) { _blockBuffer = blockBuffer; try { return base.EncodeREFTTexture(src, mipLevels, WiiPaletteFormat.IA8); } finally { _blockBuffer = null; } }
public STPMValueManager(VoidPtr address) { _values = new UnsafeBuffer(256); if (address == null) { byte* pOut = (byte*)_values.Address; for (int i = 0; i < 256; i++) *pOut++ = 0; } else { byte* pIn = (byte*)address; byte* pOut = (byte*)_values.Address; for (int i = 0; i < 256; i++) *pOut++ = *pIn++; } }
//public override FileView EncodeTexture(Bitmap src, uint mipLevels, out FileView paletteFile) //{ // _blockIndex = 0; // return base.EncodeTexture(src, mipLevels, out paletteFile); //} internal FileMap EncodeTPLTextureCached(Bitmap src, int mipLevels, UnsafeBuffer blockBuffer) { _blockBuffer = blockBuffer; try { return base.EncodeTPLTexture(src, mipLevels); } finally { _blockBuffer = null; } }
protected UnsafeBuffer thepicture; /* the input image itself */ #endregion Fields #region Constructors /* radpower for precomputation */ /* Initialise network in range (0,0,0) to (255,255,255) and set parameters ----------------------------------------------------------------------- */ public NeuQuant(UnsafeBuffer thepic, int len, int sample) { int i; int[] p; thepicture = thepic; lengthcount = len; samplefac = sample; network = new int[netsize][]; for (i = 0; i < netsize; i++) { network[i] = new int[4]; p = network[i]; p[0] = p[1] = p[2] = (i << (netbiasshift + 8)) / netsize; freq[i] = intbias / netsize; /* 1/netsize */ bias[i] = 0; } }
static PrimitiveManager DecodePrimitivesWeighted(NodeEntry n, GeometryEntry geo, SkinEntry skin, SceneEntry scene, InfluenceManager infManager, ref string Error) { PrimitiveManager manager = DecodePrimitives(n._matrix, 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; 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]; inf._weights.Add(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.Count > 1) { //Match with manager inf = infManager.FindOrCreate(inf, true); v = new Vertex3(n._matrix * skin._bindMatrix * pVert[i], inf); //World position } else { bone = inf._weights[0].Bone; v = new Vertex3(n._matrix * bone._inverseBindMatrix * skin._bindMatrix * pVert[i], 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]; Vertex3 v = null; if (*pVInd < vertList.Count) v = vertList[*pVInd]; if (v != null && v._matrixNode != null) if (v._matrixNode.Weights.Count > 1) pNorms[i] = skin._bindMatrix.GetRotationMatrix() * pNorms[i]; else pNorms[i] = skin._bindMatrix.GetRotationMatrix() * v._matrixNode.Weights[0].Bone._inverseBindMatrix.GetRotationMatrix() * pNorms[i]; } remap.Dispose(); return manager; }
/** * Flushes any pending data and closes output file. * If writing to an OutputStream, the stream is not * closed. */ public bool Finish() { if (!started) return false; bool ok = true; started = false; try { fs.WriteByte( 0x3b ); // gif trailer fs.Flush(); if (closeStream) { fs.Close(); } } catch (IOException e) { ok = false; } // reset for subsequent use transIndex = 0; fs = null; image = null; pixels = null; indexedPixels = null; colorTab = null; closeStream = false; firstFrame = true; return ok; }
public void Init(VoidPtr strmAddr, int strmLen, WaveInfo* info) { Info = *info; _streamBuffer = new UnsafeBuffer(strmLen); Memory.Move(_streamBuffer.Address, strmAddr, (uint)strmLen); _audioSource = new DataSource(_streamBuffer.Address, _streamBuffer.Length); if (info->_format._encoding == 2) _stream = new ADPCMStream(info, _audioSource.Address); else _stream = new PCMStream(info, _audioSource.Address); }
/** * Analyzes image colors and creates color map. */ protected unsafe void AnalyzePixels() { int len = pixels.Length; int nPix = len / 3; indexedPixels = new byte[nPix]; NeuQuant nq = new NeuQuant(pixels, len, sample); // initialize quantizer colorTab = nq.Process(); // create reduced palette // convert map from BGR to RGB // for (int i = 0; i < colorTab.Length; i += 3) // { // byte temp = colorTab[i]; // colorTab[i] = colorTab[i + 2]; // colorTab[i + 2] = temp; // usedEntry[i / 3] = false; // } // map image pixels to new palette byte* addr = (byte*)pixels.Address; int k = 0; for (int i = 0; i < nPix; i++) { int index = nq.Map(addr[k++] & 0xff, addr[k++] & 0xff, addr[k++] & 0xff); usedEntry[index] = true; indexedPixels[i] = (byte) index; } pixels = null; colorDepth = 8; palSize = 7; // get closest match to transparent color if specified if (transparent != Color.Empty ) { transIndex = FindClosest(transparent); } }
public void Read(Complex* iqBuffer, int length) { if (_temp == null || _temp.Length != _blockAlign * length) { _temp = new byte[_blockAlign * length]; _tempBuffer = UnsafeBuffer.Create(_temp); _tempPtr = (byte*) _tempBuffer; } var pos = 0; var size = _tempBuffer.Length; while (pos < size) { int toget = size - pos; int got = _stream.Read(_temp, pos, toget); if (got < toget) _stream.Position = _dataPos; // loop if the file ends if (got <= 0) break; pos += got; } FillIQ(iqBuffer, length); }
internal unsafe void PrepareStreamNew(int programHandle) { CalcStride(); int bufferSize = _stride * _pointCount; //Dispose of buffer if size doesn't match if ((_graphicsBuffer != null) && (_graphicsBuffer.Length != bufferSize)) { _graphicsBuffer.Dispose(); _graphicsBuffer = null; } //Create data buffer if (_graphicsBuffer == null) { _graphicsBuffer = new UnsafeBuffer(bufferSize); for (int i = 0; i < 12; i++) _dirty[i] = true; } //Update streams before binding for (int i = 0; i < 12; i++) if (_dirty[i]) UpdateStream(i); GL.BindBuffer(BufferTarget.ArrayBuffer, _arrayBufferHandle); GL.BindBuffer(BufferTarget.ElementArrayBuffer, _elementArrayBufferHandle); VoidPtr ptr = _graphicsBuffer.Address; GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(_graphicsBuffer.Length), ptr, BufferUsageHint.StreamCopy); GL.BindVertexArray(_arrayHandle); int offset = 0; int index = 0; for (int i = 0; i < 12; i++) if (_faceData[i] != null) { GL.EnableVertexAttribArray(index); switch (i) { case 0: case 1: GL.VertexAttribPointer(index, 3, VertexAttribPointerType.Float, false, _stride, offset); GL.BindAttribLocation(programHandle, index++, i == 0 ? "Position" : "Normal"); offset += 12; break; case 2: case 3: GL.VertexAttribPointer(index, 4, VertexAttribPointerType.UnsignedByte, false, _stride, offset); GL.BindAttribLocation(programHandle, index++, String.Format("Color{0}", i - 2)); offset += 4; break; default: GL.VertexAttribPointer(index, 2, VertexAttribPointerType.Float, false, _stride, offset); GL.BindAttribLocation(programHandle, index++, String.Format("UV{0}", i - 4)); offset += 8; break; } } GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.BindVertexArray(0); }