Skip to content

Commit

Permalink
feat: Almost full entities rendering. Mobs are now rendered correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Apr 18, 2024
1 parent fd42c9c commit 2d3ab6c
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 186 deletions.
3 changes: 2 additions & 1 deletion esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const buildOptions = {
'.png': 'dataurl',
'.map': 'empty',
'.vert': 'text',
'.frag': 'text'
'.frag': 'text',
'.obj': 'text',
},
write: false,
// todo would be better to enable?
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "node scripts/build.js copyFilesDev && node scripts/prepareData.mjs && node esbuild.mjs --watch",
"start-watch-script": "nodemon -w esbuild.mjs --watch",
"build": "node scripts/build.js copyFiles && node scripts/prepareData.mjs -f && node esbuild.mjs --minify --prod",
"check-build": "tsc && pnpm test-unit --run && pnpm build",
"check-build": "tsc && pnpm build",
"test:cypress": "cypress run",
"test-unit": "vitest",
"test:e2e": "start-test http-get://localhost:8080 test:cypress",
Expand Down Expand Up @@ -44,6 +44,7 @@
"@xmcl/text-component": "^2.1.3",
"@zardoy/react-util": "^0.2.0",
"@zardoy/utils": "^0.0.11",
"adm-zip": "^0.5.12",
"browserfs": "github:zardoy/browserfs#build",
"change-case": "^5.1.2",
"compression": "^1.7.4",
Expand Down
36 changes: 28 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions prismarine-viewer/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const buildOptions = {
metafile: true,
loader: {
'.png': 'dataurl',
'.obj': 'text',
},
plugins: [
{
Expand Down
7 changes: 3 additions & 4 deletions prismarine-viewer/examples/playground.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash'
import { WorldDataEmitter, Viewer, MapControls } from '../viewer'
import { WorldDataEmitter, Viewer } from '../viewer'
import { Vec3 } from 'vec3'
import { Schematic } from 'prismarine-schematic'
import BlockLoader from 'prismarine-block'
import ChunkLoader from 'prismarine-chunk'
import WorldLoader from 'prismarine-world'
Expand All @@ -11,7 +10,7 @@ import { toMajor } from '../viewer/lib/version'
import { loadScript } from '../viewer/lib/utils'
import JSZip from 'jszip'
import { TWEEN_DURATION } from '../viewer/lib/entities'
import Entity from '../viewer/lib/entity/Entity'
import { EntityMesh } from '../viewer/lib/entity/EntityMesh'

globalThis.THREE = THREE
//@ts-ignore
Expand Down Expand Up @@ -355,7 +354,7 @@ async function main () {
// prev = !prev
// }, 1000)

Entity.getStaticData(params.entity)
EntityMesh.getStaticData(params.entity)
// entityRotationFolder.destroy()
// entityRotationFolder = gui.addFolder('entity metadata')
// entityRotationFolder.add(params, 'entityRotate')
Expand Down
20 changes: 0 additions & 20 deletions prismarine-viewer/test/parallel.js

This file was deleted.

12 changes: 0 additions & 12 deletions prismarine-viewer/test/simple.test.js

This file was deleted.

109 changes: 0 additions & 109 deletions prismarine-viewer/test/viewer.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion prismarine-viewer/viewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module.exports = {
Viewer: require('./lib/viewer').Viewer,
WorldDataEmitter: require('./lib/worldDataEmitter').WorldDataEmitter,
MapControls: require('./lib/controls').MapControls,
Entity: require('./lib/entity/Entity'),
Entity: require('./lib/entity/EntityMesh'),
getBufferFromStream: require('./lib/simpleUtils').getBufferFromStream
}
30 changes: 21 additions & 9 deletions prismarine-viewer/viewer/lib/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const THREE = require('three')
const TWEEN = require('@tweenjs/tween.js')

const Entity = require('./entity/Entity')
const Entity = require('./entity/EntityMesh')
const { dispose3 } = require('./dispose')
const EventEmitter = require('events')
import { PlayerObject, PlayerAnimation } from 'skinview3d'
Expand All @@ -13,6 +13,7 @@ import { WalkingGeneralSwing } from './entity/animations'
import { NameTagObject } from 'skinview3d/libs/nametag'
import { flat, fromFormattedString } from '@xmcl/text-component'
import mojangson from 'mojangson'
import externalTexturesJson from './entity/externalTextures.json'

export const TWEEN_DURATION = 50 // todo should be 100

Expand Down Expand Up @@ -62,24 +63,30 @@ function getEntityMesh (entity, scene, options, overrides) {
try {
// /~https://github.com/PrismarineJS/prismarine-viewer/pull/410
const entityName = entity.name.toLowerCase()
const e = new Entity('1.16.4', entityName, scene, overrides)
const e = new Entity.EntityMesh('1.16.4', entityName, scene, overrides)

addNametag(entity, options, e.mesh)
return e.mesh
if (e.mesh) {
addNametag(entity, options, e.mesh)
return e.mesh
}
} catch (err) {
console.log(err)
reportError?.(err)
}
}

const geometry = new THREE.BoxGeometry(entity.width, entity.height, entity.width)
geometry.translate(0, entity.height / 2, 0)
const material = new THREE.MeshBasicMaterial({ color: 0xff_00_ff })
const cube = new THREE.Mesh(geometry, material)
addNametag({
username: entity.name,
height: entity.height,
}, options, cube)
return cube
}

export class Entities extends EventEmitter {
constructor(scene) {
constructor (scene) {
super()
this.scene = scene
this.entities = {}
Expand Down Expand Up @@ -257,6 +264,11 @@ export class Entities extends EventEmitter {
}

update (/** @type {import('prismarine-entity').Entity & {delete?, pos}} */entity, overrides) {
let isPlayerModel = entity.name === 'player'
if (entity.name === 'zombie' || entity.name === 'zombie_villager' || entity.name === 'husk') {
isPlayerModel = true
overrides.texture = `textures/1.16.4/entity/${entity.name === 'zombie_villager' ? 'zombie_villager/zombie_villager.png' : `zombie/${entity.name}.png`}`
}
if (!this.entities[entity.id] && !entity.delete) {
const group = new THREE.Group()
let mesh
Expand Down Expand Up @@ -313,7 +325,7 @@ export class Entities extends EventEmitter {
}
}
}
} else if (entity.name === 'player') {
} else if (isPlayerModel) {
// CREATE NEW PLAYER ENTITY
const wrapper = new THREE.Group()
/** @type {PlayerObject & { animation?: PlayerAnimation }} */
Expand Down Expand Up @@ -369,8 +381,8 @@ export class Entities extends EventEmitter {

this.emit('add', entity)

if (entity.name === 'player') {
this.updatePlayerSkin(entity.id, '', stevePng)
if (isPlayerModel) {
this.updatePlayerSkin(entity.id, '', overrides?.texture || stevePng)
}
this.setDebugMode(this.debugMode, group)
this.setVisible(this.visible, group)
Expand Down
Loading

0 comments on commit 2d3ab6c

Please sign in to comment.