コード例 #1
0
        protected virtual void buildUvs(UVChannelFlags channel)
        {
            using (new ProfilerSample("Build Uvs"))
            {
                var uvs        = MeshCache.GetUvs(_generation.graphic.mesh, channel);
                var targetList = _generation.uvs[channel.Index()];

                targetList.AddRange(uvs);

                //If we cannot remap this channel, just return
                if ((_generation.graphic.remappableChannels & channel) == 0)
                {
                    return;
                }

                UnityEngine.Object key;
                if (_textureFeatures.Count > 0)
                {
                    key = _textureFeatures[0].featureData[_generation.graphicIndex].texture;
                }
                else if (_spriteFeatures.Count > 0)
                {
                    key = _spriteFeatures[0].featureData[_generation.graphicIndex].sprite;
                }
                else
                {
                    return;
                }

                Rect rect = _atlasUvs.GetRect(channel.Index(), key);
                MeshUtil.RemapUvs(targetList, rect, uvs.Count);
            }
        }
コード例 #2
0
        private void doPerChannelPack(ProgressBar progress, UVChannelFlags channel, Texture2D[] packedTextures, AtlasUvs channelMapping)
        {
            var mainTextureFeature = _features.Query().FirstOrDefault(f => f.channel == channel);

            if (mainTextureFeature == null)
            {
                return;
            }

            Texture2D defaultTexture, packedTexture;

            Texture2D[] rawTextureArray, processedTextureArray;

            progress.Step("Prepare " + channel);
            prepareForPacking(mainTextureFeature, out defaultTexture,
                              out packedTexture,
                              out rawTextureArray,
                              out processedTextureArray);

            progress.Step("Pack " + channel);
            var packedRects = packedTexture.PackTextures(processedTextureArray,
                                                         _padding,
                                                         _maxAtlasSize,
                                                         makeNoLongerReadable: false);

            packedTexture.Apply(updateMipmaps: true, makeNoLongerReadable: true);
            packedTextures[_features.IndexOf(mainTextureFeature)] = packedTexture;

            packSecondaryTextures(progress, channel, mainTextureFeature, packedTexture, packedRects, packedTextures);

            //Correct uvs to account for the added border
            for (int i = 0; i < packedRects.Length; i++)
            {
                float dx = 1.0f / packedTexture.width;
                float dy = 1.0f / packedTexture.height;
                Rect  r  = packedRects[i];

                if (processedTextureArray[i] != defaultTexture)
                {
                    dx *= _border;
                    dy *= _border;
                }

                r.x           += dx;
                r.y           += dy;
                r.width       -= dx * 2;
                r.height      -= dy * 2;
                packedRects[i] = r;
            }

            for (int i = 0; i < rawTextureArray.Length; i++)
            {
                channelMapping.SetRect(channel.Index(), rawTextureArray[i], packedRects[i]);
            }
        }
コード例 #3
0
        private void packSecondaryTextures(ProgressBar progress, UVChannelFlags channel, LeapTextureFeature mainFeature, Texture2D packedTexture, Rect[] packedRects, Texture2D[] packedTextures)
        {
            //All texture features that are NOT the main texture do not get their own atlas step
            //They are simply copied into a new texture
            var nonMainFeatures = _features.Query().Where(f => f.channel == channel).Skip(1).ToList();

            progress.Begin(nonMainFeatures.Count, "", "Copying secondary textures: ", () =>
            {
                foreach (var secondaryFeature in nonMainFeatures)
                {
                    RenderTexture secondaryRT = new RenderTexture(packedTexture.width, packedTexture.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);

                    RenderTexture.active = secondaryRT;
                    GL.Clear(clearDepth: false, clearColor: true, backgroundColor: Color.black);
                    GL.LoadPixelMatrix(0, 1, 0, 1);

                    progress.Begin(secondaryFeature.featureData.Count, "", secondaryFeature.propertyName, () =>
                    {
                        for (int i = 0; i < secondaryFeature.featureData.Count; i++)
                        {
                            var mainTexture = mainFeature.featureData[i].texture;
                            if (mainTexture == null)
                            {
                                progress.Step();
                                continue;
                            }

                            var secondaryTexture = secondaryFeature.featureData[i].texture;
                            if (secondaryTexture == null)
                            {
                                progress.Step();
                                continue;
                            }

                            progress.Step(secondaryTexture.name);

                            Rect rect = packedRects[i];

                            //Use mainTexture instead of secondaryTexture here to calculate correct border to line up with main texture
                            float borderDX = _border / (float)mainTexture.width;
                            float borderDY = _border / (float)mainTexture.height;

                            drawTexture(secondaryTexture, secondaryRT, rect, borderDX, borderDY);
                        }
                    });

                    packedTextures[_features.IndexOf(secondaryFeature)] = convertToTexture2D(secondaryRT, mipmap: false);
                }
            });
        }
コード例 #4
0
ファイル: MeshUtil.cs プロジェクト: gobi1990/Robot-Chef-Game
        public static int Index(this UVChannelFlags flags)
        {
            switch (flags)
            {
            case UVChannelFlags.UV0:
                return(0);

            case UVChannelFlags.UV1:
                return(1);

            case UVChannelFlags.UV2:
                return(2);

            case UVChannelFlags.UV3:
                return(3);
            }
            throw new InvalidOperationException();
        }
コード例 #5
0
        public static string GetUvFeature(UVChannelFlags flags)
        {
            switch (flags)
            {
            case UVChannelFlags.UV0:
                return(UV_0_FEATURE);

            case UVChannelFlags.UV1:
                return(UV_1_FEATURE);

            case UVChannelFlags.UV2:
                return(UV_2_FEATURE);

            case UVChannelFlags.UV3:
                return(UV_3_FEATURE);

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #6
0
        protected virtual bool doesRequireUvChannel(UVChannelFlags channel)
        {
            switch (channel)
            {
            case UVChannelFlags.UV0:
                return(_useUv0);

            case UVChannelFlags.UV1:
                return(_useUv1);

            case UVChannelFlags.UV2:
                return(_useUv2);

            case UVChannelFlags.UV3:
                return(_useUv3);

            default:
                throw new ArgumentException("Invalid channel argument.");
            }
        }
 protected override void ReadFromImpl(object obj)
 {
     base.ReadFromImpl(obj);
     ParticleSystem.TextureSheetAnimationModule uo = (ParticleSystem.TextureSheetAnimationModule)obj;
     enabled                 = uo.enabled;
     mode                    = uo.mode;
     numTilesX               = uo.numTilesX;
     numTilesY               = uo.numTilesY;
     animation               = uo.animation;
     frameOverTime           = uo.frameOverTime;
     frameOverTimeMultiplier = uo.frameOverTimeMultiplier;
     startFrame              = uo.startFrame;
     startFrameMultiplier    = uo.startFrameMultiplier;
     cycleCount              = uo.cycleCount;
     rowIndex                = uo.rowIndex;
     uvChannelMask           = uo.uvChannelMask;
     timeMode                = uo.timeMode;
     fps        = uo.fps;
     speedRange = uo.speedRange;
     rowMode    = uo.rowMode;
 }
コード例 #8
0
        public static List <Vector4> GetUvs(Mesh mesh, UVChannelFlags channel)
        {
            var key = new UvKey()
            {
                mesh = mesh, channel = (int)channel
            };
            List <Vector4> uvs;

            if (!_uvCache.TryGetValue(key, out uvs))
            {
                uvs = new List <Vector4>();
                mesh.GetUVs(channel.Index(), uvs);

                if (uvs.Count != mesh.vertexCount)
                {
                    uvs.Fill(mesh.vertexCount, Vector4.zero);
                }

                _uvCache[key] = uvs;
            }
            return(uvs);
        }