-
Notifications
You must be signed in to change notification settings - Fork 12
Feat/asset packs validation #1263
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import type { AssetComposite } from '../types'; | ||
|
|
||
| // SDK defaults for GltfContainer collision masks (from @dcl/ecs) | ||
| const CL_POINTER = 1; | ||
| const CL_PHYSICS = 2; | ||
| const GLTF_DEFAULT_VISIBLE_MASK = 0; // CL_NONE | ||
| const GLTF_DEFAULT_INVISIBLE_MASK = CL_PHYSICS; | ||
|
|
||
| type Component = AssetComposite['components'][number]; | ||
|
|
||
| export function getComponent(components: Component[], name: string): Component | undefined { | ||
| return components.find(c => c.name === name); | ||
| } | ||
|
|
||
| export function hasComponent(components: Component[], name: string): boolean { | ||
| return components.some(c => c.name === name); | ||
| } | ||
|
|
||
| export function getComponentData(components: Component[], name: string): any | undefined { | ||
| return getComponent(components, name)?.data?.['0']?.json; | ||
| } | ||
|
|
||
| /** | ||
| * Check if entity has a collider with the given mask. | ||
| * GltfContainer is considered a valid pointer collider because GLTF models | ||
| * can have internal collider meshes (*_collider) that the SDK uses for raycasting. | ||
| */ | ||
| export function hasPointerCollider(components: Component[]): boolean { | ||
| const meshCollider = getComponentData(components, 'core::MeshCollider'); | ||
| if (meshCollider && (meshCollider.collisionMask & CL_POINTER) !== 0) return true; | ||
|
|
||
| // GltfContainer models support pointer raycasting via their visible meshes | ||
| // and internal *_collider meshes, even without explicit collision masks | ||
| if (hasComponent(components, 'core::GltfContainer')) return true; | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns const gltf = getComponentData(components, 'core::GltfContainer');
if (gltf) {
const vis = gltf.visibleMeshesCollisionMask ?? GLTF_DEFAULT_VISIBLE_MASK;
const invis = gltf.invisibleMeshesCollisionMask ?? GLTF_DEFAULT_INVISIBLE_MASK;
if ((vis & CL_POINTER) !== 0 || (invis & CL_POINTER) !== 0) return true;
} |
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Check if entity has any explicit collision mask > 0 set. | ||
| * Uses SDK defaults when values are not specified in the composite. | ||
| */ | ||
| export function hasAnyCollisionMask(components: Component[]): boolean { | ||
| const meshCollider = getComponentData(components, 'core::MeshCollider'); | ||
| if (meshCollider && meshCollider.collisionMask > 0) return true; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
|
|
||
| const gltf = getComponentData(components, 'core::GltfContainer'); | ||
| if (gltf) { | ||
| const visibleMask = gltf.visibleMeshesCollisionMask ?? GLTF_DEFAULT_VISIBLE_MASK; | ||
| const invisibleMask = gltf.invisibleMeshesCollisionMask ?? GLTF_DEFAULT_INVISIBLE_MASK; | ||
| if (visibleMask > 0 || invisibleMask > 0) return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { AssetComposite } from '../types'; | ||
| import type { ValidationError } from './rules'; | ||
| import { rules } from './rules'; | ||
|
|
||
| export type { ValidationError } from './rules'; | ||
|
|
||
| export function validateComposite( | ||
| components: AssetComposite['components'], | ||
| assetName: string, | ||
| ): ValidationError[] { | ||
| return rules.flatMap(rule => rule.validate(components, assetName)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
console.log(asset.name, 'β ')runs even when the asset has validation errors β misleading in CI logs. Wrap it: