Skip to content

Package does not render 3D asset when app is built with obfuscation #239

@OlliePorter

Description

@OlliePorter

Problem

The 3D .glb file renders correctly when the Flutter app is built without obfuscation: flutter build ipa.

The 3D .glb file does not render when the Flutter app is built with obfuscation: flutter build ipa --obfuscate --split-debug-info=debug-info --no-tree-shake-icons. Adding either flag, --obfuscate or --no-tree-shake-icons causes the file not to be visible.

Expected

The 3D .glb file should be rendered in all cases, even in cases where the application is built with obfuscation for added security.

Code

 import 'dart:io';

import 'package:flutter/material.dart';
import 'package:arkit_plugin/arkit_plugin.dart';
import 'package:flutter/services.dart';
import 'package:jippi_app/widgets/ui/app_color.dart';
import 'package:vector_math/vector_math_64.dart';
import 'package:dio/dio.dart';
import 'package:path_provider/path_provider.dart';

class Render3D extends StatefulWidget {
  @override
  _Render3DState createState() => _Render3DState();
}

class _Render3DState extends State<Render3D> {
  late ARKitController arkitController;

  @override
  void dispose() {
    arkitController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: AppColor.white,
        title: const Text(
          "Render 3D Item",
          style: TextStyle(
            fontWeight: FontWeight.w700,
            fontSize: 26,
            fontFamily: 'Nunito',
            color: AppColor.black,
          ),
        ),
      ),
      body: ARKitSceneView(
        worldAlignment: ARWorldAlignment.gravity,
        onARKitViewCreated: onARKitViewCreated,
      ),
    );
  }

  void onARKitViewCreated(ARKitController arkitController) async {
    this.arkitController = arkitController;

    String url = "https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Box/glTF-Binary/Box.glb";

    try {
      final dir = await getApplicationDocumentsDirectory();
      final filePath = '${dir.path}/${url.split("/").last}';
      await Dio().download(url, filePath);
      final file = File(filePath);

      if (file.existsSync()) {
        final node = ARKitGltfNode(
          assetType: AssetType.documents,
          url: file.path.split('/').last,
          scale: Vector3(0.15, 0.15, 0.15),
          position: Vector3(0, 0, -0.5),
        );

        final light = ARKitLight(
          type: ARKitLightType.directional,
          color: AppColor.white,
          intensity: 1000, // Increase intensity for brighter lighting
        );

        final lightNode = ARKitNode(
          light: light,
          position: Vector3(0, 10, 10), // Adjust position for optimal lighting
        );

        this.arkitController.add(lightNode);
        this.arkitController.add(node);
      } else {
        showErrorDialog('FILE DOES NOT EXIST');
        print('ERROR');
      }
    } catch (e) {
      showErrorDialog('Caught an exception: $e');
      print('Caught an exception: $e');
      rethrow;
    }
  }

  void showErrorDialog(String message) {
    showDialog<void>(
      context: context,
      builder: (BuildContext context) => AlertDialog(
        title: const Text("Error"),
        content: Text(message),
        actions: [
          TextButton(
            onPressed: () => Navigator.of(context).pop(),
            child: const Text("OK"),
          ),
        ],
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions