场景编辑器Atmospheric Directional Light UI

前言

项目工具需要做个一个可视化调整角度的UI。

这里想参考一下:Atmospheric Directional Lights的UI。

于是,查阅了一下源码,在这做一下记录。

一、相关源码

首先,在编辑器操作中,发现当DirectionalLight勾选了以下开关才可以改变上述UI的方向。

  • Atmosphere Sun Light

根据bUsedAsAtmosphereSunLight去查找如何被调用:

在在LevelEditorViewport.cpp文件中,可以追溯到函数:

static UDirectionalLightComponent* GetAtmosphericLight(const uint8  DesiredLightIndex, UWorld* ViewportWorld)

再继续追踪这个函数的使用,有以下几个地方:

InputKey函数中,发现这个是判断是否开启UI。

MouseMove中可以看到计算如下:可以大概猜测出,下面计算的是UI的方向。

接着可以看到UI的绘制部分:通过搜索UserIsControllingAtmosphericLightTimer

  • FLevelEditorViewportClient::Draw中具体代码如下:
// void FLevelEditorViewportClient::Draw(const FSceneView*  View,FPrimitiveDrawInterface* PDI)
if (UserIsControllingAtmosphericLightTimer > 0.0f)
{// Draw a gizmo helping to figure out where is the light when moving it using a shortcut.FQuat ViewRotation = FQuat(GetViewRotation());FVector ViewPosition = GetViewLocation();const float GizmoDistance = 50.0f;const float GizmoSideOffset = 15.0f;const float GizmoRadius = 10.0f;const float ThicknessLight = 0.05f;const float ThicknessBold = 0.2f;// Always draw the gizmo right in in front of the camera with a little side shift.const FVector X(1.0f, 0.0f, 0.0f);const FVector Y(0.0f, 1.0f, 0.0f);const FVector Z(0.0f, 0.0f, 1.0f);const FVector Base = ViewPosition + GizmoDistance * ViewRotation.GetForwardVector() + GizmoSideOffset * (-ViewRotation.GetUpVector() + ViewRotation.GetRightVector());// Draw world main axisFRotator IdentityX(0.0f, 0.0f, 0.0f);FRotator IdentityY(0.0f, 90.0f, 0.0f);FRotator IdentityZ(90.0f, 0.0f, 0.0f);DrawDirectionalArrow(PDI, FQuatRotationTranslationMatrix(FQuat(IdentityX), Base), FColor(255, 0, 0, 127), GizmoRadius, 0.3f, SDPG_World, ThicknessBold);DrawDirectionalArrow(PDI, FQuatRotationTranslationMatrix(FQuat(IdentityY), Base), FColor(0, 255, 0, 127), GizmoRadius, 0.3f, SDPG_World, ThicknessBold);DrawDirectionalArrow(PDI, FQuatRotationTranslationMatrix(FQuat(IdentityZ), Base), FColor(0, 0, 255, 127), GizmoRadius, 0.3f, SDPG_World, ThicknessBold);// Render polar coordinate circlesDrawCircle(PDI, Base, X, Y, FLinearColor(0.2f, 0.2f, 1.0f), GizmoRadius, 32, SDPG_World, ThicknessBold);DrawCircle(PDI, Base, X, Y, FLinearColor(0.2f, 0.2f, 0.75f), GizmoRadius*0.75f, 32, SDPG_World, ThicknessLight);DrawCircle(PDI, Base, X, Y, FLinearColor(0.2f, 0.2f, 0.50f), GizmoRadius*0.50f, 32, SDPG_World, ThicknessLight);DrawCircle(PDI, Base, X, Y, FLinearColor(0.2f, 0.2f, 0.25f), GizmoRadius*0.25f, 32, SDPG_World, ThicknessLight);DrawArc(PDI, Base, Z, Y, -90.0f, 90.0f, GizmoRadius, 32, FLinearColor(1.0f, 0.2f, 0.2f), SDPG_World);DrawArc(PDI, Base, Z, X, -90.0f, 90.0f, GizmoRadius, 32, FLinearColor(0.2f, 1.0f, 0.2f), SDPG_World);// Draw the light incoming light direction. The arrow is offset outward to help depth perception when it intersects with other gizmo elements.const FLinearColor ArrowColor = -UserControlledAtmosphericLightMatrix.GetRotation().GetForwardVector() * 0.5f + 0.5f;const FVector ArrowOrigin = Base - UserControlledAtmosphericLightMatrix.GetRotation().GetForwardVector()*GizmoRadius*1.25;const FQuatRotationTranslationMatrix ArrowToWorld(UserControlledAtmosphericLightMatrix.GetRotation(), ArrowOrigin);DrawDirectionalArrow(PDI, ArrowToWorld, ArrowColor, GizmoRadius, 0.3f, SDPG_World, ThicknessBold);// Now draw x, y and z axis to help getting a sense of depth when look at the vectors on screen.FVector LightArrowTip = -UserControlledAtmosphericLightMatrix.GetRotation().GetForwardVector()*GizmoRadius;FVector P0 = Base + LightArrowTip * FVector(1.0f, 0.0f, 0.0f);FVector P1 = Base + LightArrowTip * FVector(1.0f, 1.0f, 0.0f);FVector P2 = Base + LightArrowTip * FVector(1.0f, 1.0f, 1.0f);PDI->DrawLine(Base, P0, FLinearColor(1.0f, 0.0f, 0.0f), SDPG_World, ThicknessLight);PDI->DrawLine(P0, P1, FLinearColor(0.0f, 1.0f, 0.0f), SDPG_World, ThicknessLight);PDI->DrawLine(P1, P2, FLinearColor(0.0f, 0.0f, 1.0f), SDPG_World, ThicknessLight);
}

小结

  • LevelEditorViewport::InputKey,通过热键判断是否开启UI显示。
  • LevelEditorViewport::MouseMove,计算鼠标移动,来求得Transform矩阵用于渲染。
  • LevelEditorViewport::Draw,渲染调整角度的UI。

通过以上的代码分析,很快可以在场景编辑器中模仿实现一个简单的角度控制的UI。

参考文献

  • UE四元数

场景编辑器Atmospheric Directional Light UI相关推荐

  1. 如何使用CocoStudio场景编辑器制作魔卡幻想

    1 CocoStudio 场景编辑器 使用 CocoStudio 场景编辑器来创建游戏场景,其中包含游戏 UI 与动画,来定制一个游戏主界面. 2 使用 CocoStudio 完成<魔卡幻想&g ...

  2. 【cocos2d-x】如何使用CocoStudio场景编辑器制作魔卡幻想

    1 CocoStudio 场景编辑器 使用 CocoStudio 场景编辑器来创建游戏场景,其中包含游戏 UI 与动画,来定制一个游戏主界面. 2 使用 CocoStudio 完成<魔卡幻想&g ...

  3. Directional Light Map(Directional Irradiance)

    Light Map是一个比较经典的技术,目前来说应该是一般游戏引擎中的标配,它很好的在一种拟全局光效果的质量和效率上做了中和.不过目前用的更多.质量更好的应该是Directional Light Ma ...

  4. 16 CoCos Creator-Scene 场景编辑器

    1. 原文 https://docs.cocos.com/creator/manual/zh/getting-started/basics/editor-panels/scene.html 2. Sc ...

  5. threejs模型可视化编辑器_一个近乎无门槛、零基础的3D场景编辑器

    在这个大数据井喷.互联网爆炸的时代,如何抓住机遇.如何逆流而上或是站在浪潮顶峰?在BAT崛起之初,貌似很少有人选择走BAT当时的道路,那时的他们,选择的是逆流而上,当所有人都在搞实体经营,阿里选择了做 ...

  6. windows脚本编制引擎_从零开始的场景编辑器(二):脚本系统

    为什么需要一个脚本系统 一般来说,一个工程只需要一种编程语言就足够了.事实也确实如此,强大如C++,图形渲染(DX,OpenGL),数据库(levelDB,RocksDB),深度学习(Caffe,Te ...

  7. 征服的荣耀服务器维护,《征服的荣耀》:游戏提供了场景编辑器,但内容的充实仍需等待...

    中世纪题材的俯视角<这是我的战争>,玩家需在漫长的围城煎熬中艰难求生,同时在紧张的昼夜切换间搜集资源并规划建设方案.游戏在维持团队生存基础的考验之外引入了支援堡垒的守城设计,使得资源规划更 ...

  8. Silverlight游戏设计(Game Design):(二)场景编辑器让游戏开发更美好

    如果哪天光荣告诉我:<三国志>系列将终结,我会义无返顾的用余下那点青春继续诠释这部中国历史经典题材游戏,已无法细数它占据了我多少童年的回忆,就好比曾有那么一群满腔热血的<梦幻模拟战& ...

  9. Silverlight游戏设计(Game Design):(七)创建基于场景编辑器的新游戏Demo

    场景编辑器的功能强大且灵活,从设计之初我已毫不惭愧的将其定位到"让Silverlight游戏场景架设更简单.更快捷"这样一个高度.源码公布后,很多朋友均迫切想知道如何将其运用到实际 ...

最新文章

  1. 台式电脑可以练计算机二级嘛6,练习六-计算机二级考试OFFICE高级应用试卷与试题.pdf...
  2. php 画虚线,HTML5 Canvas绘制圆点虚线实例_html5教程技巧
  3. 使用 Flutter 制作一个简单的笑话生成器应用程序
  4. 【机器学习】KNN算法代码练习
  5. 06_特征选择,特征选择的原因,sklearn特征选择API
  6. 微软Build 2016前瞻:让开发者编写能畅行所有设备的app
  7. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 网格系统实例:响应式的列重置
  8. 使用Github Pages和Hexo搭建自己的独立博客【超级详细的小白教程】
  9. 生活:小孩的世界很简单
  10. python如何输出结果为16_Appium+python自动化(十六)- ADB命令,知否知否,应是必知必会(超详解)...
  11. jquery.form 异步校验_利用jQuery.validate异步验证用户名是否存在
  12. python分布式爬虫系统_python简单分布式爬虫
  13. PHP微信公众号服务器配置
  14. Python基础知识从hello world 开始(第三天)
  15. 组合导航(九):三维简化的INS/GPS组合导航系统
  16. 为什么说HTTP协议是无状态的
  17. python编程竞赛规则_第十一届蓝桥杯Python规则及样题
  18. 有趣的隐式图模型——USACO CONTEST FEB07 白银莲花池
  19. Vue <transition> 多个组件的过渡案例
  20. MySQL奇偶数判断

热门文章

  1. 软件测试周刊(第87期):天下就没有偶然,那不过是化了妆的、戴了面具的必然。
  2. 【数据库】聚合和排序
  3. 红米note3支持html,红米Note3有NFC功能吗?红米Note3支持NFC吗?
  4. android主流分辨率
  5. 汇编学习笔记1 通用寄存器和段寄存器详解
  6. vue手势滚动_Vue-router 手势滑动触发返回功能_晴枙_前端开发者
  7. 37岁ChatGPT创始人吃二甲双胍抗衰!这种药真能让人延寿吗?
  8. 支付宝公钥证书支付示例
  9. POI操作Excel2007实例二之“SXSSFWorkbook”处理海量数据
  10. [Guide] Mac OS X Lion: How To Boot A Linux Live System From An USB Drive How To Update Any OCZ SSD