You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm unable to implement Rotation or Pinching and it doesn't show me error.
I'm really grateful that you had put this project together it's been awesome. Thank you.
I'd appreciate some help or guidance to make this work please.
Here's my code
import'dart:io';
import'package:arkit_plugin/arkit_plugin.dart';
import'package:dio/dio.dart';
import'package:flutter/material.dart';
import'package:logger/logger.dart';
import'package:path_provider/path_provider.dart';
import'package:vector_math/vector_math_64.dart'as vector;
import'package:collection/collection.dart';
import'dart:math'as math;
classARGlbManipulationPageextendsStatefulWidget {
finalString modelUrl;
constARGlbManipulationPage({Key? key, requiredthis.modelUrl})
:super(key: key);
@override_ARGlbManipulationPageStatecreateState() =>_ARGlbManipulationPageState();
}
class_ARGlbManipulationPageStateextendsState<ARGlbManipulationPage> {
lateARKitController arkitController;
ARKitNode? modelNode;
finalLogger logger =Logger();
@overridevoiddispose() {
arkitController.dispose();
super.dispose();
}
@overrideWidgetbuild(BuildContext context) =>Scaffold(
appBar:AppBar(title:constText('Load and Manipulate GLB')),
body:ARKitSceneView(
showFeaturePoints:true,
enableTapRecognizer:true,
enablePinchRecognizer:true,
enablePanRecognizer:true,
enableRotationRecognizer:true,
planeDetection:ARPlaneDetection.horizontal,
onARKitViewCreated: onARKitViewCreated,
),
);
voidonARKitViewCreated(ARKitController arkitController) {
this.arkitController = arkitController;
// Set up gesture handlersthis.arkitController.onNodePinch = _onPinchHandler;
this.arkitController.onNodePan = _onPanHandler;
this.arkitController.onNodeRotation = _onRotationHandler;
this.arkitController.onARTap = (ar) {
final point = ar.firstWhereOrNull(
(o) => o.type ==ARKitHitTestResultType.featurePoint,
);
if (point !=null) {
_onARTapHandler(point);
}
};
}
void_onARTapHandler(ARKitTestResult point) {
final position = vector.Vector3(
point.worldTransform.getColumn(3).x,
point.worldTransform.getColumn(3).y,
point.worldTransform.getColumn(3).z,
);
_loadGLBModel(position);
}
Future<void> _loadGLBModel(vector.Vector3 position) async {
final node =await_getNodeFromNetwork(position);
arkitController.add(node);
modelNode = node;
}
Future<ARKitGltfNode> _getNodeFromNetwork(vector.Vector3 position) async {
// Assume this method downloads the GLB file and returns an ARKitGltfNodefinal file =await_downloadFile(widget.modelUrl); // Update with your URLif (file.existsSync()) {
returnARKitGltfNode(
assetType:AssetType.documents,
url: file.path.split('/').last,
scale: vector.Vector3(0.5, 0.5, 0.5),
position: position,
);
}
throwException('Failed to load $file');
}
Future<File> _downloadFile(String url) async {
try {
final dir =awaitgetApplicationDocumentsDirectory();
final filePath ='${dir.path}/${url.split("/").last}';
awaitDio().download(url, filePath);
final file =File(filePath);
print('Download completed!! path = $filePath');
return file;
} catch (e) {
print('Caught an exception: $e');
rethrow;
}
}
void_onPinchHandler(List<ARKitNodePinchResult> pinchResults) {
final pinch = pinchResults.firstWhereOrNull(
(e) => e.nodeName == modelNode?.name,
);
if (pinch !=null) {
logger.d('Pinch detected: ${pinch.scale}'); // Debugging linefinal scale = vector.Vector3.all(pinch.scale);
logger.d('Setting new scale: $scale'); // Debugging line
modelNode?.scale = scale;
} else {
logger.d('Pinch not applied to the correct node.'); // Debugging line
}
}
void_onPanHandler(List<ARKitNodePanResult> panResults) {
final pan = panResults.firstWhereOrNull(
(e) => e.nodeName == modelNode?.name,
);
if (pan !=null) {
final old = modelNode?.eulerAngles;
final newAngleY = pan.translation.x * math.pi /180;
modelNode?.eulerAngles =
vector.Vector3(old?.x ??0, newAngleY, old?.z ??0);
logger.d('Pan detected: ${pan.translation}'); // Debugging line
logger.d(
'Setting new eulerAngles: ${modelNode?.eulerAngles}'); // Debugging line
} else {
logger.d("No pan found");
}
}
void_onRotationHandler(List<ARKitNodeRotationResult> rotationResults) {
final rotation = rotationResults.firstWhereOrNull(
(e) => e.nodeName == modelNode?.name,
);
if (rotation !=null) {
final eulerAngles = modelNode?.eulerAngles ??
vector.Vector3.zero() + vector.Vector3.all(rotation.rotation);
modelNode?.eulerAngles = eulerAngles;
logger.d('Rotation detected: ${rotation.rotation}'); // Debugging line
logger.d(
'Setting new eulerAngles: ${modelNode?.eulerAngles}'); // Debugging line
} else {
logger.d("No rotation found");
}
}
}
``` @OleksiiShvachenko@mribbons@leeprobert@dokkaebi
The text was updated successfully, but these errors were encountered:
I'm unable to implement Rotation or Pinching and it doesn't show me error.
I'm really grateful that you had put this project together it's been awesome. Thank you.
I'd appreciate some help or guidance to make this work please.
Here's my code
The text was updated successfully, but these errors were encountered: