panda3d加载模型复习和python面向对象编程属性学习

news2024/9/20 3:10:35

运行一个python示例;然后去除一些代码,只剩下加载模型相关,如下;

from panda3d.core import loadPrcFileData
# Configure the parallax mapping settings (these are just the defaults)
loadPrcFileData("", "parallax-mapping-samples 3")
loadPrcFileData("", "parallax-mapping-scale 0.1")

import direct.directbase.DirectStart
from panda3d.core import WindowProperties
from panda3d.core import Filename,Shader
from panda3d.core import AmbientLight,PointLight
from panda3d.core import TextNode
from panda3d.core import Point3,Vec3,Vec4
from direct.task.Task import Task
from direct.actor.Actor import Actor
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from direct.filter.CommonFilters import *
import sys,os

# Function to put instructions on the screen.
def addInstructions(pos, msg):
    return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
                        pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)

# Function to put title on the screen.
def addTitle(text):
    return OnscreenText(text=text, style=1, fg=(1,1,1,1),
                        pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)

class BumpMapDemo(DirectObject):

    def __init__(self):

        # Check video card capabilities.

        if (base.win.getGsg().getSupportsBasicShaders() == 0):
            addTitle("Bump Mapping: Video driver reports that shaders are not supported.")
            return

        # Post the instructions
        self.title = addTitle("Panda3D: Tutorial - Bump Mapping")
        self.inst1 = addInstructions(0.95, "Press ESC to exit")
        self.inst2 = addInstructions(0.90, "Move mouse to rotate camera")
        self.inst3 = addInstructions(0.85, "Left mouse button: Move forwards")
        self.inst4 = addInstructions(0.80, "Right mouse button: Move backwards")
        self.inst5 = addInstructions(0.75, "Enter: Turn bump maps Off")

        self.room = loader.loadModel("models/abstractroom")
        self.room.reparentTo(render)

        # Make the mouse invisible, turn off normal mouse controls
        base.disableMouse()
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)

        # Set the current viewing target
        self.focus = Vec3(55,-55,20)
        self.heading = 180
        self.pitch = 0
        self.mousex = 0
        self.mousey = 0
        self.last = 0
        self.mousebtn = [0,0,0]

        self.room.setShaderAuto()

        self.shaderenable = 1        

t = BumpMapDemo()

run()

运行如下;

先看一下在python面向对象编程中,__init__()相当于构造函数,self代表类的实例;

还不太了解,看上去它的属性都是不须声明直接可以用,像下面这些,

        self.title = xxx
        self.inst1 = xxx
        self.inst2 = xxx
......
        self.inst5 = xxx

        self.room = xxx

看一下把self.title改为self.biaoti是不是一样;是一样,程序跑起来都一样;

它的模型加载了之后是赋值给 self.room,看一下把全部的room都改为house,运行一下,也是一样;

模型是调用 loader.loadModel()方法加载,加载之后赋值给 self.room;

之后还有一句 self.room.reparentTo(render),模型才会显示;

对于 reparentTo(render) 方法,手册说明如下;

Placing the Model in the Scene Graph
The most important manipulation is to change the parent of a node. A model is by default loaded without a parent, but it needs to be placed into an active scene graph so that Panda3D will be able to find the model’s geometry and render it to the screen.

The default 3D scene graph is called render, and this is how to reparent the model to this scene graph:

myModel.reparentTo(render)
It is possible to reparent the model to any node (even to another model, or to a sub-part of a different model), not just to render! What’s important is that it is parented to a node that is itself parented to a scene graph, so that Panda3D can find it. Otherwise, the model will remain invisible.

The converse is to remove a model from the scene graph, which can be done as follows:

myModel.detachNode()

    大致是说,模型载入后默认没有父对象,需要放入一个激活的场景图,这样panda3d可以发现模型的几何然后把它渲染到屏幕;reparentTo(render) 方法放置模型进场景图;

    Scene Graph,先翻译为场景图;

    如果把模型从场景图移除,调用detachNode();

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/909654.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ROS2 学习(五)接口,动作

接口 通信双方统一规定好接口。比如图像 img,控制运动的线速度和角速度…… 我们也不用了解具体实现,基本就是了解接口会去用就行。 $ ros2 interface list # 展示所有 interfaces $ ros2 interface show ... # 显示具体一个 interface $ ros2 package…

Jenkins工具系列 —— 配置邮箱 每个job下动态设置临时发送人

文章目录 安装插件添加邮箱认证邮箱申请(以QQ邮箱网页为例)jenkins添加邮箱认证 jenkins设置邮箱相关信息配置全局邮件单个JOB邮箱配置 安装插件 点击 左侧的 Manage Jenkins —> Plugins ——> 左侧的 Available plugins 添加邮箱认证 邮箱申请…

如何进行电脑文件夹分类与整理?

本科电脑用了四年,毕业后发现空间很满,但是真正有用的东西仿佛就一点。好像是在学开发的时候,听到一个老师说,根目录不要放太多文件夹,不然就相当于没有根目录了。刚好研究生有了新的台式电脑,开始有规划的…

ElasticSearch学习2

1、索引的操作 1、创建索引 对ES的操作其实就是发送一个restful请求,kibana中在DevTools中进行ES操作 创建索引时需要注意ES的版本,不同版本的ES创建索引的语句略有差别,会导致失败 如下创建一个名为people的索引,settings&…

3.JQuery closest()的用法

closest()是一个非常好用的查找祖先对象的方法,它和parent()和parents()相比,优点是简洁直观,返回0或1个对象,避免了返回很多对象而不知道怎么处理的尴尬&…

【算法日志】贪心算法刷题:单调递增数列,贪心算法总结(day32)

代码随想录刷题60Day 目录 前言 单调递增数列 贪心算法总结 前言 今天是贪心算法刷题的最后一天,今天本来是打算刷两道题,其中的一道hard题做了好久都没有做出来(主要思路错了)。然后再总结一下。 单调递增数列 int monotoneIncreasingDigits(int n…

Unity怎么制作魔法火焰特效?Unity制作魔法火焰特效方法

Unity制作魔法火焰特效方法: 在第一次玩Supergiant Games的RPG游戏《Hades》时,游戏的美术和视觉效果让人非常吃惊。受此启发,希望能够尝试制作类似风格的作品。 工作流程 整个工作从制作简单的火焰贴图开始。首先,我使用PhotoS…

SSM框架的学习与应用(Spring + Spring MVC + MyBatis)-Java EE企业级应用开发学习记录(第二天)Mybatis的深入学习

SSM框架的学习与应用(Spring Spring MVC MyBatis)-Java EE企业级应用开发学习记录(第二天)Mybatis的深入学习(增删改查的操作) 上一篇我们的项目搭建好了,也写了简答的Junit测试类进行测试,可以正确映射…

使用docker-maven-plugin插件构建镜像并推送至私服Harbor

前言 如下所示,建议使用 Dockerfile Maven 插件,但该插件也停止维护更新了。因此先暂时使用docker-maven-plugin插件。 一、开启Docker服务器的远程访问 1.1 开启2375远程访问 默认的dokcer是不支持远程访问的,需要加点配置,开…

爬虫ip带你探索无限可能

各位程序猿大佬们,今天我要为大家带来一个备受关注的话题:爬虫ip的应用范围!你可能会好奇,什么是爬虫ip?它在我们的日常生活中有哪些神奇的应用呢?让我们一起来揭开这个神秘的面纱,探索无限可能…

JavaSE-20 【Lambda】

文章目录 1 Lambda介绍1.1 什么是Lambda1.2 为什么使用Lambda 2 语法标准格式1.1 语法格式1.2 格式说明:1.3 lambda表达式的重要特征1.4 lambda表达式的常见格式1.5 语法格式11.6 语法格式21.7 语法格式31.8 语法格式41.9 语法格式51.10 语法格式6 3 函数式接口3.1 …

韩语字母及输入法介绍

韩语字母及输入法介绍 字母由来 朝鲜语字母的由来为如下:十五世纪的朝鲜王国世宗大王 和他的集贤殿大臣在思考,创制自己本国的文字,仿照了“天地人思想”和“发音器官的形象”而创制了朝鲜语字母。 ​ 元音是由三个要素而组成的&#xff1…

结构型(一) - 代理模式

一、概念 代理模式(Proxy Pattern):它在不改变原始类(或叫被代理类)代码的情况下,通过引入代理类来给原始类附加新功能。 使用场景:代理模式最常用的一个应用场景就是,在业务系统中…

Lnton羚通算法算力云平台【PyTorch】教程:torch.nn.Softplus

torch.nn.Softplus 原型 CLASS torch.nn.Softplus(beta1, threshold20) 参数 beta (int) – Softplus里β \betaβ 值, 默认为 1. threshold (int) – 高于这个值恢复为线性函数,默认为 20. 图 代码 import torch import torch.nn as nnm nn.Softp…

电工-学习电工有哪些好处

学习电工有哪些好处?在哪学习电工? 学习电工有哪些好处?在哪学习电工?学习电工可以做什么?优势有哪些? 学习电工可以做什么?学习电工有哪些好处? 就业去向:可在企业单位…

Word怎么转换成PDF文档?多个Word转换成PDF步骤分享

word文档是一种非常好用的文件格式,可以帮助用户们很好的保存图片和文字内容,不过并不是只有word这一种文档类文件格式,还有一种pdf文档也深受用户们的欢迎,在工作或者学习过程中这两种文档是可以互相转换格式的,那么W…

如何安装指定版本node.js,安装旧版本node

1、查看当前是否安装node,如果安装了需要先卸载当前版本node 搜索控制面板 -> 找到程序/卸载程序 -> 在里面找到node -> 然后右击卸载 2、卸载完成后就要安装其他版本得node.js 找到想要安装的对应版本,安装.msi格式的安装包 注&#xff…

测试框架pytest教程(9)跳过测试skip和xfail

skip无条件跳过 使用装饰器 pytest.mark.skip(reason"no way of currently testing this") def test_example(faker):print("nihao")print(faker.words()) 方法内部调用 满足条件时跳过 def test_example():a1if a>0:pytest.skip("unsupported …

Unity 之 ScreenPointToRay() (将点转换成射线的方法)

文章目录 ScreenPointToRay() ScreenPointToRay() ScreenPointToRay() 是Unity中Camera类的一个方法,用于将屏幕上的一个点转换为一条射线。这条射线的起点是摄像机在屏幕上对应的点,方向是从摄像机出发指向那个点。这在进行射线命中检测时非常有用&…

如何远程管理服务器详解

文章目录 前言一、远程管理类型二、远程桌面三、telnet 命令行远程四、查看本地开放端口 前言 很多公司是有自己的机房的,机房里面会有若干个服务器为员工和用户提供服务。大家可以想想:假设这家公司有上百台服务器,我们作为网络工程师&…