コード例 #1
0
        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;
        }
コード例 #2
0
        public override bool OnInitialize()
        {
            base.OnInitialize();

            _numEntries  = new int[] { 0, 0 };
            _solidColors = new RGBAPixel[2];
            _constants   = new bool[] { true, true };

            _nonSpecLightId = Data->_nonSpecLightId;
            _part2Offset    = Data->_part2Offset;
            _flags1         = Data->_fixedFlags;
            _flags2         = Data->_usageFlags;
            _enableOffset   = Data->_visOffset;
            _distFunc       = Data->_distFunc;
            _spotFunc       = Data->_spotFunc;

            for (int x = 0; x < 10; x++)
            {
                SetKeys(x, new KeyframeArray(FrameCount + 1));
            }

            FixedFlags flags = (FixedFlags)_flags1;

            if (Name == "<null>")
            {
                return(false);
            }

            if (!flags.HasFlag(FixedFlags.EnabledConstant))
            {
                _entryCount = FrameCount + 1;
                int numBytes = _entryCount.Align(32) / 8;

                _data = new byte[numBytes];
                Marshal.Copy((IntPtr)Data->visBitEntries, _data, 0, numBytes);
            }
            else
            {
                _entryCount = 0;
                _data       = new byte[0];
            }

            if (flags.HasFlag(FixedFlags.ColorConstant))
            {
                _solidColors[0] = Data->_lightColor;
            }
            else
            {
                _constants[0]  = false;
                _numEntries[0] = FrameCount + 1;
                RGBAPixel *addr = Data->lightColorEntries;
                for (int x = 0; x <= FrameCount; x++)
                {
                    _lightColor.Add(*addr++);
                }
            }

            if (SpecularEnabled)
            {
                if (flags.HasFlag(FixedFlags.SpecColorConstant))
                {
                    _solidColors[1] = Data->_specularColor;
                }
                else
                {
                    _constants[1]  = false;
                    _numEntries[1] = FrameCount + 1;
                    RGBAPixel *addr = Data->specColorEntries;
                    for (int x = 0; x <= FrameCount; x++)
                    {
                        _specColor.Add(*addr++);
                    }
                }
            }

            bint *values = (bint *)&Data->_startPoint;

            int index = 0;

            for (int i = 0; i < 14; i++)
            {
                if (!(i == 3 || i == 7 || i == 10 || i == 12))
                {
                    DecodeFrames(GetKeys(index), &values[i], (int)_flags1, (int)_ordered[index++]);
                }
            }

            return(false);
        }
コード例 #3
0
        public override bool OnInitialize()
        {
            //Read common header
            base.OnInitialize();

            //Initialize defaults
            _numEntries  = new int[] { 0, 0 };
            _solidColors = new RGBAPixel[2];
            _constants   = new bool[] { true, true };

            //Read header values
            _nonSpecLightId = Data->_nonSpecLightId;
            _fixedFlags     = (FixedFlags)(ushort)Data->_fixedFlags;
            _typeUsageFlags = (ushort)Data->_usageFlags;
            _distFunc       = Data->_distFunc;
            _spotFunc       = Data->_spotFunc;

            //Read user data
            (_userEntries = new UserDataCollection()).Read(Data->UserData);

            //Don't bother reading data if the entry is null
            if (Name == "<null>")
            {
                return(false);
            }

            //Read light visibility array
            if (!_fixedFlags.HasFlag(FixedFlags.EnabledConstant) && !_replaced)
            {
                _entryCount = Scene.FrameCount;
                int numBytes = _entryCount.Align(32) / 8;

                _data = new byte[numBytes];
                Marshal.Copy((IntPtr)Data->VisBitEntries, _data, 0, numBytes);
            }
            else
            {
                _entryCount = 0;
                _data       = new byte[0];
            }

            //Read light color
            ReadColors(
                (uint)_fixedFlags,
                (uint)FixedFlags.ColorConstant,
                ref _solidColors[0],
                ref _lightColor,
                Scene.FrameCount,
                Data->_lightColor.Address,
                ref _constants[0],
                ref _numEntries[0]);

            if (!SpecularEnabled)
            {
                _constants[1] = (_fixedFlags & FixedFlags.SpecColorConstant) != 0;
                return(false);
            }

            //Read light specular color
            ReadColors(
                (uint)_fixedFlags,
                (uint)FixedFlags.SpecColorConstant,
                ref _solidColors[1],
                ref _specColor,
                Scene.FrameCount,
                Data->_specularColor.Address,
                ref _constants[1],
                ref _numEntries[1]);

            return(false);
        }