zesage / flutter_cube Goto Github PK
View Code? Open in Web Editor NEWA Flutter 3D widget that renders Wavefront's object files.
License: Apache License 2.0
A Flutter 3D widget that renders Wavefront's object files.
License: Apache License 2.0
Seems that this widget doesn't show any shadows, even when the illum is set in the mtl file. Any ideas?
Object modelo = new Object(
backfaceCulling: false,
fileName: 'assets/mask2.obj', scale: Vector3(10.0, 10.0, 10.0));
Widget obj3d2() {
Cube cube = new Cube(
interactive: orientable,
onSceneCreated: (Scene scene) {
scene.world.add(modelo);
},
);
return cube;
}
hello
a simple question i suppose..
i have 3 assets:
i create
_test = Object(
name: 'test',
scale: Vector3(10.0, 10.0, 10.0),
backfaceCulling: true,
fileName: 'assets/test/test.obj');
_scene.world.add(_test!);
_scene.updateTexture();
only the 3D object appear. not the texture.
Could you help me ?
thx
Looks like there are couple of PR but no move has been made on that.
Hi all, i am able to render the obj and its texture/mtl from assets.
Currently i am trying to render the 3d object from local storage instead, however when i add:
obj = cube3d.Object(
fileName: '/storage/emulated/0/Download/testfolder/texturedMesh.obj',
isAsset: false);
using isAsset as false, i am only able to get the mesh of the object with not texture.
I am confused with how to use loadMtl, loadTexture to load the texture on top of the mesh. Any help will be great! :)
Hi,
Wonderful package ! :)
I contact you to know if it is possible to dynamically modify the material associated to an object?
Example : modify the ambient/diffuse/reflec...
Many thanks :)
hey, how can I add circular spinner loader till my object is loaded on scenecreated.
There is a way to have a spherical object (like a earth map) that dosent mess up with the screen???
Or something to make the obj auto rotate on x axis?
I took the planet example, and provided a higher res picture for the texture, but when I zoom in, the same pixelation occurs on the same level. What am I doing wrong?
Hi there,
Is it possible to interact with 3D objects?
What I need is to be able to know when the user taps on a 3D object.
I'm using the package but when running it doesn't bring color, is it a recurring problem?
as titled
So I tried having a cube that rotates according to the mpu6050 which data is read and send via a Arduino Uno. It works perfectly expect for the cube glitching in textures (I tried using different cubes/objects) but the same thing happened.
Also feel free to let me know if I could have done anything else better. Thanks in advance.
import 'dart:convert';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_cube/flutter_cube.dart';
import 'package:funduinoblecontroller/bluetooth/bluetoothmanager.dart';
class CubeScreen extends StatefulWidget {
BluetoothManager blemanager;
CubeScreen({Key? key, required this.blemanager}) : super(key: key);
@override
_CubeScreenState createState() => _CubeScreenState();
}
class _CubeScreenState extends State<CubeScreen> with SingleTickerProviderStateMixin {
late Scene _scene;
Object? _cube;
bool run = true;
double xAngle = 0;
double yAngle = 0;
double zAngle = 0;
double prevXAngle = 0;
double prevYAngle = 0;
double prevZAngle = 0;
double defaultvalueX = 0;
double defaultvalueY = 0;
double defaultvalueZ = 0;
bool isDefaultSet = false;
late AnimationController _controller;
void _onSceneCreated(Scene scene) {
_scene = scene;
scene.camera.position.z = 27;
// set light
_cube = Object(scale: Vector3(8.0, 8.0, 8.0), backfaceCulling: false , isAsset: true,
lighting: true,
fileName: 'assets/cube/cube.obj');
// enable lighting
scene.world.add(_cube!);
// position the light behind the camera
scene.light.position.z = -1;
}
// dispose remove the listener and reset the scene cube etc
@override
void dispose(){
run = false;
_controller.dispose();
_cube = null;
_scene = Scene();
super.dispose();
}
Future<void> getMessages() async {
while (run) {
await Future.delayed(Duration(milliseconds: 20));
try {
// Replace with your actual bluetooth reading logic
await Future.delayed(Duration(milliseconds: 20));
try {
List<int> readValue = await widget.blemanager.selectedCharacteristic!.read();
if(!utf8.decode(readValue).contains(widget.blemanager.messagebuffertemp)){
widget.blemanager.messagebuffertemp = utf8.decode(readValue);
await widget.blemanager.updatebuffer();
}
} catch (e) { }
String message = widget.blemanager.messagebuffer;
RegExp exp = RegExp(r'([XYZ])([+-]?\d+(\.\d+)?)');
Iterable<RegExpMatch> matches = exp.allMatches(message);
Map<String, double> values = {};
for (var match in matches) {
String? value = match.group(1); // X, Y, or Z
String? count = match.group(2); // value
values[value!] = double.parse(count!);
}
if (values.containsKey("X")) {
xAngle = values["X"]!;
}
if (values.containsKey("Y")) {
yAngle = values["Y"]!;
}
if (values.containsKey("Z")) {
zAngle = values["Z"]!;
}
// If default values are not set, set them and take them as reference
if (!isDefaultSet) {
defaultvalueX = xAngle;
defaultvalueY = yAngle;
defaultvalueZ = zAngle;
isDefaultSet = true;
} else {
xAngle -= defaultvalueX;
yAngle -= defaultvalueY;
zAngle -= defaultvalueZ;
}
if (xAngle != prevXAngle || yAngle != prevYAngle || zAngle != prevZAngle) {
try{
setState(() {
if (_cube != null) {
var x = xAngle;
var y = yAngle;
var z = zAngle;
_cube!.position.x = 5.0;
_cube!.position.y = 5.0;
_cube!.position.z = 5.0;
// The X,Y,Z are not assigned to themselfs due to the mpu6050 sensor
// not being mounted in the same orientation as the cube
_cube!.rotation.x = -y;
_cube!.rotation.y = z;
_cube!.rotation.z = -x;
_cube!.position.x = 0.0;
_cube!.position.y = 0.0;
_cube!.position.z = 0.0;
_cube!.updateTransform();
_scene.update();
}
});
}catch (e){
run = false;
}
}
// Store the current values for the next comparison
prevXAngle = xAngle;
prevYAngle = yAngle;
prevZAngle = zAngle;
} catch (e) {
run = false;
}
}
}
@override
void initState() {
super.initState();
_controller = AnimationController(duration: Duration(milliseconds: 600), vsync: this)
..addListener(() {
if (_cube != null) {
_cube!.lighting = true;
_cube!.updateTransform();
_scene.update();
}
})
..repeat();
getMessages();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("MPU Cube"),
),
body: Stack(
children: [
Center(
child: Cube(
interactive: false,
onSceneCreated: _onSceneCreated,
),
),
],
),
);
}
}
Here are some images of the problem:
Hi, I am facing an issue when rendering the 3d Object.
this is my mask image.
this is my code
Cube(
onSceneCreated: (Scene scene) {
scene.world.add(
Object(
fileName: 'assets/shoe.obj',
scale: Vector3.all(5),
lighting: true,
),
);
},
)
my mtl file
newmtl Material
Ns 323.999994
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.0 0.0 0.0
Ni 1.450000
d 1.000000
illum 2
map_Kd diffuse.png
any solution to this?
Hey,
This package is great, I've noticed an issue where certain faces will flicker in and out of existence when the user rotates around the object.
When I import a wavefront file from the web, it works fine, so it's almost definitely something I'm doing in the export process. My .obj file has two objects in it, could this be the source of the problem? I've also triangulated faces etc to no avail.
目前版本提示 错误 Unhandled Exception: Exception: FormatException: Unexpected extension byte 。是否有解决方案?
Hi , I've put my own obj file into assets folder and try to load it but couldnt work, is there a guide on how to do it?
onSceneCreated: (Scene scene) {
scene.world.add(Object(fileName: 'assets/cube/cube.obj'));
},
not working !!!
hello
some time scene.updateTexture(); is very heavy and have lag
we need add one loading view for updateTexture event
are you have sulotion ?
thank you
Application ruby
is launching and the app bar is visible but the body is empty. After a few seconds, the application is closing.
Example cube_app
works perfectly.
Logcat:
2019-12-26 20:39:00.674 764-1631/? I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.ruby/.MainActivity bnds=[35,1344][237,1633]} from uid 10063 on display 0
2019-12-26 20:39:00.768 764-9223/? I/ActivityManager: Start proc 14946:com.example.ruby/u0a110 for activity com.example.ruby/.MainActivity
2019-12-26 20:39:00.935 14946-14946/? I/om.example.ruby: type=1400 audit(0.0:834): avc: denied { open } for path="/dev/mali0" dev="tmpfs" ino=8197 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
2019-12-26 20:39:00.935 14946-14946/? I/om.example.ruby: type=1400 audit(0.0:835): avc: denied { getattr } for path="/dev/mali0" dev="tmpfs" ino=8197 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
2019-12-26 20:39:01.766 14946-14990/com.example.ruby I/[MALI][Gralloc]: [+]r_hnd(0x7f7747b720), client(72), share_fd(73)
2019-12-26 20:39:01.773 14946-14990/com.example.ruby I/[MALI][Gralloc]: [+]r_hnd(0x7f7747b860), client(72), share_fd(76)
2019-12-26 20:39:01.782 764-784/? I/ActivityManager: Displayed com.example.ruby/.MainActivity: +1s61ms
2019-12-26 20:39:01.789 14946-14990/com.example.ruby I/[MALI][Gralloc]: [+]r_hnd(0x7f7747c260), client(72), share_fd(79)
2019-12-26 20:39:04.110 14946-14965/com.example.ruby I/[MALI][Gralloc]: [+]r_hnd(0x7f563f7820), client(72), share_fd(75)
2019-12-26 20:39:04.140 764-9189/? I/ActivityManager: Fully drawn com.example.ruby/.MainActivity: +3s419ms
2019-12-26 20:39:16.339 764-9224/? I/ActivityManager: Process com.example.ruby (pid 14946) has died
2019-12-26 20:39:16.341 764-9222/? I/WindowManager: WIN DEATH: Window{1fd8e54 u0 com.example.ruby/com.example.ruby.MainActivity}
2019-12-26 20:39:16.350 764-9224/? W/ActivityManager: Force removing ActivityRecord{acfaf8e u0 com.example.ruby/.MainActivity t2206}: app died, no saved state
2019-12-26 20:39:16.367 764-9222/? W/WindowManager: Force-removing child win Window{5a1fef2 u0 SurfaceView - com.example.ruby/com.example.ruby.MainActivity} from container Window{1fd8e54 u0 com.example.ruby/com.example.ruby.MainActivity}
Hi !
Thank you for amazing plugin.
how i can change obj file in cube widget when showing model ?
i think method setState can not working in this widget.
I want to render a 3d object in a game currently developing with flame and forge2d. Is there any way I can use flutter_cube in my game?
Like flutter_cube is a widget but I want to render the 3d object with a physical body component.
How to zoom in and out using mouse or keyboard in windows/web?
Hello thanks for this great package!
I've cloned your project and run the planet example on WEB (chrome) and get this error :
Error: RangeError (index): Index out of range: index should be less than 6291456: 6291456
Then I tried to remove stars & clouds from the scene and keep only earth object, which Is working. But not with clouds & stars.
How could we solve this? This is only happened on WEB (works great on mobile)
Thank you
Hi
Just tested this with .obj file downloaded from Google Poly. Good Plugin.
However, I wish to use a .gltf file created by me in Blender. Is there a support or plans to include this format in the new versions?
Hi, is it possible to adjust the position of the light source while moving the 3D object? or maybe add multiple lights?
Hello,
I'm currently writing an application that is meant to display photogrammetry 3D models. These models usually have high poly counts, ranging from hundreds of thousands to millions. I tried decimating the models in Blender to get a result I'm happy with (Usually around 100,000 - 250,000 faces), but whenever I put those models in my app, they show up as a garbled mess of polygons sort of like this:
I tried decimating them some more (around 50,000 face count) and they look fine in the app, but in that range, they start to lose a little too much detail for my liking.
Do y'all know what the maximum poly count flutter_cube allows before garbling up the models? I wanna try and keep as much detail as possible as some models can be very intricate and lose a ton of detail when decimated...
Or better yet, does anyone know how we can potentially raise the maximum polycount? or would that be too taxing for mobile devices to have rendered more than what's already the maximum?
Thanks for reading
As the cube_app example, if we enable the lighting and change the last line of cube.mtl
map_Kd flutter.png
to a tga file.
map_Kd some.tga
The model and image can be loaded, but the lighting has no effect at all.
I tested many obj models with tga textures, all failed.
Are there any plans to release a new version of the library to pub.dev with lighting support available?
I would like to use it in my project but the latest published package version (0.0.5) does not include it yet, though it is in the master branch of the repository.
It would be so much better if I could change the texture bc Flutter Cube is the best 3d flutter package compatible with me.
I'm composing a scene with a few .obj files and I'm wondering how to store it. The first thing on which I looked was the list of vertices - and I can't get it from the library. It would seem that it should be accessible from scene.world.mesh.vertices, but it's empty.
Please include null safety support
I have some non-texture obj file, such as the one https://graphics.stanford.edu/~mdfisher/Data/Meshes/bunny.ob. I expect some thing like this image
Can you support it? Thank in advanced
I see that zooming and rotating is possible out of the box. How would one be able to pan the object? Or otherwise, how can one best change the camera position manually?
Thanks!
i can see in the code that you thought about including it, but then deemed it unnecessary - and now a noob like me is trying to figure out how to do it :)
can anyone help?
i have a scene and a 3d object (parent) with 2 childreen.
cube0= Object(filename: 'assets/parent.obj');
cube1 = Object(filename: 'assets/child1.obj');
cube2 = Object(filename: 'assets/child2obj');
cube0.add(cube1);
cube0.add(cube2);
scene.world.add(cube0);
i want to update the texture of cube1 with an image
If i write:
cube1.mesh.texture = (load image /image1.jpg)
scene.updateTexture(); // not working
If i want to update the texture of cube0 with an image and i write:
cube0.mesh.texture = (load image /image0.jpg)
scene.updateTexture(); // update cube0 and his sons
Any solution?
i want get 3d object from server and show in my game with package , but this package just show 3d object from local asset , how i can fix this issuse ?
like Imgae.network(url);
i wanna get object from server
does it has future features to have 3d physics support? thanks
how can I draw a geometry with some vertices ?give me an example please. thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.