-
new Stage(params)
-
舞台类
Name Type Description paramsObject optional 创建对象的属性参数。可包含此类的所有属性,所有属性会透传给 Renderer。
Name Type Default Description containerHTMLElement optional stage的容器, 如果有,会把canvas加进container里。
canvasHTMLCanvasElement optional stage的canvas,不传会自动创建。
cameraCamera optional stage的摄像机。
widthnumber innerWidth optional stage的宽,默认网页宽度
heightnumber innerHeight optional stage的高,默认网页高度
pixelRationumber 根据设备自动判断 optional 像素密度。
clearColorColor new Color(1, 1, 1, 1) optional 背景色。
preferWebGL2boolean false optional 是否优先使用 WebGL2
useFramebufferboolean false optional 是否使用Framebuffer,有后处理需求时需要。
framebufferOptionObject {} optional framebufferOption Framebuffer的配置,useFramebuffer为true时生效。
useLogDepthboolean false optional 是否使用对数深度,处理深度冲突。
alphaboolean false optional 是否背景透明。
depthboolean true optional 是否需要深度缓冲区。
stencilboolean false optional 是否需要模版缓冲区。
antialiasboolean true optional 是否抗锯齿。
premultipliedAlphaboolean true optional 是否需要 premultipliedAlpha。
preserveDrawingBufferboolean false optional 是否需要 preserveDrawingBuffer。
failIfMajorPerformanceCaveatboolean false optional 是否需要 failIfMajorPerformanceCaveat。
gameModeboolean 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 widthNumber 舞台宽
heightNumber 舞台高
pixelRatioNumber this.pixelRatio optional 像素密度
forceBoolean false optional 是否强制刷新
Returns:
Type Description Stage 舞台本身。链式调用支持。 -
setOffset(x, y){Stage}
-
设置舞台偏移值
Name Type Description xNumber x
yNumber y
Returns:
Type Description Stage 舞台本身。链式调用支持。 -
viewport(x, y, width, height){Stage}
-
改viewport
Name Type Description xNumber x
yNumber y
widthNumber width
heightNumber height
Returns:
Type Description Stage 舞台本身。链式调用支持。 -
tick(dt){Stage}
-
渲染一帧
Name Type Description dtNumber 间隔时间
Returns:
Type Description Stage 舞台本身。链式调用支持。 -
enableDOMEvent(type, enabled){Stage}
-
开启/关闭舞台的DOM事件响应。要让舞台上的可视对象响应用户交互,必须先使用此方法开启舞台的相应事件的响应。
Name Type Description typeString | Array 要开启/关闭的事件名称或数组。
enabledBoolean 指定开启还是关闭。如果不传此参数,则默认为开启。
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 xNumber yNumber eventModeBoolean false optional Returns:
Type Description Mesh | null -
Name Type Default Description isChildboolean 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 forceBoolean true optional 是否强制更新
Returns:
Type Description Node this -
获取当前元素相对于指定元素的矩阵
Name Type Description ancestorNode optional 相对于的元素,需要是当前元素的祖先元素,不传表示获取世界矩阵
Returns:
Type Description Matrix4 返回获取的矩阵 -
遍历当前元素的子孙元素
Name Type Default Description callbackNodeTraverseCallback 每个元素都会调用这个函数处理
onlyChildBoolean false optional 是否只遍历子元素
Returns:
Type Description Node this -
遍历当前元素的子孙元素(广度优先)
Name Type Default Description callbackNodeTraverseCallback 每个元素都会调用这个函数处理
onlyChildBoolean false optional 是否只遍历子元素
Returns:
Type Description Node this -
根据函数来获取一个子孙元素(广度优先)
Name Type Description fnNodeGetChildByCallback 判读函数
Returns:
Type Description Node | null 返回获取到的子孙元素 -
根据 name path 来获取子孙元素
Name Type Description pathArray.<String> 名字数组, e.g., getChildByNamePath(['a', 'b', 'c'])
Returns:
Type Description Node | null 返回获取到的子孙元素 -
遍历调用子孙元素onUpdate方法
Name Type Description dtNumber Returns:
Type Description Node this -
根据函数来获取一个子孙元素
Name Type Description fnNodeGetChildByCallback 判读函数
Returns:
Type Description Node | null 返回获取到的子孙元素 -
根据函数来获取匹配的所有子孙元素
Name Type Description fnNodeGetChildByCallback 判读函数
Returns:
Type Description Array.<Node> 返回获取到的子孙元素 -
获取指定name的首个子孙元素
Name Type Description namestring 元素name
Returns:
Type Description Node | null 获取的元素 -
获取指定name的所有子孙元素
Name Type Description namestring 元素name
Returns:
Type Description Array.<Node> 获取的元素数组 -
获取指定id的子孙元素
Name Type Description idstring 元素id
Returns:
Type Description Node | null 获取的元素 -
获取指定类名的所有子孙元素
Name Type Description classNamestring 类名
Returns:
Type Description Array.<Node> 获取的元素数组 -
获取指定基类名的所有子孙元素
Name Type Description classNamestring 类名
Returns:
Type Description Array.<Node> 获取的元素数组 -
设置元素的缩放比例,如果只有一个参数三个轴等比缩放
Name Type Description xnumber X缩放比例
ynumber optional Y缩放比例
znumber optional Z缩放比例
Returns:
Type Description Node this -
设置元素的位置
Name Type Description xnumber X方向位置
ynumber Y方向位置
znumber Z方向位置
Returns:
Type Description Node this -
设置元素的旋转
Name Type Description xnumber X轴旋转角度, 角度制
ynumber Y轴旋转角度, 角度制
znumber Z轴旋转角度, 角度制
Returns:
Type Description Node this -
设置中心点
Name Type Description xNumber 中心点x
yNumber 中心点y
zNumber 中心点z
Returns:
Type Description Node this -
改变元素的朝向
Name Type Description nodeNode | Object | Vector3 需要朝向的元素,或者坐标
Returns:
Type Description Node this -
inherited raycast(ray, sort, eventMode){Array.<raycastInfo>|null}
-
raycast
Name Type Default Description rayRay sortBoolean false optional 是否按距离排序
eventModeBoolean false optional 是否事件模式
Returns:
Type Description Array.<raycastInfo> | null -
获取元素的包围盒信息
Name Type Description parentNode optional 元素相对于哪个祖先元素的包围盒,不传表示世界
currentMatrixMatrix4 optional 当前计算的矩阵
boundsBounds optional 当前计算的包围盒信息
Returns:
Type Description Bounds 返回计算的包围盒信息 -
销毁
Name Type Default Description rendererWebGLRenderer optional stage时可以不传
destroyTexturesBoolean false optional 是否销毁材质的贴图,默认不销毁
Returns:
Type Description Stage this