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; } }
public override void OnRebuild(VoidPtr address, int length, bool force) { //Build common header base.OnRebuild(address, length, force); //Reset addresses _lightAddress = null; _specularAddress = null; //Don't write anything if this node is null if (_name == "<null>") { return; } //Write header information SCN0Light *header = (SCN0Light *)address; header->_nonSpecLightId = NonSpecularLightID; header->_userDataOffset = 0; header->_distFunc = _distFunc; header->_spotFunc = _spotFunc; int newFlags = 0; //Encode keyframe data for (int i = 0, index = 0; i < 14; i++) { if (!(i == 3 || i == 7 || i == 10 || i == 12)) { _dataAddrs[0] += EncodeKeyframes( Keyframes[index], _dataAddrs[0], header->_startPoint._x.Address + i * 4, ref newFlags, (int)_ordered[index++]); } } _dataAddrs[1] += WriteColors( ref newFlags, (int)FixedFlags.ColorConstant, _solidColors[0], _lightColor, _constants[0], FrameCount, header->_lightColor.Address, ref _lightAddress, _matches[0] == null ? null : _matches[0]._lightAddress, (RGBAPixel *)_dataAddrs[1]); //Only bother writing if specular is enabled if (SpecularEnabled) { _dataAddrs[1] += WriteColors( ref newFlags, (int)FixedFlags.SpecColorConstant, _solidColors[1], _specColor, _constants[1], FrameCount, header->_specularColor.Address, ref _specularAddress, _matches[1] == null ? null : _matches[1]._specularAddress, (RGBAPixel *)_dataAddrs[1]); } else { //The value is set to 0 header->_specularColor = new RGBAPixel(); //The flag, while unused, seems to be set to the same state as the color constant flag if (_constants[0]) { newFlags |= (int)FixedFlags.SpecColorConstant; } else { newFlags &= (int)~FixedFlags.SpecColorConstant; } } if (!ConstantVisibility && _entryCount != 0) { header->_visOffset = (int)_dataAddrs[2] - (int)header->_visOffset.Address; Marshal.Copy(_data, 0, (IntPtr)_dataAddrs[2], _data.Length); _dataAddrs[2] = ((VoidPtr)_dataAddrs[2] + EntryCount.Align(32) / 8); } else { newFlags |= (int)FixedFlags.EnabledConstant; } //Set newly calculated flags header->_fixedFlags = (ushort)(_fixedFlags = (FixedFlags)newFlags); header->_usageFlags = _typeUsageFlags._data; }