mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 23:21:05 +00:00
commit
24f2db9ebc
@ -293,62 +293,6 @@ void JSSceneView::Create(const JSCallbackInfo& info)
|
||||
ModelView::GetInstance()->SetModelSource(ohosPath);
|
||||
}
|
||||
|
||||
void JSSceneView::JsCamera(const JSCallbackInfo& info)
|
||||
{
|
||||
// Parse the info object.
|
||||
if (info.Length() <= 0 || !info[0]->IsObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AnimationOption animOption = ViewStackModel::GetInstance()->GetImplicitAnimationOption();
|
||||
JSRef<JSObject> jsObj = JSRef<JSObject>::Cast(info[0]);
|
||||
std::unordered_map<std::string, float> perspect { { "zNear", 0.5f }, { "zFar", 50.0f }, { "yFov", 60.0f } };
|
||||
GetModelProperty(jsObj, "perspective", perspect);
|
||||
ModelView::GetInstance()->SetCameraFrustum(perspect["zNear"], perspect["zFar"], perspect["yFov"]);
|
||||
// cameraSpace
|
||||
std::unordered_map<std::string, float> positionAng { { "theta", 0.0f }, { "phi", 0.0f }, { "radius", 4.0f } };
|
||||
std::unordered_map<std::string, float> position { { "x", 0.0f }, { "y", 0.0f }, { "z", 4.0f } };
|
||||
std::unordered_map<std::string, float> front { { "x", 0.0f }, { "y", 0.0f }, { "z", 0.0f } };
|
||||
std::unordered_map<std::string, float> up { { "x", 0.0f }, { "y", 0.0f }, { "z", 0.0f } };
|
||||
if (GetModelProperty(jsObj, "cameraSpace", positionAng)) {
|
||||
ModelView::GetInstance()->SetCameraPosition(AnimatableFloat(positionAng["theta"], animOption),
|
||||
AnimatableFloat(0, animOption), AnimatableFloat(positionAng["phi"], animOption),
|
||||
AnimatableFloat(positionAng["radius"], animOption), true);
|
||||
return;
|
||||
}
|
||||
auto itemCameraSpace = jsObj->GetProperty("cameraSpace");
|
||||
if (itemCameraSpace->IsObject()) {
|
||||
JSRef<JSObject> spaceObj = JSRef<JSObject>::Cast(itemCameraSpace);
|
||||
// position
|
||||
GetModelProperty(spaceObj, "position", position);
|
||||
// front
|
||||
GetModelProperty(spaceObj, "front", front);
|
||||
// up
|
||||
GetModelProperty(spaceObj, "up", up);
|
||||
}
|
||||
ModelView::GetInstance()->SetCameraPosition(AnimatableFloat(position["x"], animOption),
|
||||
AnimatableFloat(position["y"], animOption), AnimatableFloat(position["z"], animOption),
|
||||
AnimatableFloat(0.0f, animOption), false);
|
||||
Vec3 lookVec(front["x"], front["y"], front["z"]);
|
||||
ModelView::GetInstance()->SetCameraLookAt(lookVec);
|
||||
Vec3 upVec(up["x"], up["y"], up["z"]);
|
||||
ModelView::GetInstance()->SetCameraUp(upVec);
|
||||
}
|
||||
|
||||
void JSSceneView::JsSetTransparent(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!info[0]->IsBoolean()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool value = info[0]->ToBoolean();
|
||||
ModelView::GetInstance()->SetTransparent(value);
|
||||
}
|
||||
|
||||
void JSSceneView::JsSetBackground(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1) {
|
||||
@ -365,162 +309,6 @@ void JSSceneView::JsSetBackground(const JSCallbackInfo& info)
|
||||
ModelView::GetInstance()->SetBackground(ohosPath);
|
||||
}
|
||||
|
||||
void JSSceneView::JsLight(const JSCallbackInfo& info)
|
||||
{
|
||||
// Parse the info object.
|
||||
if (info.Length() <= 0 || !info[0]->IsObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
JSRef<JSObject> jsObj = JSRef<JSObject>::Cast(info[0]);
|
||||
JSRef<JSVal> itemType = jsObj->GetProperty("type");
|
||||
JSRef<JSVal> itemIntensity = jsObj->GetProperty("intensity");
|
||||
JSRef<JSVal> itemShadow = jsObj->GetProperty("shadow");
|
||||
auto type = static_cast<NG::ModelLightType>((itemType->IsNumber()) ? itemType->ToNumber<int32_t>() : 1);
|
||||
int intensity = (itemIntensity->IsNumber()) ? itemIntensity->ToNumber<int32_t>() : 10;
|
||||
bool shadow = (itemShadow->IsBoolean()) ? itemShadow->ToBoolean() : false;
|
||||
JSRef<JSVal> lightColor = jsObj->GetProperty("color");
|
||||
Color color(0xffffffff); // red:255, green:255, blue:255
|
||||
ParseJsColor(lightColor, color);
|
||||
AnimationOption animOption = ViewStackModel::GetInstance()->GetImplicitAnimationOption();
|
||||
Vec3 inputColor = Vec3(color.GetRed() / 255.0f, color.GetGreen() / 255.0f, color.GetBlue() / 255.0f, animOption);
|
||||
OHOS::Ace::NG::ModelPosition position;
|
||||
double maxInvalid = std::numeric_limits<double>::max();
|
||||
Quaternion rotation = Quaternion(maxInvalid, maxInvalid, maxInvalid, maxInvalid);
|
||||
std::unordered_map<std::string, float> positionAng { { "theta", 0.0f }, { "phi", 0.0f }, { "radius", 4.0f } };
|
||||
std::unordered_map<std::string, float> pos { { "x", 0.0f }, { "y", 1.0f }, { "z", 0.0f } };
|
||||
std::unordered_map<std::string, float> quat { { "x", 0.0f }, { "y", 1.0f }, { "z", 0.0f }, { "w", 1.0f } };
|
||||
if (GetModelProperty(jsObj, "lightSpace", positionAng)) {
|
||||
position.Set({ AnimatableFloat(positionAng["theta"], animOption), AnimatableFloat(0.0f, animOption),
|
||||
AnimatableFloat(positionAng["phi"], animOption) },
|
||||
AnimatableFloat(positionAng["radius"], animOption), true);
|
||||
ModelView::GetInstance()->AddLight(AceType::MakeRefPtr<NG::ModelLight>(
|
||||
type, inputColor, AnimatableFloat(intensity, animOption), shadow, position, rotation));
|
||||
return;
|
||||
}
|
||||
auto itemLightSpace = jsObj->GetProperty("lightSpace");
|
||||
if (itemLightSpace->IsObject()) {
|
||||
JSRef<JSObject> spaceObj = JSRef<JSObject>::Cast(itemLightSpace);
|
||||
GetModelProperty(spaceObj, "position", pos);
|
||||
position.Set({ AnimatableFloat(pos["x"], animOption), AnimatableFloat(pos["y"], animOption),
|
||||
AnimatableFloat(pos["z"], animOption) },
|
||||
AnimatableFloat(0.0f, animOption), false);
|
||||
GetModelProperty(spaceObj, "rotation", quat);
|
||||
rotation = Quaternion(quat["x"], quat["y"], quat["z"], quat["w"]);
|
||||
}
|
||||
ModelView::GetInstance()->AddLight(AceType::MakeRefPtr<NG::ModelLight>(
|
||||
type, inputColor, AnimatableFloat(intensity, animOption), shadow, position, rotation));
|
||||
}
|
||||
|
||||
void JSSceneView::JsAddCube(const JSCallbackInfo& info)
|
||||
{
|
||||
// Parse the info object.
|
||||
if (info.Length() <= 0 || !info[0]->IsObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
JSRef<JSObject> jsObj = JSRef<JSObject>::Cast(info[0]);
|
||||
auto name = jsObj->GetPropertyValue<std::string>("name", "");
|
||||
auto width = jsObj->GetPropertyValue<double>("width", 0.0);
|
||||
auto height = jsObj->GetPropertyValue<double>("height", 0.0);
|
||||
auto depth = jsObj->GetPropertyValue<double>("depth", 0.0);
|
||||
|
||||
OHOS::Render3D::Vec3 position(0.0f, 0.0f, 0.0f);
|
||||
if (jsObj->HasProperty("position")) {
|
||||
JSRef<JSVal> positionArgs = jsObj->GetProperty("position");
|
||||
if (positionArgs->IsObject()) {
|
||||
JSRef<JSObject> posObj = JSRef<JSObject>::Cast(positionArgs);
|
||||
position.SetX(posObj->GetPropertyValue<double>("x", 0.0));
|
||||
position.SetY(posObj->GetPropertyValue<double>("y", 0.0));
|
||||
position.SetZ(posObj->GetPropertyValue<double>("z", 0.0));
|
||||
}
|
||||
}
|
||||
|
||||
ModelView::GetInstance()->AddGeometry(
|
||||
std::make_shared<OHOS::Render3D::Cube>(name.c_str(), width, height, depth, position));
|
||||
}
|
||||
|
||||
void JSSceneView::JsAddSphere(const JSCallbackInfo& info)
|
||||
{
|
||||
// Parse the info object.
|
||||
if (info.Length() <= 0 || !info[0]->IsObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
JSRef<JSObject> jsObj = JSRef<JSObject>::Cast(info[0]);
|
||||
auto name = jsObj->GetPropertyValue<std::string>("name", "");
|
||||
auto radius = jsObj->GetPropertyValue<double>("radius", 0.0);
|
||||
auto rings = jsObj->GetPropertyValue<int32_t>("rings", 0);
|
||||
auto sectors = jsObj->GetPropertyValue<int32_t>("sectors", 0);
|
||||
|
||||
OHOS::Render3D::Vec3 position(0.0f, 0.0f, 0.0f);
|
||||
if (jsObj->HasProperty("position")) {
|
||||
JSRef<JSVal> positionArgs = jsObj->GetProperty("position");
|
||||
if (positionArgs->IsObject()) {
|
||||
JSRef<JSObject> posObj = JSRef<JSObject>::Cast(positionArgs);
|
||||
position.SetX(posObj->GetPropertyValue<double>("x", 0.0));
|
||||
position.SetY(posObj->GetPropertyValue<double>("y", 0.0));
|
||||
position.SetZ(posObj->GetPropertyValue<double>("z", 0.0));
|
||||
}
|
||||
}
|
||||
|
||||
ModelView::GetInstance()->AddGeometry(
|
||||
std::make_shared<OHOS::Render3D::Sphere>(name.c_str(), radius, rings, sectors, position));
|
||||
}
|
||||
|
||||
void JSSceneView::JsAddCone(const JSCallbackInfo& info)
|
||||
{
|
||||
// Parse the info object.
|
||||
if (info.Length() <= 0 || !info[0]->IsObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
JSRef<JSObject> jsObj = JSRef<JSObject>::Cast(info[0]);
|
||||
auto name = jsObj->GetPropertyValue<std::string>("name", "");
|
||||
auto radius = jsObj->GetPropertyValue<double>("radius", 0.0);
|
||||
auto length = jsObj->GetPropertyValue<int32_t>("length", 0);
|
||||
auto sectors = jsObj->GetPropertyValue<int32_t>("sectors", 0);
|
||||
|
||||
OHOS::Render3D::Vec3 position(0.0f, 0.0f, 0.0f);
|
||||
if (jsObj->HasProperty("position")) {
|
||||
JSRef<JSVal> positionArgs = jsObj->GetProperty("position");
|
||||
if (positionArgs->IsObject()) {
|
||||
JSRef<JSObject> posObj = JSRef<JSObject>::Cast(positionArgs);
|
||||
position.SetX(posObj->GetPropertyValue<double>("x", 0.0));
|
||||
position.SetY(posObj->GetPropertyValue<double>("y", 0.0));
|
||||
position.SetZ(posObj->GetPropertyValue<double>("z", 0.0));
|
||||
}
|
||||
}
|
||||
|
||||
ModelView::GetInstance()->AddGeometry(
|
||||
std::make_shared<OHOS::Render3D::Cone>(name.c_str(), radius, length, sectors, position));
|
||||
}
|
||||
|
||||
void JSSceneView::JsGLTFAnimation(const JSCallbackInfo& info)
|
||||
{
|
||||
// Parse the info object.
|
||||
if (info.Length() < 1 || !info[0]->IsObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
JSRef<JSObject> jsObj = JSRef<JSObject>::Cast(info[0]);
|
||||
JSRef<JSVal> itemName = jsObj->GetProperty("name");
|
||||
std::string name = (itemName->IsString()) ? itemName->ToString() : "";
|
||||
JSRef<JSVal> itemState = jsObj->GetProperty("state");
|
||||
auto state = (itemState->IsNumber()) ? itemState->ToNumber<int32_t>() : 0;
|
||||
JSRef<JSVal> itemRepeat = jsObj->GetProperty("repeatCount");
|
||||
auto repeatCount = (itemRepeat->IsNumber()) ? itemRepeat->ToNumber<int32_t>() : -1;
|
||||
JSRef<JSVal> itemSpeed = jsObj->GetProperty("speed");
|
||||
auto speed = (itemSpeed->IsNumber()) ? itemSpeed->ToNumber<float>() : 1.0f;
|
||||
JSRef<JSVal> itemDuration = jsObj->GetProperty("duration");
|
||||
auto duration = (itemDuration->IsNumber()) ? itemDuration->ToNumber<float>() : -1.0f;
|
||||
JSRef<JSVal> itemReverse = jsObj->GetProperty("reverse");
|
||||
auto reverse = (itemReverse->IsBoolean()) ? itemReverse->ToBoolean() : false;
|
||||
|
||||
ModelView::GetInstance()->AddGLTFAnimation(std::make_shared<Render3D::GLTFAnimation>(
|
||||
name, static_cast<Render3D::AnimationState>(state), repeatCount, speed, duration, reverse));
|
||||
}
|
||||
|
||||
void JSSceneView::JsAddCustomRender(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() != 2) {
|
||||
@ -543,40 +331,6 @@ void JSSceneView::JsAddCustomRender(const JSCallbackInfo& info)
|
||||
ModelView::GetInstance()->AddCustomRender(desc);
|
||||
}
|
||||
|
||||
void JSSceneView::JsWidth(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
CalcDimension value;
|
||||
if (!ParseJsDimensionVp(info[0], value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (LessNotEqual(value.Value(), 0.0)) {
|
||||
value.SetValue(0.0);
|
||||
}
|
||||
ModelView::GetInstance()->SetWidth(value);
|
||||
}
|
||||
|
||||
void JSSceneView::JsHeight(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
CalcDimension value;
|
||||
if (!ParseJsDimensionVp(info[0], value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (LessNotEqual(value.Value(), 0.0)) {
|
||||
value.SetValue(0.0);
|
||||
}
|
||||
ModelView::GetInstance()->SetHeight(value);
|
||||
}
|
||||
|
||||
void JSSceneView::JsRenderWidth(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1) {
|
||||
@ -697,17 +451,8 @@ void JSSceneView::JSBind(BindingTarget globalObj)
|
||||
MethodOptions opt = MethodOptions::NONE;
|
||||
JSClass<JSSceneView>::StaticMethod("create", &JSSceneView::Create, opt);
|
||||
JSClass<JSSceneView>::StaticMethod("gestureAccess", &JSSceneView::JsSetHandleCameraMove);
|
||||
JSClass<JSSceneView>::StaticMethod("camera", &JSSceneView::JsCamera);
|
||||
JSClass<JSSceneView>::StaticMethod("transparent", &JSSceneView::JsSetTransparent);
|
||||
JSClass<JSSceneView>::StaticMethod("environment", &JSSceneView::JsSetBackground);
|
||||
JSClass<JSSceneView>::StaticMethod("light", &JSSceneView::JsLight);
|
||||
JSClass<JSSceneView>::StaticMethod("cube", &JSSceneView::JsAddCube);
|
||||
JSClass<JSSceneView>::StaticMethod("sphere", &JSSceneView::JsAddSphere);
|
||||
JSClass<JSSceneView>::StaticMethod("cone", &JSSceneView::JsAddCone);
|
||||
JSClass<JSSceneView>::StaticMethod("modelAnimation", &JSSceneView::JsGLTFAnimation);
|
||||
JSClass<JSSceneView>::StaticMethod("customRender", &JSSceneView::JsAddCustomRender);
|
||||
JSClass<JSSceneView>::StaticMethod("width", &JSSceneView::JsWidth);
|
||||
JSClass<JSSceneView>::StaticMethod("height", &JSSceneView::JsHeight);
|
||||
JSClass<JSSceneView>::StaticMethod("shader", &JSSceneView::JsShader);
|
||||
JSClass<JSSceneView>::StaticMethod("renderWidth", &JSSceneView::JsRenderWidth);
|
||||
JSClass<JSSceneView>::StaticMethod("renderHeight", &JSSceneView::JsRenderHeight);
|
||||
|
@ -27,17 +27,8 @@ public:
|
||||
static void Create(const JSCallbackInfo& info);
|
||||
static void JsOnClick(const JSCallbackInfo& info);
|
||||
static void JsSetHandleCameraMove(const JSCallbackInfo& info);
|
||||
static void JsCamera(const JSCallbackInfo& info);
|
||||
static void JsSetTransparent(const JSCallbackInfo& info);
|
||||
static void JsSetBackground(const JSCallbackInfo& info);
|
||||
static void JsLight(const JSCallbackInfo& info);
|
||||
static void JsAddCube(const JSCallbackInfo& info);
|
||||
static void JsAddSphere(const JSCallbackInfo& info);
|
||||
static void JsAddCone(const JSCallbackInfo& info);
|
||||
static void JsGLTFAnimation(const JSCallbackInfo& info);
|
||||
static void JsAddCustomRender(const JSCallbackInfo& info);
|
||||
static void JsWidth(const JSCallbackInfo& info);
|
||||
static void JsHeight(const JSCallbackInfo& info);
|
||||
static void JsRenderHeight(const JSCallbackInfo& info);
|
||||
static void JsRenderWidth(const JSCallbackInfo& info);
|
||||
static void JsRenderFrameRate(const JSCallbackInfo& info);
|
||||
|
@ -17,9 +17,6 @@
|
||||
#include "core/components_ng/render/adapter/rosen_render_context.h"
|
||||
#include "frameworks/core/common/container.h"
|
||||
|
||||
#include "graphics_task.h"
|
||||
#include "ohos/graphics_manager.h"
|
||||
|
||||
#include "render_service_client/core/ui/rs_ui_director.h"
|
||||
#include "render_service_client/core/ui/rs_ui_share_context.h"
|
||||
|
||||
@ -193,23 +190,7 @@ void ModelAdapterWrapper::OnPaint3D(const RefPtr<ModelPaintProperty>& modelPaint
|
||||
if (modelPaintProperty->NeedsModelBackgroundSetup()) {
|
||||
UpdateEnviroment(modelPaintProperty);
|
||||
}
|
||||
|
||||
if (modelPaintProperty->NeedsCameraSetup()) {
|
||||
UpdateCamera(modelPaintProperty);
|
||||
}
|
||||
|
||||
if (modelPaintProperty->NeedsLightsSetup()) {
|
||||
UpdateLights(modelPaintProperty);
|
||||
}
|
||||
|
||||
if (modelPaintProperty->NeedsAnimationsSetup()) {
|
||||
UpdateGLTFAnimations(modelPaintProperty);
|
||||
}
|
||||
|
||||
if (modelPaintProperty->NeedsGeometriesSetup()) {
|
||||
UpdateGeometries(modelPaintProperty);
|
||||
}
|
||||
|
||||
|
||||
if (modelPaintProperty->NeedsCustomRenderSetup()) {
|
||||
UpdateCustomRender(modelPaintProperty);
|
||||
}
|
||||
@ -330,7 +311,7 @@ void ModelAdapterWrapper::UpdateScene(const RefPtr<ModelPaintProperty>& modelPai
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!modelPaintProperty->GetModelSource().has_value()) {
|
||||
if (modelPaintProperty->GetModelSourceValue().empty()) {
|
||||
LOGW("UpdateScene invalid model source");
|
||||
return;
|
||||
}
|
||||
@ -352,7 +333,7 @@ void ModelAdapterWrapper::UpdateEnviroment(const RefPtr<ModelPaintProperty>& mod
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!modelPaintProperty->GetModelBackground().has_value()) {
|
||||
if (modelPaintProperty->GetModelBackgroundValue().empty()) {
|
||||
LOGW("UpdateEnviroment invalid model background");
|
||||
return;
|
||||
}
|
||||
@ -387,193 +368,6 @@ void ModelAdapterWrapper::HandleCameraMove(const Render3D::PointerEvent& event)
|
||||
});
|
||||
}
|
||||
|
||||
void ExtractCameraProperty(const RefPtr<ModelPaintProperty>& modelPaintProperty,
|
||||
CameraProperty& camera)
|
||||
{
|
||||
if (modelPaintProperty->GetCameraPosition().has_value()) {
|
||||
auto& v = modelPaintProperty->GetCameraPosition().value();
|
||||
camera.position_.SetPosition(Render3D::Vec3 { v.GetX(), v.GetY(), v.GetZ() });
|
||||
}
|
||||
|
||||
if (modelPaintProperty->GetCameraDistance().has_value()) {
|
||||
const auto& v = modelPaintProperty->GetCameraDistance().value().GetValue();
|
||||
camera.position_.SetDistance(v);
|
||||
}
|
||||
|
||||
if (modelPaintProperty->GetCameraIsAngular().has_value()) {
|
||||
auto& v = modelPaintProperty->GetCameraIsAngular().value();
|
||||
camera.position_.SetIsAngular(v);
|
||||
}
|
||||
|
||||
if (modelPaintProperty->GetCameraLookAt().has_value()) {
|
||||
const auto& v = modelPaintProperty->GetCameraLookAt().value();
|
||||
camera.lookAt_.SetX(v.GetX());
|
||||
camera.lookAt_.SetY(v.GetY());
|
||||
camera.lookAt_.SetZ(v.GetZ());
|
||||
}
|
||||
|
||||
if (modelPaintProperty->GetCameraUp().has_value()) {
|
||||
const auto& v = modelPaintProperty->GetCameraUp().value();
|
||||
camera.up_.SetX(v.GetX());
|
||||
camera.up_.SetY(v.GetY());
|
||||
camera.up_.SetZ(v.GetZ());
|
||||
}
|
||||
|
||||
if (modelPaintProperty->GetCameraUp().has_value()) {
|
||||
const auto& v = modelPaintProperty->GetCameraUp().value();
|
||||
camera.up_.SetX(v.GetX());
|
||||
camera.up_.SetY(v.GetY());
|
||||
camera.up_.SetZ(v.GetZ());
|
||||
}
|
||||
|
||||
if (modelPaintProperty->GetCameraRotation().has_value()) {
|
||||
const auto& v = modelPaintProperty->GetCameraRotation().value();
|
||||
camera.rotation_.SetX(v.GetX());
|
||||
camera.rotation_.SetY(v.GetY());
|
||||
camera.rotation_.SetZ(v.GetZ());
|
||||
camera.rotation_.SetW(v.GetW());
|
||||
}
|
||||
|
||||
if (modelPaintProperty->GetCameraZNear().has_value()) {
|
||||
camera.near_ = modelPaintProperty->GetCameraZNear().value();
|
||||
}
|
||||
|
||||
if (modelPaintProperty->GetCameraZFar().has_value()) {
|
||||
camera.far_ = modelPaintProperty->GetCameraZFar().value();
|
||||
}
|
||||
|
||||
if (modelPaintProperty->GetCameraFOV().has_value()) {
|
||||
camera.fov_ = modelPaintProperty->GetCameraFOV().value();
|
||||
}
|
||||
}
|
||||
|
||||
void ModelAdapterWrapper::UpdateCamera(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
#if defined(KIT_3D_ENABLE)
|
||||
if (sceneAdapter_) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
CameraProperty camera;
|
||||
ExtractCameraProperty(modelPaintProperty, camera);
|
||||
Render3D::GraphicsTask::GetInstance().PushSyncMessage([weak = WeakClaim(this), &camera] {
|
||||
auto adapter = weak.Upgrade();
|
||||
CHECK_NULL_VOID(adapter);
|
||||
CHECK_NULL_VOID(adapter->widgetAdapter_);
|
||||
|
||||
adapter->widgetAdapter_->SetupCameraTransform(camera.position_, camera.lookAt_, camera.up_,
|
||||
camera.rotation_);
|
||||
adapter->widgetAdapter_->SetupCameraViewProjection(camera.near_, camera.far_, camera.fov_);
|
||||
});
|
||||
}
|
||||
|
||||
void ExtractLightsProperty(const RefPtr<ModelPaintProperty>& modelPaintProperty,
|
||||
std::vector<std::shared_ptr<Render3D::Light>>& lights)
|
||||
{
|
||||
auto& propLights = modelPaintProperty->GetModelLights().value();
|
||||
for (auto& light : propLights) {
|
||||
const auto& color = light->GetLightColor();
|
||||
const auto& rotation = light->GetRotation();
|
||||
const auto& position = light->GetPosition();
|
||||
|
||||
Render3D::Position lightPosition;
|
||||
lightPosition.SetPosition(Render3D::Vec3(position.GetX(), position.GetY(), position.GetZ()));
|
||||
lightPosition.SetDistance(position.GetDistance().GetValue());
|
||||
lightPosition.SetIsAngular(position.GetIsAngular());
|
||||
Render3D::LightType lightType;
|
||||
switch (light->GetLightType()) {
|
||||
case ModelLightType::INVALID_LIGHT:
|
||||
lightType = Render3D::LightType::INVALID;
|
||||
break;
|
||||
case ModelLightType::DIRECTIONAL_LIGHT:
|
||||
lightType = Render3D::LightType::DIRECTIONAL;
|
||||
break;
|
||||
case ModelLightType::POINT_LIGHT:
|
||||
lightType = Render3D::LightType::POINT;
|
||||
break;
|
||||
case ModelLightType::SPOT_LIGHT:
|
||||
lightType = Render3D::LightType::SPOT;
|
||||
break;
|
||||
default:
|
||||
LOGW("invalid light type");
|
||||
}
|
||||
|
||||
lights.push_back(std::make_shared<Render3D::Light>(lightType, Render3D::Vec3(
|
||||
color.GetX(), color.GetY(), color.GetZ()), light->GetLightIntensity().GetValue(),
|
||||
light->GetLightShadow(), lightPosition, Render3D::Quaternion(rotation.GetX(),
|
||||
rotation.GetY(), rotation.GetZ(), rotation.GetW())));
|
||||
}
|
||||
}
|
||||
|
||||
void ModelAdapterWrapper::UpdateLights(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
#if defined(KIT_3D_ENABLE)
|
||||
if (sceneAdapter_) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!modelPaintProperty->GetModelLights().has_value()) {
|
||||
LOGW("MODEL_NG: UpdateLights invalid lights");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Render3D::Light>> lights;
|
||||
ExtractLightsProperty(modelPaintProperty, lights);
|
||||
|
||||
Render3D::GraphicsTask::GetInstance().PushSyncMessage([weak = WeakClaim(this), &lights] {
|
||||
auto adapter = weak.Upgrade();
|
||||
CHECK_NULL_VOID(adapter);
|
||||
CHECK_NULL_VOID(adapter->widgetAdapter_);
|
||||
|
||||
adapter->widgetAdapter_->UpdateLights(lights);
|
||||
});
|
||||
}
|
||||
|
||||
void ModelAdapterWrapper::UpdateGLTFAnimations(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
#if defined(KIT_3D_ENABLE)
|
||||
if (sceneAdapter_) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!modelPaintProperty->GetModelAnimations().has_value()) {
|
||||
LOGW("UpdateGLTFAnimations invalid animation");
|
||||
return;
|
||||
}
|
||||
|
||||
auto& animations = modelPaintProperty->GetModelAnimations().value();
|
||||
Render3D::GraphicsTask::GetInstance().PushSyncMessage([weak = WeakClaim(this), &animations] {
|
||||
auto adapter = weak.Upgrade();
|
||||
CHECK_NULL_VOID(adapter);
|
||||
CHECK_NULL_VOID(adapter->widgetAdapter_);
|
||||
|
||||
adapter->widgetAdapter_->UpdateGLTFAnimations(animations);
|
||||
});
|
||||
}
|
||||
|
||||
void ModelAdapterWrapper::UpdateGeometries(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
#if defined(KIT_3D_ENABLE)
|
||||
if (sceneAdapter_) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!modelPaintProperty->GetModelGeometries().has_value()) {
|
||||
LOGW("UpdateGeometries invalid geometries");
|
||||
return;
|
||||
}
|
||||
|
||||
auto& geometries = modelPaintProperty->GetModelGeometries().value();
|
||||
|
||||
Render3D::GraphicsTask::GetInstance().PushSyncMessage([weak = WeakClaim(this), &geometries] {
|
||||
auto adapter = weak.Upgrade();
|
||||
CHECK_NULL_VOID(adapter);
|
||||
CHECK_NULL_VOID(adapter->widgetAdapter_);
|
||||
|
||||
adapter->widgetAdapter_->UpdateGeometries(geometries);
|
||||
});
|
||||
}
|
||||
|
||||
void ModelAdapterWrapper::UpdateCustomRender(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
#if defined(KIT_3D_ENABLE)
|
||||
@ -581,13 +375,9 @@ void ModelAdapterWrapper::UpdateCustomRender(const RefPtr<ModelPaintProperty>& m
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!modelPaintProperty->GetModelCustomRender().has_value()) {
|
||||
LOGW("UpdateCustomRender invalid custom render");
|
||||
return;
|
||||
}
|
||||
|
||||
auto& customRender = modelPaintProperty->GetModelCustomRender().value();
|
||||
if (!customRender) {
|
||||
LOGW("UpdateCustomRender invalid custom render");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -607,7 +397,7 @@ void ModelAdapterWrapper::UpdateShaderPath(const RefPtr<ModelPaintProperty>& mod
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!modelPaintProperty->GetShaderPath().has_value()) {
|
||||
if (modelPaintProperty->GetShaderPathValue().empty()) {
|
||||
LOGW("UpdateShaderPath invalid shader path");
|
||||
return;
|
||||
}
|
||||
@ -630,7 +420,7 @@ void ModelAdapterWrapper::UpdateImageTexturePaths(const RefPtr<ModelPaintPropert
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!modelPaintProperty->GetModelImageTexturePaths().has_value()) {
|
||||
if (modelPaintProperty->GetModelImageTexturePathsValue().empty()) {
|
||||
LOGW("UpdateImageTexturePaths invalid image texture");
|
||||
return;
|
||||
}
|
||||
@ -653,7 +443,7 @@ void ModelAdapterWrapper::UpdateShaderInputBuffers(const RefPtr<ModelPaintProper
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (!modelPaintProperty->GetModelShaderInputBuffer().has_value()) {
|
||||
if (modelPaintProperty->GetModelShaderInputBufferValue() == nullptr) {
|
||||
LOGW("UpdateShaderInputBuffers invalid shader input buffer");
|
||||
return;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <memory>
|
||||
|
||||
#include "custom/shader_input_buffer.h"
|
||||
#include "graphics_task.h"
|
||||
#include "ohos/graphics_manager.h"
|
||||
#include "ohos/texture_layer.h"
|
||||
#include "widget_adapter.h"
|
||||
|
||||
@ -80,10 +82,6 @@ private:
|
||||
void Initialize();
|
||||
void UnloadSceneAndBackground();
|
||||
void DrawFrame();
|
||||
void UpdateCamera(const RefPtr<ModelPaintProperty>& modelPaintProperty);
|
||||
void UpdateLights(const RefPtr<ModelPaintProperty>& modelPaintProperty);
|
||||
void UpdateGLTFAnimations(const RefPtr<ModelPaintProperty>& modelPaintProperty);
|
||||
void UpdateGeometries(const RefPtr<ModelPaintProperty>& modelPaintProperty);
|
||||
void UpdateScene(const RefPtr<ModelPaintProperty>& modelPaintProperty);
|
||||
void UpdateEnviroment(const RefPtr<ModelPaintProperty>& modelPaintProperty);
|
||||
void UpdateCustomRender(const RefPtr<ModelPaintProperty>& modelPaintProperty);
|
||||
|
@ -54,7 +54,6 @@ public:
|
||||
{
|
||||
auto paintProperty = MakeRefPtr<ModelPaintProperty>();
|
||||
paintProperty->UpdatePaintProperty(this);
|
||||
paintProperty->propCameraPosition_ = CloneCameraPosition();
|
||||
paintProperty->propCameraDistance_ = CloneCameraDistance();
|
||||
paintProperty->propCameraIsAngular_ = CloneCameraIsAngular();
|
||||
paintProperty->propCameraRotation_ = CloneCameraRotation();
|
||||
@ -110,7 +109,6 @@ public:
|
||||
void Reset() override
|
||||
{
|
||||
PaintProperty::Reset();
|
||||
ResetCameraPosition();
|
||||
ResetCameraDistance();
|
||||
ResetCameraIsAngular();
|
||||
ResetCameraRotation();
|
||||
@ -174,8 +172,6 @@ public:
|
||||
UpdateNeedsImageTexturePathsSetup(true);
|
||||
}
|
||||
|
||||
DEFINE_NEEDS_SETUP_FLAG_TRIGGER_PROPERTY(
|
||||
CameraPosition, Vec3, Camera, PROPERTY_UPDATE_RENDER);
|
||||
DEFINE_NEEDS_SETUP_FLAG_TRIGGER_PROPERTY(
|
||||
CameraDistance, AnimatableFloat, Camera, PROPERTY_UPDATE_RENDER);
|
||||
DEFINE_NEEDS_SETUP_FLAG_TRIGGER_PROPERTY(
|
||||
|
@ -140,7 +140,7 @@ void ModelPattern::MarkDirtyNode(const PropertyChangeFlag flag)
|
||||
static std::string TextureImagesToStr(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
std::string ret;
|
||||
if (!modelPaintProperty->GetModelImageTexturePaths().has_value()) {
|
||||
if (modelPaintProperty->GetModelImageTexturePathsValue().empty()) {
|
||||
return ret;
|
||||
}
|
||||
auto& imageTextures = modelPaintProperty->GetModelImageTexturePaths().value();
|
||||
@ -153,9 +153,6 @@ static std::string TextureImagesToStr(const RefPtr<ModelPaintProperty>& modelPai
|
||||
static std::string ShaderInputBufferToStr(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
std::string ret;
|
||||
if (!modelPaintProperty->GetModelShaderInputBuffer().has_value()) {
|
||||
return ret;
|
||||
}
|
||||
const auto& shaderInputBuffer = modelPaintProperty->GetModelShaderInputBuffer().value();
|
||||
if (!shaderInputBuffer || !shaderInputBuffer->IsValid()) {
|
||||
return ret;
|
||||
@ -207,7 +204,7 @@ static std::string SurfaceTypeToStr(const RefPtr<ModelAdapterWrapper>& modelAdap
|
||||
static std::string SceneResourceToStr(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
std::string ret;
|
||||
if (!modelPaintProperty->GetModelSource().has_value()) {
|
||||
if (modelPaintProperty->GetModelSourceValue().empty()) {
|
||||
return ret;
|
||||
}
|
||||
ret = modelPaintProperty->GetModelSource().value();
|
||||
@ -217,7 +214,7 @@ static std::string SceneResourceToStr(const RefPtr<ModelPaintProperty>& modelPai
|
||||
static std::string SceneEnvironmentToStr(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
std::string ret;
|
||||
if (!modelPaintProperty->GetModelBackground().has_value()) {
|
||||
if (modelPaintProperty->GetModelBackgroundValue().empty()) {
|
||||
return ret;
|
||||
}
|
||||
ret = modelPaintProperty->GetModelBackground().value();
|
||||
@ -227,9 +224,6 @@ static std::string SceneEnvironmentToStr(const RefPtr<ModelPaintProperty>& model
|
||||
static std::string SceneCustomRenderToStr(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
std::string ret;
|
||||
if (!modelPaintProperty->GetModelCustomRender().has_value()) {
|
||||
return ret;
|
||||
}
|
||||
auto& customRender = modelPaintProperty->GetModelCustomRender().value();
|
||||
if (!customRender) {
|
||||
return ret;
|
||||
@ -241,7 +235,7 @@ static std::string SceneCustomRenderToStr(const RefPtr<ModelPaintProperty>& mode
|
||||
static std::string SceneShaderPathToStr(const RefPtr<ModelPaintProperty>& modelPaintProperty)
|
||||
{
|
||||
std::string ret;
|
||||
if (!modelPaintProperty->GetShaderPath().has_value()) {
|
||||
if (modelPaintProperty->GetShaderPathValue().empty()) {
|
||||
return ret;
|
||||
}
|
||||
ret = modelPaintProperty->GetShaderPath().value();
|
||||
|
@ -56,19 +56,7 @@ public:
|
||||
virtual void SetBackground(const std::string& src) = 0;
|
||||
virtual void SetModelSource(const std::string& src) = 0;
|
||||
virtual void SetHandleCameraMove(bool value) = 0;
|
||||
virtual void SetTransparent(bool value) = 0;
|
||||
virtual void SetCameraPosition(AnimatableFloat x, AnimatableFloat y, AnimatableFloat z,
|
||||
AnimatableFloat distance, bool isAngular) = 0;
|
||||
virtual void SetCameraRotation(Quaternion quat) = 0;
|
||||
virtual void SetCameraFrustum(float zNear, float zFar, float fovDegrees) = 0;
|
||||
virtual void SetCameraLookAt(Vec3 lookAtVec) = 0;
|
||||
virtual void SetCameraUp(Vec3 upVec) = 0;
|
||||
virtual void AddLight(const RefPtr<NG::ModelLight>& light) = 0;
|
||||
virtual void AddGeometry(const std::shared_ptr<Render3D::Geometry>& shape) = 0;
|
||||
virtual void AddGLTFAnimation(const std::shared_ptr<Render3D::GLTFAnimation>& animation) = 0;
|
||||
virtual void AddCustomRender(const std::shared_ptr<Render3D::CustomRenderDescriptor>& customRender) = 0;
|
||||
virtual void SetWidth(Dimension& width) = 0;
|
||||
virtual void SetHeight(Dimension& height) = 0;
|
||||
virtual void SetRenderWidth(Dimension& width) = 0;
|
||||
virtual void SetRenderHeight(Dimension& height) = 0;
|
||||
virtual void SetRenderFrameRate(float rate) = 0;
|
||||
|
@ -24,19 +24,6 @@
|
||||
#include "core/pipeline/pipeline_base.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
|
||||
ModelViewNG::ModelViewNG()
|
||||
{
|
||||
const RefPtr<PipelineBase> pipeline = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
if (pipeline) {
|
||||
cameraPosition_.SetContextAndCallbacks(pipeline,
|
||||
std::bind(&ModelViewNG::PerformCameraUpdate, this));
|
||||
} else {
|
||||
LOGE("ModelViewNG() pipeline context is null");
|
||||
}
|
||||
}
|
||||
|
||||
void ModelViewNG::Create(const ModelViewContext& context)
|
||||
{
|
||||
auto* stack = ViewStackProcessor::GetInstance();
|
||||
@ -69,82 +56,6 @@ void ModelViewNG::SetModelSource(const std::string& value)
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, ModelSource, value);
|
||||
}
|
||||
|
||||
void ModelViewNG::SetTransparent(bool value)
|
||||
{
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, ModelTransparent, value);
|
||||
}
|
||||
|
||||
void ModelViewNG::SetCameraPosition(AnimatableFloat x, AnimatableFloat y, AnimatableFloat z,
|
||||
AnimatableFloat distance, bool isAngular)
|
||||
{
|
||||
if (NearEqual(cameraPosition_.GetDistance().GetValue(), std::numeric_limits<float>::max())) {
|
||||
// Initial update. Set the values directly without the animation if any.
|
||||
cameraPosition_.SetDistance(AnimatableFloat(distance.GetValue()));
|
||||
cameraPosition_.SetPosition(Vec3(x.GetValue(), y.GetValue(), z.GetValue()));
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, CameraDistance, distance);
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, CameraPosition, Vec3(x, y, z));
|
||||
} else {
|
||||
cameraPosition_.SetDistance(distance);
|
||||
cameraPosition_.SetPosition(Vec3(x, y, z));
|
||||
}
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, CameraIsAngular, isAngular);
|
||||
}
|
||||
|
||||
void ModelViewNG::SetCameraRotation(Quaternion quat)
|
||||
{
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, CameraRotation, quat);
|
||||
}
|
||||
|
||||
void ModelViewNG::SetCameraFrustum(float zNear, float zFar, float fovDegrees)
|
||||
{
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, CameraZNear, zNear);
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, CameraZFar, zFar);
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, CameraFOV, fovDegrees);
|
||||
}
|
||||
|
||||
void ModelViewNG::SetCameraLookAt(Vec3 lookAtVec)
|
||||
{
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, CameraLookAt, lookAtVec);
|
||||
}
|
||||
|
||||
void ModelViewNG::SetCameraUp(Vec3 upVec)
|
||||
{
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, CameraUp, upVec);
|
||||
}
|
||||
|
||||
void ModelViewNG::AddLight(const RefPtr<ModelLight>& light)
|
||||
{
|
||||
if (!light) {
|
||||
LOGE("Add light invalid light");
|
||||
return;
|
||||
}
|
||||
|
||||
if (lights_.empty()) {
|
||||
// Set the animation callback.
|
||||
RefPtr<PipelineBase> pipeline = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
if (pipeline) {
|
||||
light->SetContextAndCallback(pipeline,
|
||||
std::bind(&ModelViewNG::PerformLightUpdate, this));
|
||||
} else {
|
||||
LOGE("ModelViewNG() pipeline context is null");
|
||||
}
|
||||
}
|
||||
|
||||
lights_.push_back(light);
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, ModelSingleLight, light);
|
||||
}
|
||||
|
||||
void ModelViewNG::AddGeometry(const std::shared_ptr<Render3D::Geometry>& shape)
|
||||
{
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, ModelSingleGeometry, shape);
|
||||
}
|
||||
|
||||
void ModelViewNG::AddGLTFAnimation(const std::shared_ptr<Render3D::GLTFAnimation>& animation)
|
||||
{
|
||||
ACE_UPDATE_PAINT_PROPERTY(ModelPaintProperty, ModelSingleAnimation, animation);
|
||||
}
|
||||
|
||||
void ModelViewNG::AddCustomRender(const std::shared_ptr<Render3D::CustomRenderDescriptor>& customRender)
|
||||
{
|
||||
if (!customRender) {
|
||||
@ -168,22 +79,6 @@ void ModelViewNG::AddCustomRender(const std::shared_ptr<Render3D::CustomRenderDe
|
||||
}
|
||||
}
|
||||
|
||||
void ModelViewNG::SetWidth(Dimension& width)
|
||||
{
|
||||
if (LessNotEqual(width.Value(), 0.0)) {
|
||||
width.SetValue(0.0);
|
||||
}
|
||||
ViewAbstract::SetWidth(CalcLength(width));
|
||||
}
|
||||
|
||||
void ModelViewNG::SetHeight(Dimension& height)
|
||||
{
|
||||
if (LessNotEqual(height.Value(), 0.0)) {
|
||||
height.SetValue(0.0);
|
||||
}
|
||||
ViewAbstract::SetHeight(CalcLength(height));
|
||||
}
|
||||
|
||||
void ModelViewNG::SetRenderHeight(Dimension& height)
|
||||
{
|
||||
if (LessNotEqual(height.Value(), 0.0)) {
|
||||
@ -246,41 +141,6 @@ void ModelViewNG::AddShaderInputBuffer(FrameNode* frameNode, const std::shared_p
|
||||
ACE_UPDATE_NODE_PAINT_PROPERTY(ModelPaintProperty, ModelShaderInputBuffer, buffer, frameNode);
|
||||
}
|
||||
|
||||
void ModelViewNG::PerformCameraUpdate()
|
||||
{
|
||||
auto frameNode = frameNode_.Upgrade();
|
||||
if (!frameNode) {
|
||||
LOGE("frameNode is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
auto paintProperty = frameNode->GetPaintProperty<ModelPaintProperty>();
|
||||
if (paintProperty) {
|
||||
paintProperty->UpdateCameraDistance(cameraPosition_.GetDistance());
|
||||
paintProperty->UpdateCameraPosition(cameraPosition_.GetPosition());
|
||||
frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
|
||||
} else {
|
||||
LOGE("ModelPaintProperty is null");
|
||||
}
|
||||
}
|
||||
|
||||
void ModelViewNG::PerformLightUpdate()
|
||||
{
|
||||
auto frameNode = frameNode_.Upgrade();
|
||||
if (!frameNode) {
|
||||
LOGE("frameNode is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
auto paintProperty = frameNode->GetPaintProperty<ModelPaintProperty>();
|
||||
if (!paintProperty) {
|
||||
LOGE("ModelPaintProperty is null");
|
||||
return;
|
||||
}
|
||||
paintProperty->ModelLightsAnimationUpdate(lights_);
|
||||
frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Render3D::ShaderInputBuffer>> ModelViewNG::GetShaderInputBuffer()
|
||||
{
|
||||
auto frameNode = frameNode_.Upgrade();
|
||||
|
@ -25,24 +25,11 @@ namespace OHOS::Ace::NG {
|
||||
|
||||
class ACE_EXPORT ModelViewNG : public ModelView {
|
||||
public:
|
||||
ModelViewNG();
|
||||
void Create(const ModelViewContext& context) override;
|
||||
void SetBackground(const std::string& value) override;
|
||||
void SetModelSource(const std::string& value) override;
|
||||
void SetHandleCameraMove(bool value) override;
|
||||
void SetTransparent(bool value) override;
|
||||
void SetCameraPosition(AnimatableFloat x, AnimatableFloat y, AnimatableFloat z,
|
||||
AnimatableFloat distance, bool isAngular) override;
|
||||
void SetCameraRotation(Quaternion quat) override;
|
||||
void SetCameraFrustum(float zNear, float zFar, float fovDegrees) override;
|
||||
void SetCameraLookAt(Vec3 lookAtVec) override;
|
||||
void SetCameraUp(Vec3 upVec) override;
|
||||
void AddLight(const RefPtr<ModelLight>& light) override;
|
||||
void AddGeometry(const std::shared_ptr<Render3D::Geometry>& shape) override;
|
||||
void AddGLTFAnimation(const std::shared_ptr<Render3D::GLTFAnimation>& animation) override;
|
||||
void AddCustomRender(const std::shared_ptr<Render3D::CustomRenderDescriptor>& customRender) override;
|
||||
void SetWidth(Dimension& width) override;
|
||||
void SetHeight(Dimension& height) override;
|
||||
void SetRenderWidth(Dimension& width) override;
|
||||
void SetRenderHeight(Dimension& height) override;
|
||||
void SetRenderFrameRate(float rate) override;
|
||||
@ -53,9 +40,6 @@ public:
|
||||
|
||||
static void AddShaderInputBuffer(FrameNode* frameNode, const std::shared_ptr<Render3D::ShaderInputBuffer>& buffer);
|
||||
private:
|
||||
void PerformCameraUpdate();
|
||||
void PerformLightUpdate();
|
||||
|
||||
// Camera and lights animations are done from the frontend with Animatable types.
|
||||
WeakPtr<FrameNode> frameNode_;
|
||||
ModelPosition cameraPosition_;
|
||||
|
@ -53,6 +53,7 @@ group("core_pattern_unittest") {
|
||||
"loading_progress:loading_progress_test_ng",
|
||||
"marquee:marquee_test_ng",
|
||||
"menu:menu_test_ng",
|
||||
"model:model_test_ng",
|
||||
"movingphoto:movingphoto_test_ng",
|
||||
"navigation:navigation_test_ng",
|
||||
"navigator:navigator_test_ng",
|
||||
|
45
test/unittest/core/pattern/model/BUILD.gn
Normal file
45
test/unittest/core/pattern/model/BUILD.gn
Normal file
@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni")
|
||||
|
||||
ace_unittest("model_test_ng") {
|
||||
flutter_skia = true
|
||||
render = true
|
||||
type = "new"
|
||||
|
||||
sources = [
|
||||
"$ace_root/frameworks/core/components_ng/pattern/model/model_adapter_wrapper.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/model/model_layout_algorithm.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/model/model_paint_method.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/model/model_pattern.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/model/model_touch_handler.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/model/model_view_ng.cpp",
|
||||
"model_test_ng.cpp",
|
||||
]
|
||||
|
||||
if (is_ohos_standard_system) {
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_runtime:app_manager",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"form_fwk:fmskit_native",
|
||||
"form_fwk:form_manager",
|
||||
"graphic_2d:librender_service_client",
|
||||
"graphic_3d:lib3dWidgetAdapter",
|
||||
"input:libmmi-client",
|
||||
]
|
||||
}
|
||||
}
|
400
test/unittest/core/pattern/model/model_test_ng.cpp
Normal file
400
test/unittest/core/pattern/model/model_test_ng.cpp
Normal file
@ -0,0 +1,400 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
|
||||
#include "test/mock/core/common/mock_theme_manager.h"
|
||||
#include "test/mock/core/pipeline/mock_pipeline_context.h"
|
||||
#include "test/mock/core/render/mock_render_context.h"
|
||||
#include "test/mock/core/rosen/mock_canvas.h"
|
||||
#include "test/mock/core/rosen/testing_bitmap.h"
|
||||
#include "test/mock/core/rosen/testing_canvas.h"
|
||||
|
||||
#include "core/components_ng/pattern/model/model_adapter_wrapper.h"
|
||||
#include "core/components_ng/pattern/model/model_layout_algorithm.h"
|
||||
#include "core/components_ng/pattern/model/model_light.h"
|
||||
#include "core/components_ng/pattern/model/model_paint_property.h"
|
||||
#include "core/components_ng/pattern/model/model_paint_method.h"
|
||||
#include "core/components_ng/pattern/model/model_pattern.h"
|
||||
#include "core/components_ng/pattern/model/model_position.h"
|
||||
#include "core/components_ng/pattern/model/model_property.h"
|
||||
#include "core/components_ng/pattern/model/model_touch_handler.h"
|
||||
#include "core/components_ng/pattern/model/model_view.h"
|
||||
#include "core/components_ng/pattern/model/model_view_ng.h"
|
||||
|
||||
#include "scene_adapter/intf_scene_adapter.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
uint32_t testKey = UINT32_MAX / 2;
|
||||
std::string testPath = "/data/local";
|
||||
constexpr int32_t PLATFORM_VERSION_11 = 11;
|
||||
Render3D::SurfaceType testSurfaceType = OHOS::Render3D::SurfaceType::SURFACE_WINDOW;
|
||||
ModelViewContext testContext { "moudleTest", "moudleTest", testSurfaceType };
|
||||
}
|
||||
|
||||
class TestSceneAdapter : public Render3D::ISceneAdapter {
|
||||
bool LoadPluginsAndInit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
std::shared_ptr<Render3D::TextureLayer> CreateTextureLayer()
|
||||
{
|
||||
return std::make_shared<Render3D::TextureLayer>();
|
||||
}
|
||||
void OnWindowChange(const Render3D::WindowChangeInfo& windowChangeInfo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void RenderFrame(bool needsSyncPaint = false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void Deinit()
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool NeedsRepaint()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class ModelTestNg : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestSuite();
|
||||
static void TearDownTestSuite();
|
||||
private:
|
||||
ModelViewNG modelViewNG;
|
||||
};
|
||||
|
||||
void ModelTestNg::SetUpTestSuite()
|
||||
{
|
||||
MockPipelineContext::SetUp();
|
||||
}
|
||||
|
||||
void ModelTestNg::TearDownTestSuite()
|
||||
{
|
||||
MockPipelineContext::TearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ModelViewNgTest001
|
||||
* @tc.desc: Test Without Setting Property
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ModelTestNg, ModelViewNgTest001, TestSize.Level1)
|
||||
{
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
ASSERT_NE(pipeline, nullptr);
|
||||
pipeline->SetMinPlatformVersion(PLATFORM_VERSION_11);
|
||||
|
||||
// Create ModelViewNG
|
||||
modelViewNG.Create(testContext);
|
||||
|
||||
// Get ModelPaintProperty
|
||||
auto modelPaintProperty = modelViewNG.frameNode_.Upgrade()->GetPaintProperty<ModelPaintProperty>();
|
||||
ASSERT_NE(modelPaintProperty, nullptr);
|
||||
|
||||
// Get ModelPattern
|
||||
auto modelPattern = modelViewNG.frameNode_.Upgrade()->GetPattern<ModelPattern>();
|
||||
ASSERT_NE(modelPattern, nullptr);
|
||||
|
||||
// ToJsonValue Before Set Values
|
||||
const InspectorFilter filter;
|
||||
auto json = JsonUtil::Create(true);
|
||||
modelPattern->ToJsonValue(json, filter);
|
||||
|
||||
// ImageTexturePath and ShaderInputBuffers
|
||||
modelPattern->modelAdapter_->sceneAdapter_ = std::make_shared<TestSceneAdapter>();
|
||||
ASSERT_NE(modelPattern->modelAdapter_->sceneAdapter_, nullptr);
|
||||
modelPattern->modelAdapter_->UpdateImageTexturePaths(modelPaintProperty);
|
||||
modelPattern->modelAdapter_->UpdateShaderInputBuffers(modelPaintProperty);
|
||||
modelPattern->modelAdapter_->sceneAdapter_.reset();
|
||||
ASSERT_EQ(modelPattern->modelAdapter_->sceneAdapter_, nullptr);
|
||||
modelPattern->modelAdapter_->UpdateImageTexturePaths(modelPaintProperty);
|
||||
modelPattern->modelAdapter_->UpdateShaderInputBuffers(modelPaintProperty);
|
||||
|
||||
// ShaderInputBuffer
|
||||
// Buffer test begin
|
||||
std::shared_ptr<OHOS::Render3D::ShaderInputBuffer> buffer = nullptr;
|
||||
buffer = std::make_shared<OHOS::Render3D::ShaderInputBuffer>();
|
||||
int length = 3; // 3: buffer length
|
||||
|
||||
ASSERT_TRUE(buffer->Alloc(length));
|
||||
for (uint32_t i = 0; i < static_cast<uint32_t>(length); i++) {
|
||||
buffer->Update(1, i);
|
||||
}
|
||||
modelViewNG.AddShaderInputBuffer(buffer);
|
||||
EXPECT_EQ(modelPaintProperty->GetModelShaderInputBufferValue(), buffer);
|
||||
modelPattern->modelAdapter_->UpdateShaderInputBuffers(modelPaintProperty);
|
||||
EXPECT_EQ(modelViewNG.GetShaderInputBuffer(), modelPaintProperty->propModelShaderInputBuffer_);
|
||||
|
||||
FrameNode* frameNode = nullptr;
|
||||
modelViewNG.AddShaderInputBuffer(frameNode, buffer);
|
||||
// Buffer test end
|
||||
|
||||
// CustomRender
|
||||
modelPattern->modelAdapter_->UpdateCustomRender(modelPaintProperty);
|
||||
auto desc = std::make_shared<Render3D::CustomRenderDescriptor>("/data/local", true);
|
||||
modelViewNG.AddCustomRender(desc);
|
||||
EXPECT_EQ(modelPaintProperty->GetModelCustomRenderValue(), desc);
|
||||
modelPattern->modelAdapter_->UpdateCustomRender(modelPaintProperty);
|
||||
|
||||
// AddShaderImageTexture
|
||||
// Case 1:: frameNode != nullptr
|
||||
modelViewNG.AddShaderImageTexture("/data/local");
|
||||
// Add Same Path
|
||||
modelViewNG.AddShaderImageTexture("/data/local");
|
||||
EXPECT_EQ(modelPaintProperty->GetModelImageTexturePathsValue().back(), "/data/local");
|
||||
|
||||
// case 2 frameNode == nullptr
|
||||
modelViewNG.frameNode_.Reset();
|
||||
modelViewNG.AddShaderImageTexture("/data/local1");
|
||||
EXPECT_EQ(modelPaintProperty->GetModelImageTexturePathsValue().size(), 1);
|
||||
modelViewNG.GetShaderInputBuffer();
|
||||
|
||||
modelViewNG.AddCustomRender(desc);
|
||||
desc.reset();
|
||||
modelViewNG.AddCustomRender(desc);
|
||||
modelPattern->modelAdapter_->UpdateCustomRender(modelPaintProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ModelViewNgTest002
|
||||
* @tc.desc: Test ModelAdapterWrapper Functions and SceneAdapter == nullptr
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ModelTestNg, ModelViewNgTest002, TestSize.Level1)
|
||||
{
|
||||
// Get FrameNode
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
|
||||
// Get ModelPaintProperty
|
||||
auto modelPaintProperty = frameNode->GetPaintProperty<ModelPaintProperty>();
|
||||
ASSERT_NE(modelPaintProperty, nullptr);
|
||||
|
||||
// Get ModelPattern
|
||||
auto modelPattern = frameNode->GetPattern<ModelPattern>();
|
||||
ASSERT_NE(modelPattern, nullptr);
|
||||
|
||||
// Create SceneAdapter
|
||||
modelPattern->modelAdapter_->sceneAdapter_ = std::make_shared<TestSceneAdapter>();
|
||||
ASSERT_NE(modelPattern->modelAdapter_->sceneAdapter_, nullptr);
|
||||
|
||||
RefPtr<RenderContext> context;
|
||||
modelPattern->modelAdapter_->OnAttachToFrameNode(context);
|
||||
modelPattern->modelAdapter_->Deinit();
|
||||
Render3D::PointerEvent event;
|
||||
modelPattern->modelAdapter_->HandleCameraMove(event);
|
||||
modelPattern->modelAdapter_->DrawFrame();
|
||||
Render3D::WindowChangeInfo windowChangeInfo {};
|
||||
modelPattern->modelAdapter_->OnDirtyLayoutWrapperSwap(windowChangeInfo);
|
||||
modelPattern->modelAdapter_->CreateTextureLayer();
|
||||
modelPattern->modelAdapter_->CreateWidgetAdapter();
|
||||
modelPattern->modelAdapter_->UnloadSceneAndBackground();
|
||||
modelPattern->modelAdapter_->UpdateScene(modelPaintProperty);
|
||||
modelPattern->modelAdapter_->UpdateEnviroment(modelPaintProperty);
|
||||
modelPattern->modelAdapter_->UpdateCustomRender(modelPaintProperty);
|
||||
modelPattern->modelAdapter_->UpdateShaderPath(modelPaintProperty);
|
||||
|
||||
modelPattern->modelAdapter_->sceneAdapter_.reset();
|
||||
ASSERT_EQ(modelPattern->modelAdapter_->sceneAdapter_, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ModelViewNgTest003
|
||||
* @tc.desc: Test ModelViewNG Functions
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ModelTestNg, ModelViewNgTest003, TestSize.Level1)
|
||||
{
|
||||
// Get FrameNode
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
|
||||
// Get ModelPaintProperty
|
||||
auto modelPaintProperty = frameNode->GetPaintProperty<ModelPaintProperty>();
|
||||
ASSERT_NE(modelPaintProperty, nullptr);
|
||||
|
||||
// Get ModelPattern
|
||||
auto modelPattern = frameNode->GetPattern<ModelPattern>();
|
||||
ASSERT_NE(modelPattern, nullptr);
|
||||
|
||||
// Environment
|
||||
modelPattern->modelAdapter_->UpdateEnviroment(modelPaintProperty);
|
||||
modelViewNG.SetBackground(testPath);
|
||||
EXPECT_EQ(modelPaintProperty->GetModelBackgroundValue(), testPath);
|
||||
modelPattern->modelAdapter_->UpdateEnviroment(modelPaintProperty);
|
||||
|
||||
// ModelSource
|
||||
modelPattern->modelAdapter_->UpdateScene(modelPaintProperty);
|
||||
modelViewNG.SetModelSource(testPath);
|
||||
EXPECT_EQ(modelPaintProperty->GetModelSourceValue(), testPath);
|
||||
modelPattern->modelAdapter_->UpdateScene(modelPaintProperty);
|
||||
|
||||
// RenderWidth and RenderHeight
|
||||
// Case 1 : Value < 0.0f
|
||||
CalcDimension value;
|
||||
value.SetValue(-1.0f);
|
||||
modelViewNG.SetRenderWidth(value);
|
||||
value.SetValue(-1.0f);
|
||||
modelViewNG.SetRenderHeight(value);
|
||||
|
||||
// Case 2 : Value > 0.0f
|
||||
value.SetValue(1.0f);
|
||||
modelViewNG.SetRenderWidth(value);
|
||||
EXPECT_EQ(modelPaintProperty->GetRenderWidthValue(), 1.0f);
|
||||
modelViewNG.SetRenderHeight(value);
|
||||
EXPECT_EQ(modelPaintProperty->GetRenderHeightValue(), 1.0f);
|
||||
|
||||
// Shader
|
||||
modelPattern->modelAdapter_->UpdateShaderPath(modelPaintProperty);
|
||||
modelViewNG.SetShader(testPath);
|
||||
EXPECT_EQ(modelPaintProperty->GetShaderPathValue(), testPath);
|
||||
modelPattern->modelAdapter_->UpdateShaderPath(modelPaintProperty);
|
||||
|
||||
// HandleCameraMove
|
||||
modelViewNG.SetHandleCameraMove(false);
|
||||
EXPECT_EQ(modelPaintProperty->GetModelCameraMoveValue(), false);
|
||||
|
||||
// RenderFrameRate
|
||||
modelViewNG.SetRenderFrameRate(1.0f);
|
||||
EXPECT_EQ(modelPaintProperty->GetRenderFrameRateValue(), 1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ModelViewNgTest004
|
||||
* @tc.desc: Test ModelPattern Functions
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ModelTestNg, ModelViewNgTest004, TestSize.Level1)
|
||||
{
|
||||
// Get FrameNode
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
|
||||
// Get ModelPattern
|
||||
auto modelPattern = frameNode->GetPattern<ModelPattern>();
|
||||
ASSERT_NE(modelPattern, nullptr);
|
||||
|
||||
// Get ModelPaintProperty
|
||||
auto modelPaintProperty = frameNode->GetPaintProperty<ModelPaintProperty>();
|
||||
ASSERT_NE(modelPaintProperty, nullptr);
|
||||
|
||||
// OnPaint3D
|
||||
// Case 1 : needsSynsPaint_ = true
|
||||
modelPattern->modelAdapter_->OnPaint3D(modelPaintProperty);
|
||||
// Case 2 : needsSynsPaint_ = false
|
||||
modelPattern->modelAdapter_->OnPaint3D(modelPaintProperty);
|
||||
modelPattern->modelAdapter_->OnPaintFinish();
|
||||
|
||||
// HdleCameraMove
|
||||
Render3D::PointerEvent event;
|
||||
modelPattern->modelAdapter_->HandleCameraMove(event);
|
||||
|
||||
// OnAttachToFrameNode
|
||||
modelPattern->modelAdapter_->UnloadSceneAndBackground();
|
||||
modelPattern->modelAdapter_->widgetAdapter_.reset();
|
||||
modelPattern->modelAdapter_->textureLayer_.reset();
|
||||
EXPECT_EQ(modelPattern->modelAdapter_->widgetAdapter_, nullptr);
|
||||
EXPECT_EQ(modelPattern->modelAdapter_->textureLayer_, nullptr);
|
||||
modelPattern->OnAttachToFrameNode();
|
||||
EXPECT_NE(modelPattern->modelAdapter_->widgetAdapter_, nullptr);
|
||||
EXPECT_NE(modelPattern->modelAdapter_->textureLayer_, nullptr);
|
||||
|
||||
TouchEventInfo touchEventInfo("onTouch");
|
||||
TouchLocationInfo touchLocationInfo(0);
|
||||
touchLocationInfo.touchType_ = TouchType::MOVE;
|
||||
touchLocationInfo.localLocation_ = Offset(1.0f, 1.0f);
|
||||
touchEventInfo.AddChangedTouchLocationInfo(std::move(touchLocationInfo));
|
||||
modelPattern->HandleTouchEvent(touchEventInfo);
|
||||
EXPECT_NE(modelPattern->CreateNodePaintMethod(), nullptr);
|
||||
|
||||
// OnModifyDone
|
||||
modelPattern->OnModifyDone();
|
||||
EXPECT_NE(modelPattern->modelAdapter_, nullptr);
|
||||
|
||||
// OnDirtyLayoutWrapperSwap
|
||||
RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
geometryNode->SetContentSize(SizeF(100.0f, 100.0f));
|
||||
geometryNode->SetContentOffset(OffsetF(0.0f, 0.0f));
|
||||
auto layoutWrapper =
|
||||
AceType::MakeRefPtr<LayoutWrapperNode>(static_cast<WeakPtr<FrameNode>>(frameNode), geometryNode, nullptr);
|
||||
ASSERT_NE(layoutWrapper, nullptr);
|
||||
layoutWrapper->skipMeasureContent_ = std::make_optional(true);
|
||||
DirtySwapConfig config;
|
||||
EXPECT_FALSE(modelPattern->OnDirtyLayoutWrapperSwap(layoutWrapper, config));
|
||||
|
||||
// MarkDirtyNode
|
||||
modelPattern->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
|
||||
|
||||
// OnRebuildFrame
|
||||
modelPattern->OnRebuildFrame();
|
||||
EXPECT_NE(modelPattern->modelAdapter_->textureLayer_, nullptr);
|
||||
|
||||
// NeedsRepaint
|
||||
modelPattern->modelAdapter_->needsRepaint_ = true;
|
||||
EXPECT_TRUE(modelPattern->NeedsRepaint());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ModelViewNgTest005
|
||||
* @tc.desc: Test Util Functions
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ModelTestNg, ModelViewNgTest005, TestSize.Level1)
|
||||
{
|
||||
// Get FrameNode
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
|
||||
// Get ModelPattern
|
||||
auto modelPattern = frameNode->GetPattern<ModelPattern>();
|
||||
ASSERT_NE(modelPattern, nullptr);
|
||||
|
||||
// Get ModelPaintProperty
|
||||
auto modelPaintProperty = frameNode->GetPaintProperty<ModelPaintProperty>();
|
||||
ASSERT_NE(modelPaintProperty, nullptr);
|
||||
|
||||
// SetHapInfo
|
||||
Render3D::HapInfo hapinfo = modelPattern->modelAdapter_->SetHapInfo();
|
||||
EXPECT_EQ(hapinfo.hapPath_, "");
|
||||
EXPECT_EQ(hapinfo.bundleName_, "");
|
||||
EXPECT_EQ(hapinfo.moduleName_, "");
|
||||
|
||||
const InspectorFilter filter1;
|
||||
auto json1 = JsonUtil::Create(true);
|
||||
modelPattern->ToJsonValue(json1, filter1);
|
||||
ASSERT_NE(json1, nullptr);
|
||||
EXPECT_EQ(json1->GetString("renderWidth"), "1.000000");
|
||||
EXPECT_EQ(json1->GetString("renderHeight"), "1.000000");
|
||||
EXPECT_EQ(json1->GetString("shaderInputBuffer"), "1.000000 1.000000 1.000000 ");
|
||||
EXPECT_EQ(json1->GetString("shaderImageTexture"), "/data/local ");
|
||||
EXPECT_EQ(json1->GetString("modelType"), "ModelType.SURFACE");
|
||||
EXPECT_EQ(json1->GetString("environment"), testPath);
|
||||
EXPECT_EQ(json1->GetString("customRender"), testPath);
|
||||
EXPECT_EQ(json1->GetString("shader"), testPath);
|
||||
EXPECT_EQ(json1->GetString("scene"), testPath);
|
||||
|
||||
modelPattern->modelAdapter_->Deinit();
|
||||
Render3D::GraphicsTask::GetInstance().Stop();
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
Loading…
Reference in New Issue
Block a user