gpt4 book ai didi

flutter 显示 3d 对象 flutter_3d_obj

转载 作者:行者123 更新时间:2023-12-03 16:37:51 25 4
gpt4 key购买 nike

我设法使用 /flutter_3d_obj 在 flutter 上显示 3d 对象.我现在正在尝试获取 flutter 中点击点的坐标。我该怎么做。或者在 flutter 中显示 3d 对象的最佳方式是什么?并有能力获得一个点的坐标。

最佳答案

你可以用 GestureDectector 包裹你的 3Dmodel Widget小部件并使用 onTapDownDetail听触摸位置的属性

import 'package:flutter/material.dart';
import 'package:flutter_3d_obj/flutter_3d_obj.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
home: new MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
@override
MyHomePageState createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('3D Touchable Model'),
),
body: Touch3DModel());
}
}

class Touch3DModel extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return Touch3DModelState();
}
}

class Touch3DModelState extends State<Touch3DModel> {
double obj_width = 100;
double obj_height = 100;
double x_coord = 100.0;
double y_coord = 100.0;

void onTapDown(BuildContext context, TapDownDetails details) {
print('${details.globalPosition}');
final RenderBox box = context.findRenderObject();
final Offset localOffset = box.globalToLocal(details.globalPosition);
setState(() {
x_coord = localOffset.dx;
y_coord = localOffset.dy;
});
}

@override
Widget build(BuildContext context) {
return GestureDetector(
onTapDown: (TapDownDetails details) => onTapDown(context, details),
child: Stack(fit: StackFit.expand, children: <Widget>[
Container(color: Colors.grey),
Positioned(
child: Object3D(
size: const Size(obj_width, obj_height),
path: "assets/file.obj",
asset: true,
),
left: x_coord - obj_width / 2, // To offset the object possitioning from top left of the object to the center.
top: y_coord - obj_height / 2,
)
]),
);
}
}

注意:使用 flutter_3d_obj 需要你有一个 3d obj,你用 blender 或类似的工具构建。

归功于 aptik

关于flutter 显示 3d 对象 flutter_3d_obj,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59496386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com