当前位置: 首页 > news >正文

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

运行一个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 instructionsself.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 controlsbase.disableMouse()props = WindowProperties()props.setCursorHidden(True)base.win.requestProperties(props)# Set the current viewing targetself.focus = Vec3(55,-55,20)self.heading = 180self.pitch = 0self.mousex = 0self.mousey = 0self.last = 0self.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.lryc.cn/news/132598.html

相关文章:

  • 使用 Node.js 生成优化的图像格式
  • 【WinAPI详解】<CreateWindowEx详解>
  • 【Git】分支管理
  • 玩转单元测试之gtest
  • Tomcat 一次请求的生命周期
  • spring cloud gateway中配置uri
  • 使用NAudio录制wav音频
  • 数据结构之动态内存管理机制
  • 【汇编语言】栈及栈操作的实现
  • 【JavaEE】面向切面编程AOP是什么-Spring AOP框架的基本使用
  • SpringBoot+微信小程序奶茶在线点单小程序系统 附带详细运行指导视频
  • 【支付宝小程序】开发基础--文件结构教程
  • LLM 生成式配置的推理参数温度 top k tokens等 Generative configuration inference parameters
  • npm的镜像源和代理的查看和修改
  • IP库新增经过实践的Verilog 库
  • SLAM-VIO视觉惯性里程计
  • 分布式 RPC 框架入门
  • Spring boot与Spring cloud 之间的关系
  • 报名开启 | HarmonyOS第一课“营”在暑期系列直播
  • Apache DolphinScheduler 支持使用 OceanBase 作为元数据库啦!
  • matlab使用教程(17)—广度优先和深度优先搜索
  • CSerialPort教程4.3.x (2) - CSerialPort源码简介
  • 【数据结构OJ题】有效的括号
  • Java性能分析中常用命令和工具
  • JVM性能分析-jstat工具观察gc频率
  • mysql 查询报错 1267 - Illegal mix of collations
  • 【ARM】Day6
  • 深入理解Flink Mailbox线程模型
  • Docker搭建LNMP运行Wordpress平台
  • 10个常见渐变交互效果