1 line
20 KiB
Plaintext
1 line
20 KiB
Plaintext
|
|
{"version":3,"file":"MD2CharacterComplex.cjs","sources":["../../src/misc/MD2CharacterComplex.js"],"sourcesContent":["import { Box3, MathUtils, MeshLambertMaterial, Object3D, TextureLoader, UVMapping } from 'three'\nimport { MD2Loader } from '../loaders/MD2Loader'\nimport { MorphBlendMesh } from '../misc/MorphBlendMesh'\n\nclass MD2CharacterComplex {\n constructor() {\n this.scale = 1\n\n // animation parameters\n\n this.animationFPS = 6\n this.transitionFrames = 15\n\n // movement model parameters\n\n this.maxSpeed = 275\n this.maxReverseSpeed = -275\n\n this.frontAcceleration = 600\n this.backAcceleration = 600\n\n this.frontDecceleration = 600\n\n this.angularSpeed = 2.5\n\n // rig\n\n this.root = new Object3D()\n\n this.meshBody = null\n this.meshWeapon = null\n\n this.controls = null\n\n // skins\n\n this.skinsBody = []\n this.skinsWeapon = []\n\n this.weapons = []\n\n this.currentSkin = undefined\n\n //\n\n this.onLoadComplete = function () {}\n\n // internals\n\n this.meshes = []\n this.animations = {}\n\n this.loadCounter = 0\n\n // internal movement control variables\n\n this.speed = 0\n this.bodyOrientation = 0\n\n this.walkSpeed = this.maxSpeed\n this.crouchSpeed = this.maxSpeed * 0.5\n\n // internal animation parameters\n\n this.activeAnimation = null\n this.oldAnimation = null\n\n // API\n }\n\n enableShadows(enable) {\n for (let i = 0; i < this.meshes.length; i++) {\n this.meshes[i].castShadow = enable\n this.meshes[i].receiveShadow = enable\n }\n }\n\n setVisible(enable) {\n for (let i = 0; i < this.meshes.length; i++) {\n this.meshes[i].visible = enable\n this.meshes[i].visible = enable\n }\n }\n\n shareParts(original) {\n this.animations = original.animations\n this.walkSpeed = original.walkSpeed\n this.crouchSpeed = original.crouchSpeed\n\n this.skinsBody = original.skinsBody\n this.skinsWeapon = original.skinsWeapon\n\n // BODY\n\n const mesh = this._createPart(original.meshBody.geometry, this.skinsBody[0])\n mesh.scale.set(this.scale, this.scale, this.scale)\n\n this.root.position.y = original.root.position.y\n this.root.add(mesh)\n\n this.meshBody = mesh\n\n this.meshes.push(mesh)\n\n // WEAPONS\n\n for (let i = 0; i < original.weapons.length; i++) {\n const meshWeapon = this._createPart(original.weapons[i].geometry, this.skinsWeapon[i])\n meshWeapon.scale.set(this.scale, this.scale, this.scale)\n meshWeapon.visible = false\n\n meshWeapon.name = original.weapons[i].name\n\n this.root.add(meshWeapon)\n\n this.weapons[i] = meshWeapon\n this.meshWeapon = meshWeapon\n\n this.meshes.push(meshWeapon)\n }\n }\n\n loadParts(config) {\n const scope = this\n\n function loadTextures(baseUrl, textureUrls) {\n const textureLoader = new TextureLoader()\n const textures = []\n\n for (let i = 0; i < textureUrls.length; i++) {\n textures[i] = textureLoader.load(baseUrl + textureUrls[i], checkLoadingComplete)\n textures[i].mapping = UVMapping\n textures[i].name = textureUrls[i]\n if ('colorSpace' in textures[i]) textures[i].colorSpace = 'srgb'\n else textures[i].encoding = 3001 // sRGBEncoding\n }\n\n return textures\n }\n\n function checkLoadingComplete() {\n scope.loadCounter -= 1\n if (scope.loadCounter === 0) scope.onLoadComplete()\n }\n\n this.animations = config.animations\n this.walkSpeed = config.walkSpeed\n this.crouchSpeed = config.crouchSpeed\n\n this.loadCounter = config.weapons.length * 2 + config.skins.length + 1\n\n const weaponsTextures = []\n for (let i = 0; i < config.weapons.length; i++) weaponsTextures[i] = config.weapons[i][1]\n\n // SKINS\n\n this.skinsBody = loadTextures(config.baseUrl + 'skins/', config.skins)\n this.skinsWeapon = loadTextures(config.baseUrl + 'skins/', weaponsTextures)\n\n // BODY\n\n const loader = new MD2Loader()\n\n loader.lo
|