目录

FaceView

Class Info

public class FaceView extends GLSurfaceView implements Renderer, OnFrameAvailableListener

提供面部AR场景渲染能力。

Public Constructor Summary

Constructor Name

FaceView(Context context, AttributeSet attributeSet)

构造方法,使用Layout XML注册使用。

FaceView(Context context, SdkType sdkType)

构造方法,使用new方法时调用。

Public Method Summary

Qualifier and Type

Method Name and Description

void

clearResource()

清除场景中加载的素材。

void

destroy()

释放所有已加载的资源。

int

loadAsset(String resourceName, LandmarkType landmark)

加载渲染素材。

void

onDrawFrame(GL10 gl)

当前帧被绘制时该方法被调用。

void

onFrameAvailable(SurfaceTexture surfaceTexture)

用于通知数据流中新的帧可用的回调方法。

void

onPause()

暂停渲染线程。

void

onResume()

恢复渲染线程。

void

onSurfaceChanged(GL10 gl, int width, int height)

当Surface的大小被改变时该方法被调用。

void

onSurfaceCreated(GL10 gl, EGLConfig config)

当Surface被创建时该方法被调用。

void

setInitialPose(int index, float[] position, float[] scale, float[] rotation)

设置素材的初始姿态。

void

surfaceDestroyed(SurfaceHolder holder)

生命周期方法,当Surface被销毁时该方法被调用。

Public Constructors

[h2]FaceView(Context context, AttributeSet attributeSet)

Constructor

public FaceView(Context context, AttributeSet attributeSet)

使用注册Layout XML的方法创建一个FaceView对象。

Parameters

Name

Description

context

Activity上下文。

attributeSet

Layout XML属性集。

[h2]FaceView(Context context, SdkType sdkType)

Constructor

public FaceView(Context context, SdkType sdkType)

使用new方法创建一个FaceView对象。

Parameters

Name

Description

context

Activity上下文。

SdkType

SDK类型。可选择使用ML_KIT与AR_ENGINE。

Public Methods

[h2]clearResource

Method

public void clearResource()

清除场景中加载的素材。

[h2]destroy

Method

public void destroy()

释放所有已加载的资源。

通常情况下,如果不需要进行资源管理,则该函数不需要显式调用。

FaceView生命周期结束时,会自动释放所有已加载素材。

[h2]loadAsset

Method

public int loadAsset(String resourceName, LandmarkType landmark)

加载渲染素材,并设置标志点位置。

Parameters

Name

Description

resourceName

素材文件路径名称。

landmark

素材标定位置。

Returns

Type

Description

int

素材索引值。

返回值为负数时,表示加载失败;返回值为非负数时,表示已加载素材的索引值。

[h2]onDrawFrame

Method

public void onDrawFrame(GL10 gl)

当前帧被绘制时该方法被调用。

Parameters

Name

Description

gl

gl接口。

[h2]onFrameAvailable

Method

public void onFrameAvailable(SurfaceTexture surfaceTexture)

用于通知数据流中新的帧可用的回调方法。

Parameters

Name

Description

surfaceTexture

surfaceTexture对象。

[h2]onPause

Method

public void onPause()

暂停渲染线程。

[h2]onResume

Method

public void onResume()

恢复渲染线程。

[h2]onSurfaceChanged

Method

public void onSurfaceChanged(GL10 gl, int width, int height)

当Surface的大小被改变时该方法被调用。

Parameters

Name

Description

gl

gl接口。

width

Surface的宽度,单位pixel。

height

Surface的高度,单位pixel。

[h2]onSurfaceCreated

Method

public void onSurfaceCreated(GL10 gl, EGLConfig config)

当Surface被创建时该方法被调用。

Parameters

Name

Description

gl

gl接口。

config

EGLConfig对象。

[h2]setInitialPose

Method

public void setInitialPose(int index, float[] position, float[] scale, float[] rotation)

设置素材的初始位置与姿态。

Parameters

Name

Description

index

已加载素材的索引值。

position

素材在场景中的位置坐标数组。

类型为float[3]数组,分别表示在X轴、Y轴、Z轴的坐标。

scale

素材的缩放系数数组。

类型为float[3]数组,分别表示X轴、Y轴、Z轴的缩放系数。

系数值为1.0f时,表示不缩放。

rotation

素材的旋转四元数。

类型为float[4]数组,分别表示归一化四元数的w、x、y、z。

[h2]surfaceDestroyed

Method

public void surfaceDestroyed(SurfaceHolder holder)

生命周期方法,当Surface被销毁时该方法被调用。

Parameters

Name

Description

holder

Surface持有对象,不能为null。