Python 3d引擎--Ursina(万字详细版)

Python有一个不错的3D引擎——Ursina
Ursina官网http://www.ursinaengine.orghttp://www.ursinaengine.org

前言 

打开cmd,控制台输入pip install ursina以安装ursina

1.1编写第一个程序

首先导入ursina

from ursina import *

然后创建app

app=Ursina()

运行app

app.run()

最终代码:

 
  1. from ursina import *
     
    app=Ursina()
     
    app.run()
    

如果出现了一个灰色的窗口,那么说明运行成功了!

 绘制实体长方体


绘制实体需要用到一个函数:Entity()

因为我们要绘制长方体,所以设置参数model="cube"

代码如下:

from ursina import *
 
app=Ursina()
 
cube=Entity(model="cube")
 
app.run()

 

绘制长方体阴影与设置颜色

这时我们需要用到函数--cube 

根据cube数据来调整颜色与其他数据

from ursina import *

app = Ursina()

window.color = color.black
print(len(scene.entities))
base_cube = Entity(model='cube', color=color.yellow, texture='white_cube')

for i in range(8):
    print(curve.out_expo(i/8))
    Entity(parent=base_cube, model='cube', color=color.orange, scale=math.pow(1.14,i), alpha=.1)

base_cube.combine()
print(len(scene.entities))


combine_parent = Entity()
base_cube.parent = combine_parent

# for i in range(20):
#     duplicate(base_cube, position=(random.uniform(-100,100),random.uniform(-100,100),random.uniform(-100,100)))

# combine_parent.combine()

EditorCamera()


app.run()

3d版长方体

from ursina import *


app = Ursina()

# Make a simple game so we have something to test with
from ursina.prefabs.first_person_controller import FirstPersonController
player = FirstPersonController(gravity=0, model='cube', color=color.azure)
camera.z = -10
ground = Entity(model='plane', texture='grass', scale=10)

# Create an Entity for handling pausing an unpausing.
# Make sure to set ignore_paused to True so the pause handler itself can still receive input while the game is paused.
pause_handler = Entity(ignore_paused=True)
pause_text = Text('PAUSED', origin=(0,0), scale=2, enabled=False) # Make a Text saying "PAUSED" just to make it clear when it's paused.

def pause_handler_input(key):
    if key == 'escape':
        application.paused = not application.paused # Pause/unpause the game.
        pause_text.enabled = application.paused     # Also toggle "PAUSED" graphic.

pause_handler.input = pause_handler_input   # Assign the input function to the pause handler.


app.run()

 

 

FPS游戏

首先,导入ursina模块

from ursina import 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值