public ColorCodec(RGBAPixel[] pixels) { _srcCount = pixels.Length; _handle = GCHandle.Alloc(pixels, GCHandleType.Pinned); _pData = (RGBAPixel*)_handle.AddrOfPinnedObject(); Evaluate(); }
public static int Compare(RGBAPixel p1, RGBAPixel p2) { int v1 = *(int *)&p1; int v2 = *(int *)&p2; if (v1 > v2) { return(1); } if (v1 < v2) { return(-1); } return(1); }
public int CompareTo(object obj) { if (obj is RGBAPixel) { RGBAPixel o = (RGBAPixel)obj; if (A > o.A) { return(1); } else if (A < o.A) { return(-1); } else if (R > o.R) { return(1); } else if (R < o.R) { return(-1); } else if (G > o.G) { return(1); } else if (G < o.G) { return(-1); } else if (B > o.B) { return(1); } else if (B < o.B) { return(-1); } return(0); } return(1); }
public static int Compare(RGBAPixel p1, RGBAPixel p2) { int v1 = *(int*)&p1; int v2 = *(int*)&p2; if (v1 > v2) return 1; if (v1 < v2) return -1; return 1; }
public LightChannel(uint flags, RGBAPixel mat, RGBAPixel amb, uint color, uint alpha) { _flags = flags; _matColor = mat; _ambColor = amb; _color = new LightChannelControl(color) { _parent = this }; _alpha = new LightChannelControl(alpha) { _parent = this }; }
public LightChannel(uint flags, RGBAPixel mat, RGBAPixel amb, uint color, uint alpha, MDL0MaterialNode material) : this(flags, mat, amb, color, alpha) { _parent = material; }
internal void ApplyCLR0(CLR0Node node, int index) { if (node == null) return; CLR0MaterialNode mat = node.FindChild(Name, false) as CLR0MaterialNode; if (mat != null) foreach (CLR0MaterialEntryNode e in mat.Children) { ARGBPixel p = e.Colors.Count > index ? e.Colors[index] : new ARGBPixel(); switch (e.Target) { case EntryTarget.Ambient0: amb1 = (RGBAPixel)p; break; case EntryTarget.Ambient1: amb2 = (RGBAPixel)p; break; case EntryTarget.Color0: clr1 = (RGBAPixel)p; break; case EntryTarget.Color1: clr2 = (RGBAPixel)p; break; case EntryTarget.TevColorReg0: c1 = (GXColorS10)p; break; case EntryTarget.TevColorReg1: c2 = (GXColorS10)p; break; case EntryTarget.TevColorReg2: c3 = (GXColorS10)p; break; case EntryTarget.TevKonstReg0: k1 = (GXColorS10)p; break; case EntryTarget.TevKonstReg1: k2 = (GXColorS10)p; break; case EntryTarget.TevKonstReg2: k3 = (GXColorS10)p; break; case EntryTarget.TevKonstReg3: k4 = (GXColorS10)p; break; } } }
public override bool OnInitialize() { MDL0Material* header = Header; _initVersion = header->_pad != 0 && _replaced ? header->_pad : Model._version; if ((_name == null) && (header->_stringOffset != 0)) _name = header->ResourceString; XFCmds.Clear(); //Get XF Commands byte* pData = (byte*)header->DisplayLists(Model._version) + 0xE0; Top: if (*pData++ == 0x10) { XFData dat = new XFData(); int count = (ushort)*(bushort*)pData; pData += 2; dat.addr = (XFMemoryAddr)(ushort)*(bushort*)pData; pData += 2; dat.values = new List<uint>(); for (int i = 0; i < count + 1; i++) { dat.values.Add(*(buint*)pData); pData += 4; } XFCmds.Add(dat); goto Top; } _mdl0Offset = header->_mdl0Offset; _stringOffset = header->_stringOffset; _userDataOffset = header->UserDataOffset(_initVersion); _shaderOffset = header->_shaderOffset; _dlOffset = header->DisplayListOffset(_initVersion); _furDataOffset = header->FurDataOffset(_initVersion); _matRefOffset = header->_matRefOffset; _pad = header->_pad; _dataLen = header->_dataLen; _numTextures = header->_numTexGens; _numLights = header->_numLightChans; _usageFlags = new Bin32(header->_usageFlags); _indirectMethod1 = header->_indirectMethod1; _indirectMethod2 = header->_indirectMethod2; _indirectMethod3 = header->_indirectMethod3; _indirectMethod4 = header->_indirectMethod4; _normMapRefLight1 = header->_normMapRefLight1; _normMapRefLight2 = header->_normMapRefLight2; _normMapRefLight3 = header->_normMapRefLight3; _normMapRefLight4 = header->_normMapRefLight4; _ssc = header->_activeTEVStages; _clip = header->_numIndTexStages; _transp = header->_enableAlphaTest; _lSet = header->_lightSet; _fSet = header->_fogSet; _cull = (CullMode)(int)header->_cull; if ((-header->_mdl0Offset + (int)header->DisplayListOffset(_initVersion)) % 0x20 != 0) { Model._errors.Add("Material " + Index + " has an improper align offset."); SignalPropertyChange(); } mode = header->DisplayLists(_initVersion); _alphaFunc = mode->AlphaFunction; _zMode = mode->ZMode; _blendMode = mode->BlendMode; _constantAlpha = mode->ConstantAlpha; _tevColorBlock = *header->TevColorBlock(_initVersion); _tevKonstBlock = *header->TevKonstBlock(_initVersion); _indMtx = *header->IndMtxBlock(_initVersion); MDL0TexSRTData* TexMatrices = header->TexMatrices(_initVersion); _layerFlags = TexMatrices->_layerFlags; _texMtxFlags = TexMatrices->_mtxFlags; MDL0MaterialLighting* Light = header->Light(_initVersion); (_chan1 = Light->Channel1)._parent = this; (_chan2 = Light->Channel2)._parent = this; c1 = CReg2Color; c2 = CReg2Color; c3 = CReg2Color; k1 = KReg0Color; k2 = KReg1Color; k3 = KReg2Color; k3 = KReg3Color; clr1 = C1MaterialColor; clr2 = C2MaterialColor; amb1 = C1AmbientColor; amb2 = C2AmbientColor; (_userEntries = new UserDataCollection()).Read(header->UserData(_initVersion)); return true; }
public override void OnRebuild(VoidPtr address, int length, bool force) { base.OnRebuild(address, length, force); _matchAddr = null; SCN0AmbientLight* header = (SCN0AmbientLight*)address; header->_header._length = _length = SCN0AmbientLight.Size; if (_name != "<null>") { header->_fixedFlags = 128; header->_pad1 = 0; header->_pad2 = 0; header->_flags = usageFlags; if (_numEntries != 0) { header->_fixedFlags = 0; _matchAddr = lightAddr; if (_match == null) { *((bint*)header->_lighting.Address) = (int)lightAddr - (int)header->_lighting.Address; for (int i = 0; i <= ((SCN0Node)Parent.Parent).FrameCount; i++) if (i < _colors.Count) *lightAddr++ = (RGBAPixel)_colors[i]; else *lightAddr++ = new RGBAPixel(); } else *((bint*)header->_lighting.Address) = (int)_match._matchAddr - (int)header->_lighting.Address; } else header->_lighting = (RGBAPixel)_solidColor; } }
public void SetRGBA(int index, RGBAPixel value) { ((RGBAPixel*)_values.Address)[index] = value; }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { RGBAPixel p = new RGBAPixel(); string s = value.ToString(); string[] arr = s.Split(delims, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 4) { byte.TryParse(arr[0], out p.R); byte.TryParse(arr[1], out p.G); byte.TryParse(arr[2], out p.B); byte.TryParse(arr[3], out p.A); } //d.Color = (Color)(ARGBPixel)p; //if (!d.Visible && d.ShowDialog() == System.Windows.Forms.DialogResult.OK) // p = new RGBAPixel() { R = d.Color.R, G = d.Color.G, B = d.Color.B, A = d.Color.A }; return p; }
public ColorCodec(RGBAPixel* sPtr, int count) { _pData = sPtr; _srcCount = count; Evaluate(); }
public override void OnRebuild(VoidPtr address, int length, bool force) { base.OnRebuild(address, length, force); lightAddress = null; specularAddress = null; SCN0Light* header = (SCN0Light*)address; if (_name != "<null>") { header->_nonSpecLightId = NonSpecularLightID; header->_part2Offset = _part2Offset; header->_visOffset = _enableOffset; header->_distFunc = _distFunc; header->_spotFunc = _spotFunc; int newFlags = 0; if (_lightColor.Count > 1) { lightAddress = lightAddr; if (match2 == null) { *((bint*)header->_lightColor.Address) = (int)lightAddr - (int)header->_lightColor.Address; for (int x = 0; x <= FrameCount; x++) if (x < _lightColor.Count) *lightAddr++ = _lightColor[x]; else *lightAddr++ = new RGBAPixel(); } else *((bint*)header->_lightColor.Address) = (int)match1.lightAddress - (int)header->_lightColor.Address; } else { newFlags |= (int)FixedFlags.ColorConstant; header->_lightColor = _solidColors[0]; } if (_specColor.Count > 1) { specularAddress = lightAddr; if (match2 == null) { *((bint*)header->_specularColor.Address) = (int)lightAddr - (int)header->_specularColor.Address; for (int x = 0; x <= FrameCount; x++) if (x < _specColor.Count) *lightAddr++ = _specColor[x]; else *lightAddr++ = new RGBAPixel(); } else *((bint*)header->_specularColor.Address) = (int)match2.specularAddress - (int)header->_specularColor.Address; } else { newFlags |= (int)FixedFlags.SpecColorConstant; header->_specularColor = _solidColors[1]; } if (!SetConstant && _entryCount != 0) { header->_visOffset = (int)visAddr - (int)header->_visOffset.Address; Marshal.Copy(_data, 0, (IntPtr)visAddr, _data.Length); visAddr = ((VoidPtr)visAddr + EntryCount.Align(32) / 8); } else newFlags |= (int)FixedFlags.EnabledConstant; bint* values = (bint*)&header->_startPoint; int index = 0; for (int i = 0; i < 14; i++) if (!(i == 3 || i == 7 || i == 10 || i == 12)) EncodeFrames(GetKeys(index), ref keyframeAddr, &values[i], ref newFlags, (int)_ordered[index++]); header->_fixedFlags = _flags1 = (ushort)newFlags; header->_usageFlags = _flags2; } }
/// <summary> /// Retrieves color values from raw facedata in a remapped array. /// </summary> /// <param name="index">The color set to retrieve. Values 0 - 1</param> /// <param name="force">If not forced, will return values created by a previous call (if there was one).</param> /// <returns></returns> public RGBAPixel[] GetColors(int index, bool force) { index.Clamp(0, 1); if (_colors[index] != null && _colors[index].Length != 0 && !force) return _colors[index]; HashSet<RGBAPixel> list = new HashSet<RGBAPixel>(); if (_faceData[index + 2] != null) { RGBAPixel* pIn = (RGBAPixel*)_faceData[index + 2].Address; for (int i = 0; i < _pointCount; i++) list.Add(*pIn++); } _colors[index] = new RGBAPixel[list.Count]; list.CopyTo(_colors[index]); return _colors[index]; }
public override void OnRebuild(VoidPtr address, int length, bool force) { base.OnRebuild(address, length, force); _matchAddr = null; SCN0Fog* header = (SCN0Fog*)address; flags = SCN0FogFlags.None; if (_colors.Count > 1) { _matchAddr = lightAddr; if (_match == null) { *((bint*)header->_color.Address) = (int)lightAddr - (int)header->_color.Address; for (int i = 0; i <= ((SCN0Node)Parent.Parent).FrameCount; i++) if (i < _colors.Count) *lightAddr++ = (RGBAPixel)_colors[i]; else *lightAddr++ = new RGBAPixel(); } else *((bint*)header->_color.Address) = (int)_match._matchAddr - (int)header->_color.Address; } else { flags |= SCN0FogFlags.FixedColor; header->_color = (RGBAPixel)_solidColor; } if (_startKeys._keyCount > 1) { *((bint*)header->_start.Address) = (int)keyframeAddr - (int)header->_start.Address; EncodeFrames(_startKeys, ref keyframeAddr); } else { flags |= SCN0FogFlags.FixedStart; if (_startKeys._keyCount == 1) header->_start = _startKeys._keyRoot._next._value; else header->_start = 0; } if (_endKeys._keyCount > 1) { *((bint*)header->_end.Address) = (int)keyframeAddr - (int)header->_end.Address; EncodeFrames(_endKeys, ref keyframeAddr); } else { flags |= SCN0FogFlags.FixedEnd; if (_endKeys._keyCount == 1) header->_end = _endKeys._keyRoot._next._value; else header->_end = 0; } header->_flags = (byte)flags; header->_type = type; }