Skip to content

Commit

Permalink
feat: add control to collision boxes + collision box calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jvenin committed May 9, 2024
1 parent a4483d3 commit 5b07b6c
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 47 deletions.
24 changes: 12 additions & 12 deletions lib/classes/gsf/header2/collision_struct.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,19 @@ class BlockerCollisionStruct extends CollisionStruct {

@override
CollisionModel toModel() {
final center = Vector3(positionX.value, positionY.value, positionZ.value);
final distX = sizeX.value / 2;
final distY = sizeY.value / 2;
final distZ = sizeZ.value / 2;
final basePoint = Vector3(positionX.value, positionY.value, positionZ.value); // back bottom left
final distX = sizeX.value;
final distY = sizeY.value;
final distZ = sizeZ.value;
final List<ModelVertex> vertices = [
ModelVertex(center + Vector3(distX, distY, distZ)), // front top right
ModelVertex(center + Vector3(distX, distY, -distZ)), // front bottom right
ModelVertex(center + Vector3(distX, -distY, distZ)), // back top right
ModelVertex(center + Vector3(distX, -distY, -distZ)), // back bottom right
ModelVertex(center + Vector3(-distX, distY, distZ)), // front top left
ModelVertex(center + Vector3(-distX, distY, -distZ)), // front bottom left
ModelVertex(center + Vector3(-distX, -distY, distZ)), // back top left
ModelVertex(center + Vector3(-distX, -distY, -distZ)), // back bottom left
ModelVertex(basePoint + Vector3(distX, distY, distZ)), // front top right
ModelVertex(basePoint + Vector3(distX, distY, 0)), // front bottom right
ModelVertex(basePoint + Vector3(distX, 0, distZ)), // back top right
ModelVertex(basePoint + Vector3(distX, 0, 0)), // back bottom right
ModelVertex(basePoint + Vector3(0, distY, distZ)), // front top left
ModelVertex(basePoint + Vector3(0, distY, 0)), // front bottom left
ModelVertex(basePoint + Vector3(0, 0, distZ)), // back top left
ModelVertex(basePoint), // back bottom left
];
final List<ModelTriangle> triangles = [
ModelTriangle(
Expand Down
6 changes: 5 additions & 1 deletion lib/widgets/viewer/model_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ModelDrawer extends CustomPainter {
required this.showCloth,
required this.showSkeleton,
required this.showLinks,
required this.showCollisionBoxes,
}) : super(repaint: mousePosition);

final ValueNotifier<MouseEventData> mousePosition;
Expand All @@ -37,6 +38,7 @@ class ModelDrawer extends CustomPainter {
final bool showCloth;
final bool showSkeleton;
final bool showLinks;
final bool showCollisionBoxes;

final Transformation transformation = Transformation();

Expand Down Expand Up @@ -196,7 +198,9 @@ class ModelDrawer extends CustomPainter {
showCloths: showCloth,
showTexture: showTexture,
);
model.drawCollisions(transformation, size, canvas, meshColor);
if (showCollisionBoxes) {
model.drawCollisions(transformation, size, canvas, meshColor);
}
if (showSkeleton) {
model.drawSkeleton(
transformation,
Expand Down
8 changes: 8 additions & 0 deletions lib/widgets/viewer/notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ class ModelSelectionStateNotifier extends Notifier<ModelViewerSelectionState> {
orElse: () => null);
}

void updateShowCollisionBoxes(bool showCollisionBoxes) {
state.maybeMap(
withModel: (withModel) {
state = withModel.copyWith(showCollisionBoxes: showCollisionBoxes);
},
orElse: () => null);
}

void updateFilterAttribute(int indice) {
state.maybeMap(
withModel: (withModel) {
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/viewer/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ class ModelViewerSelectionState with _$ModelViewerSelectionState {
@Default(false) showPartyColor,
@Default(false) showSkeleton,
@Default(true) showLinks,
@Default(false) showCollisionBoxes,
}) = ModelViewerSelectionStateWithModel;
}
114 changes: 84 additions & 30 deletions lib/widgets/viewer/state.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ mixin _$ModelViewerSelectionState {
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks)
dynamic showLinks,
dynamic showCollisionBoxes)
withModel,
}) =>
throw _privateConstructorUsedError;
Expand All @@ -52,7 +53,8 @@ mixin _$ModelViewerSelectionState {
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks)?
dynamic showLinks,
dynamic showCollisionBoxes)?
withModel,
}) =>
throw _privateConstructorUsedError;
Expand All @@ -70,7 +72,8 @@ mixin _$ModelViewerSelectionState {
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks)?
dynamic showLinks,
dynamic showCollisionBoxes)?
withModel,
required TResult orElse(),
}) =>
Expand Down Expand Up @@ -236,7 +239,8 @@ class _$EmptyImpl implements _Empty {
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks)
dynamic showLinks,
dynamic showCollisionBoxes)
withModel,
}) {
return empty(materialsTable, models);
Expand All @@ -258,7 +262,8 @@ class _$EmptyImpl implements _Empty {
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks)?
dynamic showLinks,
dynamic showCollisionBoxes)?
withModel,
}) {
return empty?.call(materialsTable, models);
Expand All @@ -279,7 +284,8 @@ class _$EmptyImpl implements _Empty {
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks)?
dynamic showLinks,
dynamic showCollisionBoxes)?
withModel,
required TResult orElse(),
}) {
Expand Down Expand Up @@ -356,7 +362,8 @@ abstract class _$$ModelViewerSelectionStateWithModelImplCopyWith<$Res>
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks});
dynamic showLinks,
dynamic showCollisionBoxes});
}

/// @nodoc
Expand All @@ -382,6 +389,7 @@ class __$$ModelViewerSelectionStateWithModelImplCopyWithImpl<$Res>
Object? showPartyColor = freezed,
Object? showSkeleton = freezed,
Object? showLinks = freezed,
Object? showCollisionBoxes = freezed,
}) {
return _then(_$ModelViewerSelectionStateWithModelImpl(
models: null == models
Expand All @@ -408,6 +416,9 @@ class __$$ModelViewerSelectionStateWithModelImplCopyWithImpl<$Res>
showSkeleton:
freezed == showSkeleton ? _value.showSkeleton! : showSkeleton,
showLinks: freezed == showLinks ? _value.showLinks! : showLinks,
showCollisionBoxes: freezed == showCollisionBoxes
? _value.showCollisionBoxes!
: showCollisionBoxes,
));
}
}
Expand All @@ -426,7 +437,8 @@ class _$ModelViewerSelectionStateWithModelImpl
this.showTexture = true,
this.showPartyColor = false,
this.showSkeleton = false,
this.showLinks = true})
this.showLinks = true,
this.showCollisionBoxes = false})
: _models = models;

final List<ModelSettings> _models;
Expand Down Expand Up @@ -461,10 +473,13 @@ class _$ModelViewerSelectionStateWithModelImpl
@override
@JsonKey()
final dynamic showLinks;
@override
@JsonKey()
final dynamic showCollisionBoxes;

@override
String toString() {
return 'ModelViewerSelectionState.withModel(models: $models, model: $model, filter: $filter, materialsTable: $materialsTable, showCloth: $showCloth, showNormals: $showNormals, showTexture: $showTexture, showPartyColor: $showPartyColor, showSkeleton: $showSkeleton, showLinks: $showLinks)';
return 'ModelViewerSelectionState.withModel(models: $models, model: $model, filter: $filter, materialsTable: $materialsTable, showCloth: $showCloth, showNormals: $showNormals, showTexture: $showTexture, showPartyColor: $showPartyColor, showSkeleton: $showSkeleton, showLinks: $showLinks, showCollisionBoxes: $showCollisionBoxes)';
}

@override
Expand All @@ -486,7 +501,9 @@ class _$ModelViewerSelectionStateWithModelImpl
.equals(other.showPartyColor, showPartyColor) &&
const DeepCollectionEquality()
.equals(other.showSkeleton, showSkeleton) &&
const DeepCollectionEquality().equals(other.showLinks, showLinks));
const DeepCollectionEquality().equals(other.showLinks, showLinks) &&
const DeepCollectionEquality()
.equals(other.showCollisionBoxes, showCollisionBoxes));
}

@override
Expand All @@ -501,7 +518,8 @@ class _$ModelViewerSelectionStateWithModelImpl
const DeepCollectionEquality().hash(showTexture),
const DeepCollectionEquality().hash(showPartyColor),
const DeepCollectionEquality().hash(showSkeleton),
const DeepCollectionEquality().hash(showLinks));
const DeepCollectionEquality().hash(showLinks),
const DeepCollectionEquality().hash(showCollisionBoxes));

@JsonKey(ignore: true)
@override
Expand All @@ -527,11 +545,22 @@ class _$ModelViewerSelectionStateWithModelImpl
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks)
dynamic showLinks,
dynamic showCollisionBoxes)
withModel,
}) {
return withModel(models, model, filter, materialsTable, showCloth,
showNormals, showTexture, showPartyColor, showSkeleton, showLinks);
return withModel(
models,
model,
filter,
materialsTable,
showCloth,
showNormals,
showTexture,
showPartyColor,
showSkeleton,
showLinks,
showCollisionBoxes);
}

@override
Expand All @@ -550,11 +579,22 @@ class _$ModelViewerSelectionStateWithModelImpl
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks)?
dynamic showLinks,
dynamic showCollisionBoxes)?
withModel,
}) {
return withModel?.call(models, model, filter, materialsTable, showCloth,
showNormals, showTexture, showPartyColor, showSkeleton, showLinks);
return withModel?.call(
models,
model,
filter,
materialsTable,
showCloth,
showNormals,
showTexture,
showPartyColor,
showSkeleton,
showLinks,
showCollisionBoxes);
}

@override
Expand All @@ -572,13 +612,24 @@ class _$ModelViewerSelectionStateWithModelImpl
dynamic showTexture,
dynamic showPartyColor,
dynamic showSkeleton,
dynamic showLinks)?
dynamic showLinks,
dynamic showCollisionBoxes)?
withModel,
required TResult orElse(),
}) {
if (withModel != null) {
return withModel(models, model, filter, materialsTable, showCloth,
showNormals, showTexture, showPartyColor, showSkeleton, showLinks);
return withModel(
models,
model,
filter,
materialsTable,
showCloth,
showNormals,
showTexture,
showPartyColor,
showSkeleton,
showLinks,
showCollisionBoxes);
}
return orElse();
}
Expand Down Expand Up @@ -619,16 +670,18 @@ class _$ModelViewerSelectionStateWithModelImpl
abstract class ModelViewerSelectionStateWithModel
implements ModelViewerSelectionState {
const factory ModelViewerSelectionStateWithModel(
{required final List<ModelSettings> models,
required final ModelSettings model,
required final ChunkAttributes filter,
required final MaterialsTable materialsTable,
final dynamic showCloth,
final dynamic showNormals,
final dynamic showTexture,
final dynamic showPartyColor,
final dynamic showSkeleton,
final dynamic showLinks}) = _$ModelViewerSelectionStateWithModelImpl;
{required final List<ModelSettings> models,
required final ModelSettings model,
required final ChunkAttributes filter,
required final MaterialsTable materialsTable,
final dynamic showCloth,
final dynamic showNormals,
final dynamic showTexture,
final dynamic showPartyColor,
final dynamic showSkeleton,
final dynamic showLinks,
final dynamic showCollisionBoxes}) =
_$ModelViewerSelectionStateWithModelImpl;

@override
List<ModelSettings> get models;
Expand All @@ -642,6 +695,7 @@ abstract class ModelViewerSelectionStateWithModel
dynamic get showPartyColor;
dynamic get showSkeleton;
dynamic get showLinks;
dynamic get showCollisionBoxes;
@override
@JsonKey(ignore: true)
_$$ModelViewerSelectionStateWithModelImplCopyWith<
Expand Down
Loading

0 comments on commit 5b07b6c

Please sign in to comment.