Skip to content

Commit e20fb8b

Browse files
committed
add ?debugEntities for list of supported entities
1 parent cd2ff62 commit e20fb8b

File tree

3 files changed

+21
-161
lines changed

3 files changed

+21
-161
lines changed
Lines changed: 2 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1,166 +1,13 @@
1-
//@ts-nocheck
21
import { BasePlaygroundScene } from '../baseScene'
32
import { EntityDebugFlags, EntityMesh, rendererSpecialHandled } from '../../viewer/three/entity/EntityMesh'
3+
import { displayEntitiesDebugList } from '../allEntitiesDebug'
44

55
export default class AllEntities extends BasePlaygroundScene {
66
continuousRender = false
77
enableCameraControls = false
88

99
async initData () {
1010
await super.initData()
11-
12-
// Create results container
13-
const container = document.createElement('div')
14-
container.style.cssText = `
15-
position: fixed;
16-
top: 50%;
17-
left: 50%;
18-
transform: translate(-50%, -50%);
19-
max-height: 90vh;
20-
overflow-y: auto;
21-
background: rgba(0,0,0,0.8);
22-
color: white;
23-
padding: 20px;
24-
border-radius: 8px;
25-
font-family: monospace;
26-
min-width: 400px;
27-
`
28-
document.body.appendChild(container)
29-
30-
// Add title
31-
const title = document.createElement('h2')
32-
title.textContent = 'Minecraft Entity Support'
33-
title.style.cssText = 'margin-top: 0; text-align: center;'
34-
container.appendChild(title)
35-
36-
// Test entities
37-
const results: Array<{
38-
entity: string;
39-
supported: boolean;
40-
type?: 'obj' | 'bedrock';
41-
mappedFrom?: string;
42-
textureMap?: boolean;
43-
errors?: string[];
44-
}> = []
45-
const { mcData } = window
46-
const entityNames = Object.keys(mcData.entitiesArray.reduce((acc, entity) => {
47-
acc[entity.name] = true
48-
return acc
49-
}, {}))
50-
51-
// Add loading indicator
52-
const loading = document.createElement('div')
53-
loading.textContent = 'Testing entities...'
54-
loading.style.textAlign = 'center'
55-
container.appendChild(loading)
56-
57-
for (const entity of entityNames) {
58-
const debugFlags: EntityDebugFlags = {}
59-
60-
try {
61-
// eslint-disable-next-line no-new
62-
new EntityMesh(this.version, entity, viewer.world, {}, debugFlags)
63-
64-
results.push({
65-
entity,
66-
supported: !!debugFlags.type || rendererSpecialHandled.includes(entity),
67-
type: debugFlags.type,
68-
mappedFrom: debugFlags.tempMap,
69-
textureMap: debugFlags.textureMap,
70-
errors: debugFlags.errors
71-
})
72-
} catch (e) {
73-
console.error(e)
74-
results.push({
75-
entity,
76-
supported: false,
77-
mappedFrom: debugFlags.tempMap
78-
})
79-
}
80-
}
81-
82-
// Remove loading indicator
83-
loading.remove()
84-
85-
const createSection = (title: string, items: any[], filter: (item: any) => boolean) => {
86-
const section = document.createElement('div')
87-
section.style.marginBottom = '20px'
88-
89-
const sectionTitle = document.createElement('h3')
90-
sectionTitle.textContent = title
91-
sectionTitle.style.textAlign = 'center'
92-
section.appendChild(sectionTitle)
93-
94-
const list = document.createElement('ul')
95-
list.style.cssText = 'padding-left: 20px; list-style-type: none; margin: 0;'
96-
97-
const filteredItems = items.filter(filter)
98-
for (const item of filteredItems) {
99-
const listItem = document.createElement('li')
100-
listItem.style.cssText = 'line-height: 1.4; margin: 8px 0;'
101-
102-
const entityName = document.createElement('strong')
103-
entityName.style.cssText = 'user-select: text;-webkit-user-select: text;'
104-
entityName.textContent = item.entity
105-
listItem.appendChild(entityName)
106-
107-
let text = ''
108-
if (item.mappedFrom) {
109-
text += ` -> ${item.mappedFrom}`
110-
}
111-
if (item.type) {
112-
text += ` - ${item.type}`
113-
}
114-
if (item.textureMap) {
115-
text += ' ⚠️'
116-
}
117-
if (item.errors) {
118-
text += ' ❌'
119-
}
120-
121-
listItem.appendChild(document.createTextNode(text))
122-
list.appendChild(listItem)
123-
}
124-
125-
section.appendChild(list)
126-
return { section, count: filteredItems.length }
127-
}
128-
129-
// Sort results - bedrock first
130-
results.sort((a, b) => {
131-
if (a.type === 'bedrock' && b.type !== 'bedrock') return -1
132-
if (a.type !== 'bedrock' && b.type === 'bedrock') return 1
133-
return a.entity.localeCompare(b.entity)
134-
})
135-
136-
// Add sections
137-
const sections = [
138-
{
139-
title: '❌ Unsupported Entities',
140-
filter: (r: any) => !r.supported && !r.mappedFrom
141-
},
142-
{
143-
title: '⚠️ Partially Supported Entities',
144-
filter: (r: any) => r.mappedFrom
145-
},
146-
{
147-
title: '✅ Supported Entities',
148-
filter: (r: any) => r.supported && !r.mappedFrom
149-
}
150-
]
151-
152-
for (const { title, filter } of sections) {
153-
const { section, count } = createSection(title, results, filter)
154-
if (count > 0) {
155-
container.appendChild(section)
156-
}
157-
}
158-
159-
// log object with errors per entity
160-
const errors = results.filter(r => r.errors).map(r => ({
161-
entity: r.entity,
162-
errors: r.errors
163-
}))
164-
console.log(errors)
11+
displayEntitiesDebugList(this.version)
16512
}
16613
}

renderer/viewer/three/entities.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,14 @@ export class Entities {
10891089
})
10901090
}
10911091
}
1092+
1093+
raycastScene () {
1094+
// return any object from scene. raycast from camera
1095+
const raycaster = new THREE.Raycaster()
1096+
raycaster.setFromCamera(new THREE.Vector2(0, 0), this.worldRenderer.camera)
1097+
const intersects = raycaster.intersectObjects(this.worldRenderer.scene.children)
1098+
return intersects[0]?.object
1099+
}
10921100
}
10931101

10941102
function getGeneralEntitiesMetadata (entity: { name; metadata }): Partial<UnionToIntersection<EntityMetadataVersions[keyof EntityMetadataVersions]>> {
@@ -1187,12 +1195,6 @@ function addArmorModel (worldRenderer: WorldRendererThree, entityMesh: THREE.Obj
11871195
group.name = `armor_${slotType}${overlay ? '_overlay' : ''}`
11881196
group.add(mesh)
11891197

1190-
const skeletonHelper = new THREE.SkeletonHelper(mesh)
1191-
//@ts-expect-error
1192-
skeletonHelper.material.linewidth = 2
1193-
skeletonHelper.visible = false
1194-
group.add(skeletonHelper)
1195-
11961198
entityMesh.add(mesh)
11971199
}
11981200

renderer/viewer/three/graphicsBackend.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Vec3 } from 'vec3'
33
import { GraphicsBackendLoader, GraphicsBackend, GraphicsInitOptions, DisplayWorldOptions } from '../../../src/appViewer'
44
import { ProgressReporter } from '../../../src/core/progressReporter'
55
import { showNotification } from '../../../src/react/NotificationProvider'
6+
import { displayEntitiesDebugList } from '../../playground/allEntitiesDebug'
7+
import supportedVersions from '../../../src/supportedVersions.mjs'
68
import { WorldRendererThree } from './worldrendererThree'
79
import { DocumentRenderer } from './documentRenderer'
810
import { PanoramaRenderer } from './panorama'
@@ -55,6 +57,15 @@ const createGraphicsBackend: GraphicsBackendLoader = (initOptions: GraphicsInitO
5557

5658
const startPanorama = async () => {
5759
if (worldRenderer) return
60+
const qs = new URLSearchParams(window.location.search)
61+
if (qs.get('debugEntities')) {
62+
initOptions.resourcesManager.currentConfig = { version: qs.get('version') || supportedVersions.at(-1)!, noInventoryGui: true }
63+
await initOptions.resourcesManager.updateAssetsData({ })
64+
65+
displayEntitiesDebugList(initOptions.resourcesManager.currentConfig.version)
66+
return
67+
}
68+
5869
if (!panoramaRenderer) {
5970
panoramaRenderer = new PanoramaRenderer(documentRenderer, initOptions, !!process.env.SINGLE_FILE_BUILD_MODE)
6071
window.panoramaRenderer = panoramaRenderer

0 commit comments

Comments
 (0)