Skip to content

Latest commit

 

History

History
114 lines (91 loc) · 2.81 KB

File metadata and controls

114 lines (91 loc) · 2.81 KB
Error in user YAML: (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1
---
show: step
version: 1.0 
enable_checker: true
- 本教程同步发布在: 
	- 个人网站: `https://oeasy.org` 
	- 蓝桥云课: `https://www.lanqiao.cn/courses/3584` 
	- GitHub: `https://github.com/overmind1980/oeasy-python-tutorial` 
	- Gitee: `https://gitee.com/overmind1980/oeasypython` 
---

  • oeasy Python 0723
  • 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。

文字的输出

开始

  • 上次我们研究了
    • 物体的旋转
    • 有三个轴向
英文 中文 作用
heading 航向轴 转头
pitch 俯仰轴 点头
bank 横滚 歪头 盗梦空间特效
  • 可以把旋转的角度输出成文字吗?

生成文本

图片描述

  • 可以生成文本
import bpy

# 清空场景
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

# 创建3D文字
bpy.ops.object.text_add(location=(0, 0, 0))
text_obj = bpy.context.object
text_obj.data.body = "Hello"

# 添加一些基本设置
text_obj.data.size = 1.0  # 文字大小
text_obj.data.extrude = 0.1  # 文字厚度
  • 我想显示飞机的旋转值

上飞机

import bpy
from math import pi

bpy.ops.object.select_all(action="SELECT") # 选择所有物体
bpy.ops.object.delete() # 删除选定的物体
c919 = bpy.data.objects.new("c919", None)
bpy.data.collections["Collection"].objects.link(c919)
bpy.ops.mesh.primitive_cylinder_add(radius=1, depth=9)
bpy.context.object.rotation_euler[0] = pi /2
bpy.context.object.parent = c919
bpy.ops.mesh.primitive_cube_add(size=2)
bpy.context.object.name = "body"
bpy.context.object.scale = (0.2,0.75,1)
bpy.context.object.parent = c919
bpy.context.object.rotation_euler[0] = - pi / 4
bpy.context.object.location = (0, 5 ,1)
bpy.context.object.parent = c919
bpy.context.object.name = "tail1"
bpy.ops.mesh.primitive_cube_add(size=2)
bpy.context.object.scale = (1,0.5,0.25)
bpy.context.object.location = (0, 5 ,1)
bpy.context.object.parent = c919
bpy.context.object.name = "tail2"
bpy.ops.mesh.primitive_cube_add(size=2)
bpy.context.object.scale = (5,1,0.25)
bpy.context.object.location = (0, -1 ,0)
bpy.context.object.parent = c919
bpy.context.object.name = "wings"
c919.location = (-10,10,0)
bpy.ops.mesh.primitive_uv_sphere_add()
center = bpy.context.object
center.name = "center"
c919.parent = center
center.rotation_euler = (0,0,3.14/2)


# 创建3D文字
bpy.ops.object.text_add(location=(0, 0, 0))
text_obj = bpy.context.object
text_obj.data.body = center.rotation_euler

# 添加一些基本设置
text_obj.data.size = 1.0  # 文字大小
text_obj.data.extrude = 0.1  # 文字厚度

总结

  • 我们下次再说!👋

  • 本文来自 oeasy Python 系统教程。
  • 想完整、扎实学 Python,
  • 搜索 oeasy 即可。