Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load renderable #234

Open
zachgumball opened this issue Oct 7, 2024 · 0 comments
Open

Unable to load renderable #234

zachgumball opened this issue Oct 7, 2024 · 0 comments

Comments

@zachgumball
Copy link

hello, i have this problem when try to add the 3d object to screen. My object 3d path is all correct, trying to use Chicken_01.gltf but still error. When I checking this gltf file it say error
How to fix this?
This is My code :
import 'package:flutter/material.dart';
import 'package:ar_flutter_plugin/managers/ar_location_manager.dart';
import 'package:ar_flutter_plugin/managers/ar_session_manager.dart';
import 'package:ar_flutter_plugin/managers/ar_object_manager.dart';
import 'package:ar_flutter_plugin/managers/ar_anchor_manager.dart';
import 'package:ar_flutter_plugin/models/ar_node.dart';
import 'package:ar_flutter_plugin/ar_flutter_plugin.dart';
import 'package:vector_math/vector_math_64.dart' hide Colors;
import 'package:ar_flutter_plugin/datatypes/node_types.dart';

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

@OverRide
_Materi1State createState() => _Materi1State();
}

class _Materi1State extends State {
ARSessionManager? arSessionManager;
ARObjectManager? arObjectManager;

void onARViewCreated(
ARSessionManager sessionManager, ARObjectManager objectManager) {
arSessionManager = sessionManager;
arObjectManager = objectManager;

// Initialize AR session settings
arSessionManager!.onInitialize(
  showFeaturePoints: false,
  showPlanes: true,
  showWorldOrigin: false,
);

arObjectManager!.onInitialize();

}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cahaya dan Bunyi'),
),
body: Stack(
children: [
Positioned.fill(
child: Image.asset(
'assets/background/background2.png',
fit: BoxFit.cover,
),
),
Container(
color: Colors.white.withOpacity(0.7),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image.asset(
'assets/matahari.jpg',
width: 370,
height: 200,
fit: BoxFit.cover,
),
),
const SizedBox(height: 16),
const Text(
'Mengenal Cahaya dan Bunyi',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
const Divider(thickness: 2, color: Colors.grey),
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 5,
),
],
),
child: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Cahaya adalah radiasi elektromagnetik yang dapat dilihat oleh mata manusia. Ia memiliki panjang gelombang yang bervariasi, biasanya dalam rentang 380 hingga 750 nanometer. Cahaya adalah sumber energi yang memungkinkan proses fotosintesis pada tanaman dan mempengaruhi penglihatan manusia. Dalam ilmu fisika, cahaya juga dapat dianggap sebagai aliran partikel yang disebut foton dan dapat berperilaku sebagai gelombang. Cahaya dapat dipantulkan, dib refraksikan, dan diserap oleh berbagai material.',
style: TextStyle(fontSize: 16),
),
],
),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ARViewScreen()),
);
},
child: const Text('Tampilkan Objek 3D dalam AR'),
),
],
),
),
],
),
);
}
}

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

@OverRide
_ARViewScreenState createState() => _ARViewScreenState();
}

class _ARViewScreenState extends State {
ARSessionManager? arSessionManager;
ARObjectManager? arObjectManager;

void onARViewCreated(
ARSessionManager sessionManager, ARObjectManager objectManager) {
arSessionManager = sessionManager;
arObjectManager = objectManager;

// Initialize AR session settings
arSessionManager!.onInitialize(
  showFeaturePoints: false,
  showPlanes: false,
  showWorldOrigin: false,
);

arObjectManager!.onInitialize();

}

Future onPlaceObject() async {
var newNode = ARNode(
type: NodeType.localGLTF2,
uri: "assets/models/AnimatedCube.gltf",
scale: Vector3(0.2, 0.2, 0.2),
position: Vector3(0, 0, 0),
rotation: Vector4(0, 0, 0, 0),
);

// Coba tambahkan node
bool? didAdd = await arObjectManager?.addNode(newNode);
if (didAdd!) {
  print("3D Object added successfully!");
} else {
  print("Failed to add 3D Object.");
}

}

@OverRide
void dispose() {
arSessionManager?.dispose();
super.dispose();
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('AR View')),
body: ARView(
onARViewCreated: (arSessionManager, arObjectManager, arAnchorManager,
arCameraManager) {
onARViewCreated(arSessionManager, arObjectManager);
},
),
floatingActionButton: FloatingActionButton(
onPressed: onPlaceObject,
child: const Icon(Icons.add),
),
);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant