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

Add custom face color calculation function #3

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ grouping the vertices into one single draw call). It is also a null-safe library

## Preview

![Failed to load Screenshot](https://github.com/arnovanliere/object_3d/blob/master/screenshot.png)
![Failed to load Screenshot](./screenshots/screenshot.png)
![Failed to load Screenshot](./screenshots/fresnel.png)
See more in [/screenshots](./screenshots/).

## Credits
- All credits for the initial library go to [hemanthrajv](https://github.com/hemanthrajv/flutter_3d_obj).
- Gesture feedback, optimization, and face coloring customization are thanks to [TheMaverickProgrammer](https://github.com/TheMaverickProgrammer) in collaboration with [DBL](https://github.com/InstrinsicAutomations).
21 changes: 18 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ linter:
prefer_final_in_for_each: true
use_build_context_synchronously: true
always_declare_return_types: true
always_specify_types: false
omit_local_variable_types: true
avoid_types_on_closure_parameters: true
always_specify_types: true
void_checks: true
use_raw_strings: true
unnecessary_this: true
unnecessary_string_interpolations: true
unnecessary_string_escapes: true
unnecessary_null_aware_assignments: true
unnecessary_new: true
unnecessary_late: true
unnecessary_lambdas: true
unnecessary_brace_in_string_interps: true
prefer_asserts_in_initializer_lists: true
prefer_asserts_with_message: true
lines_longer_than_80_chars: true
avoid_setters_without_getters: true
avoid_return_types_on_setters: true
annotate_overrides: true
always_put_required_named_parameters_first: true
26 changes: 24 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'dart:math' as math;
import 'package:vector_math/vector_math_64.dart' show Vector3;
import 'package:object_3d/object_3d.dart';

void main() {
Expand Down Expand Up @@ -29,16 +31,36 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
// (uncomment line in Object3D constructor)
// ignore: unused_element
Face _fresnel(Face face) {
final color = Colors.blue;
final light = Vector3(0.0, 0.0, 100.0).normalized();
double ln1 = light.dot(face.normal);
double s1 = 1.0 + face.v1.normalized().dot(face.normal);
double s2 = 1.0 + face.v2.normalized().dot(face.normal);
double s3 = 1.0 + face.v3.normalized().dot(face.normal);
double power = 2;

Color c = Color.fromRGBO(
(color.red + math.pow(s1, power).round()).clamp(0, 255),
(color.green + math.pow(s2, power).round()).clamp(0, 255),
(color.blue + math.pow(s3, power).round()).clamp(0, 255),
1.0 - ln1.abs());
return face..setColors(c, c, c);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Object 3D Example'),
),
body: const Center(
body: Center(
child: Object3D(
size: Size(400.0, 400.0),
size: const Size(400.0, 400.0),
path: "assets/file.obj",
// faceColorFunc: _fresnel, // uncomment to see in action
),
),
);
Expand Down
Loading
Loading