Beispiel #1
0
        public static IEnumerator RenderOutfit(DCustomOutfit outfit, Color beakColor, Color bodyColor, Color bellyColor, ImageBuilderCameraData cameraData, GameObject avatarGO, Func <ModelRenderer, bool> onProcessModel, AvatarAnimationFrame animationFrame = null)
        {
            AvatarModel avatarModel = avatarGO.GetComponent <AvatarModel>();

            avatarModel.BeakColor  = beakColor;
            avatarModel.BodyColor  = bodyColor;
            avatarModel.BellyColor = bellyColor;
            avatarModel.ClearAllEquipment();
            avatarModel.ApplyOutfit(outfit);
            AvatarView avatarView = avatarGO.GetComponent <AvatarView>();

            yield return(new WaitUntil(() => avatarView.IsReady));

            ModelRendererConfig renderConfig = new ModelRendererConfig(avatarGO.transform, cameraData.ModelOffset, new Vector2(cameraData.IconSize, cameraData.IconSize));

            avatarGO.transform.Rotate(cameraData.ModelRotation);
            renderConfig.FieldOfView = cameraData.FieldOfView;
            ModelRenderer modelRenderer = new ModelRenderer(renderConfig);

            modelRenderer.RotateCamera(cameraData.CameraRotation);
            if (animationFrame != null)
            {
                Animator component = avatarGO.GetComponent <Animator>();
                component.Play(animationFrame.StateName, animationFrame.Layer, animationFrame.Time);
            }
            do
            {
                yield return(null);
            }while (onProcessModel(modelRenderer));
        }
        private IEnumerator renderToTexture(ItemRenderParams param)
        {
            param.OutputTexture = null;
            DCustomEquipment equipment = param.equipment;
            int equipmentTemplateId    = equipment.DefinitionId;
            Dictionary <int, TemplateDefinition> templates = Service.Get <GameData>().Get <Dictionary <int, TemplateDefinition> >();

            if (!templates.ContainsKey(equipmentTemplateId))
            {
                Log.LogErrorFormatted(this, "Unable to locate template {0} in template definitions with id {1}.", equipment.Name, equipmentTemplateId);
                yield break;
            }
            TemplateDefinition templateDefinition = templates[equipmentTemplateId];
            AssetRequest <TemplateRenderData> templateRequest;

            try
            {
                templateRequest = Content.LoadAsync(templateDefinition.RenderDataKey);
            }
            catch (Exception)
            {
                Log.LogErrorFormatted(this, "Could not load render data for template definition {0} at {1}.", templateDefinition.Name, templateDefinition.RenderDataKey.Key);
                yield break;
            }
            if (templateRequest != null)
            {
                yield return(templateRequest);

                TemplateRenderData templateRenderData = templateRequest.Asset;
                penguin.transform.rotation = templateRenderData.ItemRotation;
                ModelRendererConfig config = new ModelRendererConfig(penguin.transform, templateRenderData.ItemPosition, new Vector2(256f, 256f))
                {
                    FieldOfView               = templateRenderData.CameraFOV,
                    FrameObjectInCamera       = false,
                    UseOcclusionCulling       = false,
                    AutoDestroyObjectToRender = false
                };
                if (param.BackgroundColor != Color.clear)
                {
                    config.CameraBackgroundColor = param.BackgroundColor;
                    config.UseSolidBackground    = true;
                }
                ModelRenderer modelRenderer = new ModelRenderer(config);
                modelRenderer.RotateCamera(templateRenderData.CameraRotation.eulerAngles);
                yield return(new WaitForEndOfFrame());

                param.OutputTexture = modelRenderer.Image;
                modelRenderer.Destroy();
            }
        }
        private IEnumerator renderToTexture(RenderParams param, GameObject decorationGameObject, StructureRenderData decorationRenderData)
        {
            ModelRendererConfig config = new ModelRendererConfig(decorationGameObject.transform, decorationRenderData.ItemPosition, new Vector2(256f, 256f))
            {
                FieldOfView               = decorationRenderData.CameraFOV,
                FrameObjectInCamera       = false,
                UseOcclusionCulling       = false,
                AutoDestroyObjectToRender = true
            };

            if (param.BackgroundColor != Color.clear)
            {
                config.CameraBackgroundColor = param.BackgroundColor;
                config.UseSolidBackground    = true;
            }
            ModelRenderer modelRenderer = new ModelRenderer(config);

            modelRenderer.RotateCamera(decorationRenderData.CameraRotation.eulerAngles);
            yield return(new WaitForEndOfFrame());

            param.OutputTexture = modelRenderer.Image;
            modelRenderer.Destroy();
        }
 public ModelRenderer(ModelRendererConfig config)
 {
     this.config = config;
     init();
 }