Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Primitive

基础图形网格,可以在运行时构建一些基础的网格。

Hierarchy

Index

Constructors

constructor

Properties

Protected _name

_name: string

_native

_native: string = ""
en

Serializable url for native asset. For internal usage.

zh

用于本机资产的可序列化URL。供内部使用。

default

""

_objFlags

_objFlags: number

_uuid

_uuid: string

内部使用。

info

info: Record<string, number>

创建此基础图形网格的可选参数,请在 onLoaded 调用之前设置。

loaded

loaded: boolean = true
en

Whether the asset is loaded or not

zh

该资源是否已经成功加载。

morphRendering

morphRendering: MorphRendering | null = null

type

type: number = PrimitiveType.BOX

此基础图形网格的类型,请在 onLoaded 调用之前设置。

Static PrimitiveType

PrimitiveType: EnumAlias<typeof PrimitiveType> = PrimitiveType

Static preventDeferredLoadDependents

preventDeferredLoadDependents: boolean = false
en

Indicates whether its dependent raw assets can support deferred load if the owner scene (or prefab) is marked as asyncLoadAssets.

zh

当场景或 Prefab 被标记为 asyncLoadAssets,禁止延迟加载该资源所依赖的其它 RawAsset。

default

false

Static preventPreloadNativeObject

preventPreloadNativeObject: boolean = false
en

Indicates whether its native object should be preloaded from native url.

zh

禁止预加载原生对象。

default

false

Accessors

nativeAsset

  • get nativeAsset(): ArrayBuffer
  • set nativeAsset(value: ArrayBuffer): void

data

  • get data(): Uint8Array

hash

  • get hash(): number

isValid

  • get isValid(): boolean
  • en

    Indicates whether the object is not yet destroyed. (It will not be available after being destroyed)
    When an object's destroy is called, it is actually destroyed after the end of this frame. So isValid will return false from the next frame, while isValid in the current frame will still be true. If you want to determine whether the current frame has called destroy, use isValid(obj, true), but this is often caused by a particular logical requirements, which is not normally required.

    zh

    表示该对象是否可用(被 destroy 后将不可用)。
    当一个对象的 destroy 调用以后,会在这一帧结束后才真正销毁。
    因此从下一帧开始 isValid 就会返回 false,而当前帧内 isValid 仍然会是 true。
    如果希望判断当前帧是否调用过 destroy,请使用 isValid(obj, true),不过这往往是特殊的业务需求引起的,通常情况下不需要这样。

    default

    true

    readonly
    example
    import { Node, log } from 'cc';
    const node = new Node();
    log(node.isValid);    // true
    node.destroy();
    log(node.isValid);    // true, still valid in this frame
    // after a frame...
    log(node.isValid);    // false, destroyed in the end of last frame

    Returns boolean

jointBufferIndices

  • get jointBufferIndices(): number[]

maxPosition

  • get maxPosition(): undefined | Vec3
  • en

    The maximum position of all vertices in the mesh

    zh

    (各分量都)大于等于此网格任何顶点位置的最大位置。

    deprecated

    Please use [[struct.maxPosition]] instead

    Returns undefined | Vec3

minPosition

  • get minPosition(): undefined | Vec3
  • en

    The minimum position of all vertices in the mesh

    zh

    (各分量都)小于等于此网格任何顶点位置的最大位置。

    deprecated

    Please use [[struct.minPosition]] instead

    Returns undefined | Vec3

name

  • get name(): string
  • set name(value: string): void

nativeUrl

  • get nativeUrl(): string
  • en

    Returns the url of this asset's native object, if none it will returns an empty string.

    zh

    返回该资源对应的目标平台资源的 URL,如果没有将返回一个空字符串。

    readonly

    Returns string

renderingSubMeshes

struct

subMeshCount

  • get subMeshCount(): number

Methods

destroyImmediate

  • _destroyImmediate(): void

destruct

  • _destruct(): void
  • Clear all references in the instance.

    NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject. You can override the _destruct method if you need, for example: _destruct: function () { for (var key in this) { if (this.hasOwnProperty(key)) { switch (typeof this[key]) { case 'string': this[key] = ''; break; case 'object': case 'function': this[key] = null; break; } } }

    Returns void

Private setRawAsset

  • setRawAsset(filename: string, inLibrary?: boolean): void
  • en

    Set native file name for this asset.

    zh

    为此资源设置原始文件名。

    seealso

    nativeUrl

    Parameters

    • filename: string
    • Default value inLibrary: boolean = true

    Returns void

assign

  • assign(struct: IStruct, data: Uint8Array): void
  • en

    Reset the struct and data of the mesh

    zh

    重置此网格的结构和数据。

    deprecated

    Will be removed in v3.0.0, please use reset instead

    Parameters

    • struct: IStruct

      The new struct

    • data: Uint8Array

      The new data

    Returns void

copyAttribute

  • copyAttribute(primitiveIndex: number, attributeName: GFXAttributeName, buffer: ArrayBuffer, stride: number, offset: number): boolean
  • en

    Read the requested attribute of the given sub mesh and fill into the given buffer.

    zh

    读取子网格的指定属性到目标缓冲区中。

    Parameters

    • primitiveIndex: number

      Sub mesh index

    • attributeName: GFXAttributeName

      Attribute name

    • buffer: ArrayBuffer

      The target array buffer

    • stride: number

      Byte distance between two attributes in the target buffer

    • offset: number

      The offset of the first attribute in the target buffer

    Returns boolean

    Return false if failed to access attribute, return true otherwise.

copyIndices

  • copyIndices(primitiveIndex: number, outputArray: number[] | ArrayBufferView): boolean
  • en

    Read the indices data of the given sub mesh and fill into the given array

    zh

    读取子网格的索引数据到目标数组中。

    Parameters

    • primitiveIndex: number

      Sub mesh index

    • outputArray: number[] | ArrayBufferView

      The target output array

    Returns boolean

    Return false if failed to access the indices data, return true otherwise.

Optional createNode

  • en

    Create a new node using this asset in the scene.
    If this type of asset dont have its corresponding node type, this method should be null.

    zh

    使用该资源在场景中创建一个新节点。
    如果这类资源没有相应的节点类型,该方法应该是空的。

    Parameters

    Returns void

destroy

  • destroy(): boolean

destroyRenderingMesh

  • destroyRenderingMesh(): void

emit

  • emit(type: EventType, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any): void
  • zh

    派发一个指定事件,并传递需要的参数

    en

    Trigger an event directly with the event name and necessary arguments.

    Parameters

    • type: EventType

      event type

    • Optional arg0: any
    • Optional arg1: any
    • Optional arg2: any
    • Optional arg3: any
    • Optional arg4: any

    Returns void

getBoneSpaceBounds

hasEventListener

  • hasEventListener(type: string, callback?: Function, target?: undefined | object): boolean
  • zh

    检查指定事件是否已注册回调。

    en

    Checks whether there is correspond event listener registered on the given event.

    Parameters

    • type: string

      Event type.

    • Optional callback: Function

      Callback function when event triggered.

    • Optional target: undefined | object

      Callback callee.

    Returns boolean

initialize

  • initialize(): void

merge

  • merge(mesh: Mesh, worldMatrix?: Mat4, validate?: undefined | false | true): boolean
  • en

    Merge the given mesh into the current mesh

    zh

    合并指定的网格到此网格中。

    Parameters

    • mesh: Mesh

      The mesh to be merged

    • Optional worldMatrix: Mat4

      The world matrix of the given mesh

    • Optional validate: undefined | false | true

    Returns boolean

    Check the mesh state and return the validation result.

off

  • en

    Removes the listeners previously registered with the same type, callback, target and or useCapture, if only type is passed as parameter, all listeners registered with that type will be removed.

    zh

    删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。

    example

    import { log } from 'cc'; // register fire eventListener var callback = eventTarget.on('fire', function () { log("fire in the hole"); }, target); // remove fire event listener eventTarget.off('fire', callback, target); // remove all fire event listeners eventTarget.off('fire');

    Type parameters

    • TFunction: Function

    Parameters

    • type: EventType

      A string representing the event type being removed.

    • Optional callback: TFunction

      The callback to remove.

    • Optional thisArg: any

    Returns void

on

  • on<TFunction>(type: EventType, callback: TFunction, thisArg?: any, once?: undefined | false | true): typeof callback
  • en

    Register an callback of a specific event type on the EventTarget. This type of event should be triggered via emit.

    zh

    注册事件目标的特定事件类型回调。这种类型的事件应该被 emit 触发。

    example

    import { log } from 'cc'; eventTarget.on('fire', function () { log("fire in the hole"); }, node);

    Type parameters

    • TFunction: Function

    Parameters

    • type: EventType

      A string representing the event type to listen for.

    • callback: TFunction

      The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

    • Optional thisArg: any

      The target (this object) to invoke the callback, can be null

    • Optional once: undefined | false | true

    Returns typeof callback

    • Just returns the incoming callback so you can save the anonymous function easier.

onLoaded

  • onLoaded(): void

once

  • once<TFunction>(type: EventType, callback: TFunction, thisArg?: any): typeof callback
  • en

    Register an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.

    zh

    注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。

    example

    import { log } from 'cc'; eventTarget.once('fire', function () { log("this is the callback and will be invoked only once"); }, node);

    Type parameters

    • TFunction: Function

    Parameters

    • type: EventType

      A string representing the event type to listen for.

    • callback: TFunction

      The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

    • Optional thisArg: any

    Returns typeof callback

readAttribute

  • readAttribute(primitiveIndex: number, attributeName: GFXAttributeName): Storage | null
  • en

    Read the requested attribute of the given sub mesh

    zh

    读取子网格的指定属性。

    Parameters

    • primitiveIndex: number

      Sub mesh index

    • attributeName: GFXAttributeName

      Attribute name

    Returns Storage | null

    Return null if not found or can't read, otherwise, will create a large enough typed array to contain all data of the attribute, the array type will match the data type of the attribute.

readIndices

  • readIndices(primitiveIndex: number): null | Uint8Array | Uint16Array | Uint32Array
  • en

    Read the indices data of the given sub mesh

    zh

    读取子网格的索引数据。

    Parameters

    • primitiveIndex: number

      Sub mesh index

    Returns null | Uint8Array | Uint16Array | Uint32Array

    Return null if not found or can't read, otherwise, will create a large enough typed array to contain all indices data, the array type will use the corresponding stride size.

removeAll

  • removeAll(typeOrTarget: string | object): void
  • zh

    移除在特定事件类型中注册的所有回调或在某个目标中注册的所有回调。

    en

    Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

    Parameters

    • typeOrTarget: string | object

      The event type or target with which the listeners will be removed

    Returns void

reset

Private serialize

  • serialize(): void

targetOff

  • targetOff(typeOrTarget: string | object): void
  • en

    Removes all callbacks previously registered with the same target (passed as parameter). This is not for removing all listeners in the current event target, and this is not for removing all listeners the target parameter have registered. It's only for removing all listeners (callback and target couple) registered on the current event target by the target parameter.

    zh

    在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。 这个函数无法删除当前 EventTarget 的所有事件监听器,也无法删除 target 参数所注册的所有事件监听器。 这个函数只能删除 target 参数在当前 EventTarget 上注册的所有事件监听器。

    Parameters

    • typeOrTarget: string | object

      The target to be searched for all related listeners

    Returns void

toString

  • toString(): string
  • en

    Returns the string representation of the object.
    The Asset object overrides the toString() method of the Object object.
    JavaScript calls the toString() method automatically
    when an asset is to be represented as a text value or when a texture is referred to in a string concatenation.

    For assets of the native type, it will return this.nativeUrl.
    Otherwise, an empty string is returned.
    This method may be overwritten by subclasses.

    zh

    返回对象的字符串表示形式。
    Asset 对象将会重写 Object 对象的 toString() 方法。
    当资源要表示为文本值时或在字符串连接时引用时,
    JavaScript 会自动调用 toString() 方法。

    对于原始类型的资源,它将返回this.nativeUrl
    否则,返回空字符串。
    子类可能会覆盖此方法。

    method

    toString

    Returns string

validateMergingMesh

  • validateMergingMesh(mesh: Mesh): boolean
  • en

    Validation for whether the given mesh can be merged into the current mesh. To pass the validation, it must satisfy either of these two requirements:

    • When the current mesh have no data
    • When the two mesh have the same vertex bundle count, the same sub meshes count, and the same sub mesh layout.

    Same mesh layout means:

    • They have the same primitive type and reference to the same amount vertex bundle with the same indices.
    • And they all have or don't have index view
    zh

    验证指定网格是否可以合并至当前网格。

    当满足以下条件之一时,指定网格可以合并至当前网格:

    • 当前网格无数据而待合并网格有数据;
    • 它们的顶点块数目相同且对应顶点块的布局一致,并且它们的子网格数目相同且对应子网格的布局一致。

    两个顶点块布局一致当且仅当:

    • 它们具有相同数量的顶点属性且对应的顶点属性具有相同的属性格式。

    两个子网格布局一致,当且仅当:

    • 它们具有相同的图元类型并且引用相同数量、相同索引的顶点块;并且,
    • 要么都需要索引绘制,要么都不需要索引绘制。

    Parameters

    • mesh: Mesh

      The other mesh to be validated

    Returns boolean

Static deferredDestroy

  • _deferredDestroy(): void

Static deserialize

  • deserialize(data: any): any

Static isRawAssetType

  • isRawAssetType(ctor: Function): boolean

Generated using TypeDoc