Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Show "x" markers where skinning process failed

Scott Petrovic57459ea6dcd3
diff --git a/src/lib/Generators.ts b/src/lib/Generators.ts
index 72b2a4b..48f07b1 100644
--- a/src/lib/Generators.ts
+++ b/src/lib/Generators.ts
@@ -2,9 +2,11 @@ import {
PerspectiveCamera, DoubleSide, DirectionalLight, GridHelper,
Bone, Skeleton, AmbientLight, PlaneGeometry, Mesh,
SphereGeometry, type MeshBasicMaterial, MeshPhongMaterial, AxesHelper,
- Vector3, PointsMaterial, BufferGeometry, Points, type Object3D, WebGLRenderer
+ Vector3, PointsMaterial, BufferGeometry, Points, type Object3D, WebGLRenderer,
+ Group, Line, LineBasicMaterial
} from 'three'
+
import { CustomSkeletonHelper } from './CustomSkeletonHelper'
import { Utility } from './Utilities'
@@ -79,16 +81,46 @@ export class Generators {
static create_skeleton_helper (skeleton: Skeleton): CustomSkeletonHelper {
const skeleton_helper = new CustomSkeletonHelper(skeleton.bones[0], { lineWidth: 5, dashed: true })
- skeleton_helper.setLineWidth(30)
return skeleton_helper
}
+ // create x markers at a location in space
+ static create_x_markers (points: Vector3[], size = 0.1, color = 0xff0000, name = ''): Group {
+ const group = new Group()
+ group.name = `X markers: ${name}`
+
+ const material = new LineBasicMaterial({
+ color,
+ depthTest: false
+ })
+
+ points.forEach(point => {
+ // Create first diagonal line (\ direction)
+ const geometry1 = new BufferGeometry().setFromPoints([
+ new Vector3(point.x - size, point.y - size, point.z),
+ new Vector3(point.x + size, point.y + size, point.z)
+ ])
+ const line1 = new Line(geometry1, material)
+
+ // Create second diagonal line (/ direction)
+ const geometry2 = new BufferGeometry().setFromPoints([
+ new Vector3(point.x - size, point.y + size, point.z),
+ new Vector3(point.x + size, point.y - size, point.z)
+ ])
+ const line2 = new Line(geometry2, material)
+
+ group.add(line1)
+ group.add(line2)
+ })
+
+ return group
+ }
+
static create_spheres_for_points (points: Vector3[], sphere_size = 0.01, color = 0x00ffff, name = ''): Points {
const points_material: PointsMaterial = new PointsMaterial({ size: sphere_size, color })
const points_geometry = new BufferGeometry().setFromPoints(points)
const point_objects: Points = new Points(points_geometry, points_material)
- point_objects.name = `Point display: ${name} `
-
+ point_objects.name = `Point display: ${name}`
return point_objects
}
diff --git a/src/script.ts b/src/script.ts
index dbeae5f..6d865b0 100644
--- a/src/script.ts
+++ b/src/script.ts
@@ -16,7 +16,7 @@ import { StepExportToFile } from './lib/processes/StepExportToFile.ts'
import { StepWeightSkin } from './lib/processes/StepWeightSkin.ts'
import { ProcessStep } from './lib/enums/ProcessStep.ts'
-import { type Bone, Group, Scene, type Skeleton, type Vector3, type Points } from 'three'
+import { type Bone, Group, Scene, type Skeleton, type Vector3 } from 'three'
import type BoneTesterData from './lib/models/BoneTesterData.ts'
import { build_version } from './environment.js'
@@ -118,9 +118,9 @@ export class Bootstrap {
}
private show_skin_failure_message (bone_names_with_errors: string[], error_point_positions: Vector3[]): void {
- // add the bone vertices as sphere to debugging object
- const sphere_failures: Points = Generators.create_spheres_for_points(error_point_positions, 0.08, 0xff0000)
- this.debugging_visual_object.add(sphere_failures)
+ // add the bone vertices as X markers to debugging object
+ const error_markers: Group = Generators.create_x_markers(error_point_positions, 0.02, 0xff0000)
+ this.debugging_visual_object.add(error_markers)
// add information to the info panel
if (this.ui.dom_info_panel === null) {