-
new Stage(params)
-
舞台类
Name Type Description params
Object optional 创建对象的属性参数。可包含此类的所有属性,所有属性会透传给 Renderer。
Name Type Default Description container
HTMLElement optional stage的容器, 如果有,会把canvas加进container里。
canvas
HTMLCanvasElement optional stage的canvas,不传会自动创建。
camera
Camera optional stage的摄像机。
width
number innerWidth optional stage的宽,默认网页宽度
height
number innerHeight optional stage的高,默认网页高度
pixelRatio
number 根据设备自动判断 optional 像素密度。
clearColor
Color new Color(1, 1, 1, 1) optional 背景色。
preferWebGL2
boolean false optional 是否优先使用 WebGL2
useFramebuffer
boolean false optional 是否使用Framebuffer,有后处理需求时需要。
framebufferOption
Object {} optional framebufferOption Framebuffer的配置,useFramebuffer为true时生效。
useLogDepth
boolean false optional 是否使用对数深度,处理深度冲突。
alpha
boolean false optional 是否背景透明。
depth
boolean true optional 是否需要深度缓冲区。
stencil
boolean false optional 是否需要模版缓冲区。
antialias
boolean true optional 是否抗锯齿。
premultipliedAlpha
boolean true optional 是否需要 premultipliedAlpha。
preserveDrawingBuffer
boolean false optional 是否需要 preserveDrawingBuffer。
failIfMajorPerformanceCaveat
boolean false optional 是否需要 failIfMajorPerformanceCaveat。
gameMode
boolean false optional 是否开启游戏模式,UC 浏览器专用
[value:string]
any optional 其它属性
Example
const stage = new Hilo3d.Stage({ container:document.body, width:innerWidth, height:innerHeight });
Extends
Members Show Inherited
Name | Type | Default | Description |
---|---|---|---|
renderer
|
WebGLRenderer |
渲染器 |
|
camera
|
Camera |
摄像机 |
|
pixelRatio
|
Number | 根据设备自动判断 |
像素密度 |
offsetX
|
Number | 0 |
偏移值 |
offsetY
|
Number | 0 |
偏移值 |
width
|
Number | 0 |
舞台宽度 |
height
|
Number | 0 |
舞台高度 |
canvas
|
HTMLCanvasElement | null |
canvas |
isNode
|
boolean | true | inherited |
className
|
string | Node | inherited |
name
|
string |
inherited
Node 的名字,可以通过 getChildByName 查找 |
|
anim
|
Animation | null |
inherited
动画 |
animationId
|
String | '' |
inherited
animation 查找 id |
jointName
|
String | '' |
inherited
骨骼名称 |
autoUpdateWorldMatrix
|
boolean | true |
inherited
是否自动更新世界矩阵 |
autoUpdateChildWorldMatrix
|
boolean | true |
inherited
是否自动更新子元素世界矩阵 |
parent
|
Node | null |
inherited
父节点 |
needCallChildUpdate
|
boolean | true |
inherited
每次更新的时候是否调用子节点的 onUpdate 方法 |
visible
|
boolean | true |
inherited
节点是否显示 |
pointerEnabled
|
Boolean | true |
inherited
可视对象是否接受交互事件。默认为接受交互事件,即true。 |
pointerChildren
|
Boolean | true |
inherited
子元素是否接受交互事件。 |
useHandCursor
|
Boolean | false |
inherited
是否用鼠标指针 |
userData
|
any | null |
inherited
用户数据 |
onUpdate
|
function | null |
inherited
update 回调 |
onlySyncQuaternion
|
Boolean | false |
inherited
只同步四元数,不同步欧拉角 |
id
|
string | inherited | |
up
|
Vector3 |
inherited
元素的up向量 |
|
children
|
Array.<Node> |
inherited
元素直接点数组 |
|
worldMatrix
|
Matrix4 |
inherited
元素的世界矩阵 |
|
matrix
|
Matrix4Notifier |
inherited
元素的矩阵 |
|
position
|
Vector3Notifier |
inherited
位置 |
|
x
|
number |
inherited
x轴坐标 |
|
y
|
number |
inherited
y轴坐标 |
|
z
|
number |
inherited
z轴坐标 |
|
scale
|
Vector3Notifier |
inherited
缩放 |
|
scaleX
|
number |
inherited
缩放比例x |
|
scaleY
|
number |
inherited
缩放比例y |
|
scaleZ
|
number |
inherited
缩放比例z |
|
pivot
|
Vector3Notifier |
inherited
中心点 |
|
pivotX
|
Number |
inherited
中心点x |
|
pivotY
|
Number |
inherited
中心点y |
|
pivotZ
|
Number |
inherited
中心点z |
|
rotation
|
EulerNotifier |
inherited
欧拉角 |
|
rotationX
|
number |
inherited
旋转角度 x, 角度制 |
|
rotationY
|
number |
inherited
旋转角度 y, 角度制 |
|
rotationZ
|
number |
inherited
旋转角度 z, 角度制 |
|
quaternion
|
Quaternion |
inherited
四元数角度 |
|
matrixVersion
|
Number | 0 |
inherited
矩阵 version,每次改变会加一 |
worldMatrixVersion
|
Number | 0 |
inherited
世界矩阵 version,每次改变会加一 |
Methods Show Inherited
-
resize(width, height, pixelRatio, force){Stage}
-
缩放舞台
Name Type Default Description width
Number 舞台宽
height
Number 舞台高
pixelRatio
Number this.pixelRatio optional 像素密度
force
Boolean false optional 是否强制刷新
Returns:
Type Description Stage 舞台本身。链式调用支持。 -
setOffset(x, y){Stage}
-
设置舞台偏移值
Name Type Description x
Number x
y
Number y
Returns:
Type Description Stage 舞台本身。链式调用支持。 -
viewport(x, y, width, height){Stage}
-
改viewport
Name Type Description x
Number x
y
Number y
width
Number width
height
Number height
Returns:
Type Description Stage 舞台本身。链式调用支持。 -
tick(dt){Stage}
-
渲染一帧
Name Type Description dt
Number 间隔时间
Returns:
Type Description Stage 舞台本身。链式调用支持。 -
enableDOMEvent(type, enabled){Stage}
-
开启/关闭舞台的DOM事件响应。要让舞台上的可视对象响应用户交互,必须先使用此方法开启舞台的相应事件的响应。
Name Type Description type
String | Array 要开启/关闭的事件名称或数组。
enabled
Boolean 指定开启还是关闭。如果不传此参数,则默认为开启。
Returns:
Type Description Stage 舞台本身。链式调用支持。 -
updateDomViewport(){Object}
-
更新 DOM viewport
Returns:
Type Description Object DOM viewport, {left, top, right, bottom} -
getMeshResultAtPoint(x, y, eventMode){Mesh|null}
-
获取指定点的 mesh
Name Type Default Description x
Number y
Number eventMode
Boolean false optional Returns:
Type Description Mesh | null -
Name Type Default Description isChild
boolean false optional 是否子节点,子节点不会处理动画及骨骼Mesh,即如果有动画将共享
Returns:
Type Description Node 返回clone的Node -
inherited resetSkinedMeshRootNode()
-
重置子孙元素中 SkinedMesh 的根节点为当前元素
-
inherited getChildrenNameMap(){Object}
-
将所以子孙元素放到一个对象中,对象key为元素的name,value为该元素
Returns:
Type Description Object 返回获取的对象 -
更新世界矩阵
Name Type Default Description force
Boolean true optional 是否强制更新
Returns:
Type Description Node this -
获取当前元素相对于指定元素的矩阵
Name Type Description ancestor
Node optional 相对于的元素,需要是当前元素的祖先元素,不传表示获取世界矩阵
Returns:
Type Description Matrix4 返回获取的矩阵 -
遍历当前元素的子孙元素
Name Type Default Description callback
NodeTraverseCallback 每个元素都会调用这个函数处理
onlyChild
Boolean false optional 是否只遍历子元素
Returns:
Type Description Node this -
遍历当前元素的子孙元素(广度优先)
Name Type Default Description callback
NodeTraverseCallback 每个元素都会调用这个函数处理
onlyChild
Boolean false optional 是否只遍历子元素
Returns:
Type Description Node this -
根据函数来获取一个子孙元素(广度优先)
Name Type Description fn
NodeGetChildByCallback 判读函数
Returns:
Type Description Node | null 返回获取到的子孙元素 -
根据 name path 来获取子孙元素
Name Type Description path
Array.<String> 名字数组, e.g., getChildByNamePath(['a', 'b', 'c'])
Returns:
Type Description Node | null 返回获取到的子孙元素 -
遍历调用子孙元素onUpdate方法
Name Type Description dt
Number Returns:
Type Description Node this -
根据函数来获取一个子孙元素
Name Type Description fn
NodeGetChildByCallback 判读函数
Returns:
Type Description Node | null 返回获取到的子孙元素 -
根据函数来获取匹配的所有子孙元素
Name Type Description fn
NodeGetChildByCallback 判读函数
Returns:
Type Description Array.<Node> 返回获取到的子孙元素 -
获取指定name的首个子孙元素
Name Type Description name
string 元素name
Returns:
Type Description Node | null 获取的元素 -
获取指定name的所有子孙元素
Name Type Description name
string 元素name
Returns:
Type Description Array.<Node> 获取的元素数组 -
获取指定id的子孙元素
Name Type Description id
string 元素id
Returns:
Type Description Node | null 获取的元素 -
获取指定类名的所有子孙元素
Name Type Description className
string 类名
Returns:
Type Description Array.<Node> 获取的元素数组 -
获取指定基类名的所有子孙元素
Name Type Description className
string 类名
Returns:
Type Description Array.<Node> 获取的元素数组 -
设置元素的缩放比例,如果只有一个参数三个轴等比缩放
Name Type Description x
number X缩放比例
y
number optional Y缩放比例
z
number optional Z缩放比例
Returns:
Type Description Node this -
设置元素的位置
Name Type Description x
number X方向位置
y
number Y方向位置
z
number Z方向位置
Returns:
Type Description Node this -
设置元素的旋转
Name Type Description x
number X轴旋转角度, 角度制
y
number Y轴旋转角度, 角度制
z
number Z轴旋转角度, 角度制
Returns:
Type Description Node this -
设置中心点
Name Type Description x
Number 中心点x
y
Number 中心点y
z
Number 中心点z
Returns:
Type Description Node this -
改变元素的朝向
Name Type Description node
Node | Object | Vector3 需要朝向的元素,或者坐标
Returns:
Type Description Node this -
inherited raycast(ray, sort, eventMode){Array.<raycastInfo>|null}
-
raycast
Name Type Default Description ray
Ray sort
Boolean false optional 是否按距离排序
eventMode
Boolean false optional 是否事件模式
Returns:
Type Description Array.<raycastInfo> | null -
获取元素的包围盒信息
Name Type Description parent
Node optional 元素相对于哪个祖先元素的包围盒,不传表示世界
currentMatrix
Matrix4 optional 当前计算的矩阵
bounds
Bounds optional 当前计算的包围盒信息
Returns:
Type Description Bounds 返回计算的包围盒信息 -
销毁
Name Type Default Description renderer
WebGLRenderer optional stage时可以不传
destroyTextures
Boolean false optional 是否销毁材质的贴图,默认不销毁
Returns:
Type Description Stage this