示例#1
0
        public static void BakeTexture(List <ViewPart> parts, Rect[] atlasUVOffsets, BodyColorMaterialProperties bodyColor, RenderTexture atlasRenderTexture)
        {
            BakeMaterialProperties bakeMaterialProperties = new BakeMaterialProperties(null);
            RenderTexture          active = RenderTexture.active;

            RenderTexture.active = atlasRenderTexture;
            GL.Clear(true, true, new Color32(0, 0, 0, 0));
            for (int i = 0; i < parts.Count; i++)
            {
                ViewPart viewPart    = parts[i];
                Material material    = new Material(viewPart.HasMaterialProperties(typeof(EquipmentMaterialProperties)) ? AvatarService.EquipmentBakeShader : AvatarService.BodyBakeShader);
                Texture  maskTexture = viewPart.GetMaskTexture();
                viewPart.ApplyMaterialProperties(material);
                bodyColor.Apply(material);
                Rect rect = atlasUVOffsets[i];
                bakeMaterialProperties.AtlasOffsetU      = rect.x;
                bakeMaterialProperties.AtlasOffsetV      = rect.y;
                bakeMaterialProperties.AtlasOffsetScaleU = rect.width;
                bakeMaterialProperties.AtlasOffsetScaleV = rect.height;
                bakeMaterialProperties.Apply(material);
                atlasRenderTexture.DiscardContents();
                Graphics.Blit(maskTexture, atlasRenderTexture, material);
                Object.Destroy(material);
            }
            RenderTexture.active = active;
        }
示例#2
0
        public Request CombineParts(AvatarDefinition definition, BodyColorMaterialProperties bodycolor, List <ViewPart> parts, int maxAtlasDimension)
        {
            Request     request = new Request();
            IEnumerator value   = partsCombiner(request, definition, bodycolor ?? definition.BodyColor, parts, maxAtlasDimension);

            queue.Enqueue(new KeyValuePair <Request, IEnumerator>(request, value));
            return(request);
        }
示例#3
0
        public void SetupRenderer(GameObject gameObject, AvatarModel model, ref Renderer rend)
        {
            if (rend == null)
            {
                rend = this.MeshDef.CreateRenderer(gameObject);
                model.Definition.RenderProperties.Apply(rend);
            }
            Material material = this.GetMaterial(false);
            BodyColorMaterialProperties bodyColorMaterialProperties = new BodyColorMaterialProperties(model.BeakColor, model.BellyColor, model.BodyColor);

            bodyColorMaterialProperties.Apply(material);
            this.ApplyMaterialProperties(material);
            ComponentExtensions.DestroyIfInstance(rend.sharedMaterial);
            rend.sharedMaterial = material;
            this.MeshDef.ApplyMesh(gameObject, null);
        }
示例#4
0
 public void Update()
 {
     if (base.IsBusy && loadingEquipmentRequest.Finished && loadingDecalRequest.Finished)
     {
         cleanupCurrent();
         switchLoadingRequestsToCurrent();
         setupRenderer();
         stopWork();
     }
     if (bodyMatProps != null && rend != null)
     {
         Material sharedMaterial = rend.sharedMaterial;
         if (sharedMaterial != null)
         {
             bodyMatProps.Apply(sharedMaterial);
             bodyMatProps = null;
         }
     }
 }
示例#5
0
 public void Update()
 {
     if (combineRequest == null)
     {
         if (partsRequest != null && partsRequest.Finished && decalsRequest != null && decalsRequest.Finished)
         {
             BodyColorMaterialProperties bodycolor = new BodyColorMaterialProperties(Model.BeakColor, Model.BellyColor, Model.BodyColor);
             combineRequest = avatarService.CombineParts(Model.Definition, bodycolor, partViews, MaxAtlasDimension);
         }
     }
     else if (combineRequest.Finished)
     {
         setupRenderer();
         outfitService.Unload(partsRequest);
         partsRequest = null;
         outfitService.Unload(decalsRequest);
         decalsRequest  = null;
         combineRequest = null;
         stopWork();
     }
 }
示例#6
0
 public void Update()
 {
     if (this.combineRequest == null)
     {
         if (this.partsRequest != null && this.partsRequest.Finished && this.decalsRequest != null && this.decalsRequest.Finished)
         {
             BodyColorMaterialProperties bodycolor = new BodyColorMaterialProperties(this.Model.BeakColor, this.Model.BellyColor, this.Model.BodyColor);
             this.combineRequest = this.avatarService.CombineParts(this.Model.Definition, bodycolor, this.partViews, this.MaxAtlasDimension);
         }
     }
     else if (this.combineRequest.Finished)
     {
         this.setupRenderer();
         this.outfitService.Unload <EquipmentViewDefinition>(this.partsRequest);
         this.partsRequest = null;
         this.outfitService.Unload <Texture2D>(this.decalsRequest);
         this.decalsRequest  = null;
         this.combineRequest = null;
         base.stopWork();
     }
 }
 public void ApplyColor()
 {
     this.bodyMatProps = new BodyColorMaterialProperties(this.Model.BeakColor, this.Model.BellyColor, this.Model.BodyColor);
 }
示例#8
0
        private static IEnumerator partsCombiner(Request request, AvatarDefinition definition, BodyColorMaterialProperties bodycolor, List <ViewPart> parts, int maxAtlasDimension)
        {
            int meshCount = parts.Count;

            Mesh[]  meshes          = new Mesh[meshCount];
            int[][] meshBoneIndexes = new int[meshCount][];
            for (int i = 0; i < meshCount; i++)
            {
                string[] boneNames = parts[i].GetBoneNames();
                meshes[i]          = parts[i].GetMesh();
                meshBoneIndexes[i] = new int[boneNames.Length];
                for (int j = 0; j < boneNames.Length; j++)
                {
                    meshBoneIndexes[i][j] = definition.BoneIndexLookup[boneNames[j]];
                }
            }
            request.Mesh = Combine.CombineSkinnedMeshes(meshes, meshBoneIndexes, definition.BindPose);
            yield return(null);

            int curSize;

            Rect[] atlasUVOffsets = Combine.CalculateAtlasLayout(parts, out curSize);
            yield return(null);

            int renderTextureSize = Mathf.Min(Mathf.ClosestPowerOfTwo(curSize), maxAtlasDimension);

            request.Atlas = new RenderTexture(renderTextureSize, renderTextureSize, 0, RenderTextureFormat.ARGB32);
            request.Atlas.isPowerOfTwo = true;
            request.Atlas.filterMode   = FilterMode.Bilinear;
            request.Atlas.useMipMap    = false;
            Combine.BakeTexture(parts, atlasUVOffsets, bodycolor, request.Atlas);
            yield return(null);

            Combine.ApplyAtlasUV(meshes, request.Mesh, atlasUVOffsets);
        }
 private static IEnumerator partsCombiner(AvatarService.Request request, AvatarDefinition definition, BodyColorMaterialProperties bodycolor, List <ViewPart> parts, int maxAtlasDimension)
 {
     AvatarService._partsCombiner_d__0 _partsCombiner_d__ = new AvatarService._partsCombiner_d__0(0);
     _partsCombiner_d__.request           = request;
     _partsCombiner_d__.definition        = definition;
     _partsCombiner_d__.bodycolor         = bodycolor;
     _partsCombiner_d__.parts             = parts;
     _partsCombiner_d__.maxAtlasDimension = maxAtlasDimension;
     return(_partsCombiner_d__);
 }
示例#10
0
 public void ApplyColor()
 {
     bodyMatProps = new BodyColorMaterialProperties(Model.BeakColor, Model.BellyColor, Model.BodyColor);
 }