bdero / flutter_scene

3D library for Flutter.
MIT License
173 stars 11 forks source link

demo runs not smoothly on android #39

Open wangcker opened 2 weeks ago

wangcker commented 2 weeks ago

The demo program runs not smoothly and stutters on the Android system, but it run smoothly on the iOS system

android runs video:

https://github.com/user-attachments/assets/171e7477-208c-4c9b-a6c2-78f10b81e4ce

wangcker commented 2 weeks ago

the whole code :


import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_scene/camera.dart';
import 'package:flutter_scene/node.dart';

import 'package:flutter_scene/scene.dart';
import 'package:vector_math/vector_math.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
  double elapsedSeconds = 0;
  Scene scene = Scene();

  @override
  void initState() {
    createTicker((elapsed) {
      debugPrint("time ${elapsed.inMilliseconds.toDouble() / 1000}");
      setState(() {
        elapsedSeconds = elapsed.inMilliseconds.toDouble() / 1000;
      });
    }).start();

    Node.fromAsset('build/models/DamagedHelmet.model').then((model) {
      model.name = 'Helmet';
      scene.add(model);
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final painter = ScenePainter(
      scene: scene,
      camera: PerspectiveCamera(
        position: Vector3(sin(elapsedSeconds) * 2, 2, cos(elapsedSeconds) * 2),
        target: Vector3(0, 0, 0),
      ),
    );

    return MaterialApp(
      title: '我的 3D 应用',
      home: CustomPaint(painter: painter),
    );
  }
}

class ScenePainter extends CustomPainter {
  ScenePainter({required this.scene, required this.camera});
  Scene scene;
  Camera camera;

  @override
  void paint(Canvas canvas, Size size) {
    scene.render(camera, canvas, viewport: Offset.zero & size);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}
kwill39 commented 2 weeks ago

@wangcker did you run using flutter scene locally like in #38 ? I'm curious if were you able to resolve that issue when you ran the demo

wangcker commented 2 weeks ago

@wangcker did you run using flutter scene locally like in #38 ? I'm curious if were you able to resolve that issue when you ran the demo

no,the problem still exists , so change the flutter_scene ref from pub.dev.

wangcker commented 2 weeks ago

@wangcker did you run using flutter scene locally like in #38 ? I'm curious if were you able to resolve that issue when you ran the demo

i fix it #43

bdero commented 1 week ago

Some questions:

wangcker commented 20 hours ago

it`s may be producted by memory leak