Skip to content

Commit

Permalink
load model textures
Browse files Browse the repository at this point in the history
  • Loading branch information
solvedDev committed Apr 10, 2020
1 parent 10fb9aa commit 827ec40
Show file tree
Hide file tree
Showing 242 changed files with 59 additions and 25 deletions.
6 changes: 1 addition & 5 deletions src/renderer/scripts/editor/Model/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import {
GridHelper,
} from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { join } from 'path'
import { loadModels, IModelSchema } from './loadModel'
import { readJSON } from '../../Utilities/JsonFS'
import { loadAllTextures, ITextureData } from './loadTextures'
import { CURRENT } from '../../constants'

export interface IModelOptions {
fov?: number
Expand Down Expand Up @@ -82,9 +80,7 @@ export async function createModelEditor(
let allTextureData = await loadAllTextures(identifiers)
identifiers.forEach((id, i) => {
allTextureData[id].forEach((texData, j) => {
texData.texture.data = loader.load(
texData.texture.file_path
)
texData.texture.data = loader.load(texData.texture.file_path)
texData.material = materials[i]

if (j === 0) {
Expand Down
76 changes: 56 additions & 20 deletions src/renderer/scripts/editor/Model/loadTextures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { readJSON } from '../../Utilities/JsonFS'
import { Texture, MeshLambertMaterial } from 'three'
import { CURRENT } from '../../constants'
import { join } from 'path'
import { promises as fs, existsSync } from "fs"
declare const __static: string;
import { promises as fs, existsSync } from 'fs'
declare const __static: string

export interface ITextureData {
texture: {
Expand All @@ -21,31 +21,64 @@ export async function loadAllTextures(identifiers: string[]) {
identifiers.map(async id => {
res[id] = await loadTextures(id)
console.log(await guessTexture(id))
if(res[id].length === 0) res[id] = await guessTexture(id)
if (res[id].length === 0) res[id] = await guessTexture(id)
})
)

return res
}


const GUESS_DATA = () => [[CURRENT.RP_PATH, '.png'], [join(__static, "vanilla/RP"), '.png']]
const GUESS_DATA = () => [
[CURRENT.RP_PATH, '.png'],
[join(__static, 'vanilla/RP'), '.png'],
]
async function guessTexture(identifier: string) {
return (await Promise.all(GUESS_DATA().map(async ([base, ext]) => {
let try_folder = join(base, 'textures/entity', identifier.split(":").pop().split(".")[1])
try {
let entries = await fs.readdir(try_folder)
return entries.map(en => ({ texture: { file_path: join(try_folder, en + ext), name: 'Unknown' } }))
} catch(e) {
console.log(try_folder + ext, e)
return {
texture: {
name: 'Unknown',
file_path: try_folder + ext
return (
await Promise.all(
GUESS_DATA().map(async ([base, ext]) => {
let try_folder = join(
base,
'textures/entity',
identifier
.split(':')
.pop()
.split('.')[1]
)

try {
let entries = await fs.readdir(try_folder)
return await Promise.all(
entries.map(async en => {
if (
(
await fs.lstat(join(try_folder, en))
).isDirectory()
)
return

return {
texture: {
name: 'Unknown',
file_path: join(try_folder, en),
},
}
})
)
} catch (e) {
return {
texture: {
name: 'Unknown',
file_path: try_folder + ext,
},
}
}
}
}
}))).flat().filter(entry => entry !== undefined && existsSync(entry.texture.file_path))
})
)
)
.flat()
.filter(
entry => entry !== undefined && existsSync(entry.texture.file_path)
)
}

export async function loadTextures(identifier: string) {
Expand Down Expand Up @@ -73,7 +106,10 @@ export async function loadTextures(identifier: string) {
data.push({
texture: {
name: key,
file_path: join(CURRENT.RP_PATH, val.endsWith('.png') ? val : val + '.png'),
file_path: join(
CURRENT.RP_PATH,
val.endsWith('.png') ? val : val + '.png'
),
},
})
})
Expand Down
2 changes: 2 additions & 0 deletions static/vanilla/RP/models/entity/horse_v2.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"geometry.horse.v2": {
"visible_bounds_width": 2,
"visible_bounds_height": 3,
"texturewidth": 128,
"textureheight": 128,
"visible_bounds_offset": [ 0, 1, 0 ],
"bones": [
{
Expand Down
Binary file modified static/vanilla/RP/textures/entity/agent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/alex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/armor_stand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/arrows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/beacon_beam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/brown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/cyan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/light_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/lime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/magenta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/pink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/purple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/silver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/bed/yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/vanilla/RP/textures/entity/bee/bee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/vanilla/RP/textures/entity/bee/bee_angry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/vanilla/RP/textures/entity/boat/boat_acacia.png
Binary file modified static/vanilla/RP/textures/entity/boat/boat_birch.png
Binary file modified static/vanilla/RP/textures/entity/boat/boat_darkoak.png
Binary file modified static/vanilla/RP/textures/entity/boat/boat_jungle.png
Binary file modified static/vanilla/RP/textures/entity/boat/boat_oak.png
Binary file modified static/vanilla/RP/textures/entity/boat/boat_spruce.png
Binary file modified static/vanilla/RP/textures/entity/camera_tripod.png
Binary file modified static/vanilla/RP/textures/entity/cape_invisible.png
Binary file modified static/vanilla/RP/textures/entity/cat/blackcat.png
Binary file modified static/vanilla/RP/textures/entity/cat/calico.png
Binary file modified static/vanilla/RP/textures/entity/cat/ocelot.png
Binary file modified static/vanilla/RP/textures/entity/cat/red.png
Binary file modified static/vanilla/RP/textures/entity/cat/siamese.png
Binary file modified static/vanilla/RP/textures/entity/cat/tuxedo.png
Binary file modified static/vanilla/RP/textures/entity/chest/double_normal.png
Binary file modified static/vanilla/RP/textures/entity/chest/ender.png
Binary file modified static/vanilla/RP/textures/entity/chest/normal.png
Binary file modified static/vanilla/RP/textures/entity/chest/trapped.png
Binary file modified static/vanilla/RP/textures/entity/chest/trapped_double.png
Binary file modified static/vanilla/RP/textures/entity/chicken.png
Binary file modified static/vanilla/RP/textures/entity/cow/cow.png
Binary file modified static/vanilla/RP/textures/entity/cow/mooshroom.png
Binary file modified static/vanilla/RP/textures/entity/creeper/creeper.png
Binary file modified static/vanilla/RP/textures/entity/creeper/creeper_armor.png
Binary file modified static/vanilla/RP/textures/entity/dolphin.png
Binary file modified static/vanilla/RP/textures/entity/dragon/dragon_exploding.png
Binary file modified static/vanilla/RP/textures/entity/dragon/dragon_eyes.png
Binary file modified static/vanilla/RP/textures/entity/dummy.png
Binary file modified static/vanilla/RP/textures/entity/enchanting_table_book.png
Binary file modified static/vanilla/RP/textures/entity/end_portal.png
Binary file modified static/vanilla/RP/textures/entity/endercrystal/endercrystal.png
Binary file modified static/vanilla/RP/textures/entity/endermite.png
Binary file modified static/vanilla/RP/textures/entity/experience_orb.png
Binary file modified static/vanilla/RP/textures/entity/fireworks.png
Binary file modified static/vanilla/RP/textures/entity/fish/clownfish.png
Binary file modified static/vanilla/RP/textures/entity/fish/cod.png
Binary file modified static/vanilla/RP/textures/entity/fish/fish.png
Binary file modified static/vanilla/RP/textures/entity/fish/pufferfish.png
Binary file modified static/vanilla/RP/textures/entity/fish/salmon.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_a.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_a_pattern_1.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_a_pattern_2.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_a_pattern_3.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_a_pattern_4.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_a_pattern_5.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_a_pattern_6.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_b.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_b_pattern_1.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_b_pattern_2.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_b_pattern_3.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_b_pattern_4.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_b_pattern_5.png
Binary file modified static/vanilla/RP/textures/entity/fish/tropical_b_pattern_6.png
Binary file modified static/vanilla/RP/textures/entity/fox/arctic_fox.png
Binary file modified static/vanilla/RP/textures/entity/fox/fox.png
Binary file modified static/vanilla/RP/textures/entity/ghast/ghast.png
Binary file modified static/vanilla/RP/textures/entity/guardian.png
Binary file modified static/vanilla/RP/textures/entity/guardian_beam.png
Binary file modified static/vanilla/RP/textures/entity/guardian_elder.png
Binary file modified static/vanilla/RP/textures/entity/horse2/donkey.png
Binary file modified static/vanilla/RP/textures/entity/horse2/horse_black.png
Binary file modified static/vanilla/RP/textures/entity/horse2/horse_brown.png
Binary file modified static/vanilla/RP/textures/entity/horse2/horse_chestnut.png
Binary file modified static/vanilla/RP/textures/entity/horse2/horse_creamy.png
Binary file modified static/vanilla/RP/textures/entity/horse2/horse_darkbrown.png
Binary file modified static/vanilla/RP/textures/entity/horse2/horse_gray.png
Binary file modified static/vanilla/RP/textures/entity/horse2/horse_skeleton.png
Binary file modified static/vanilla/RP/textures/entity/horse2/horse_white.png
Binary file modified static/vanilla/RP/textures/entity/horse2/horse_zombie.png
Binary file modified static/vanilla/RP/textures/entity/horse2/mule.png
Binary file modified static/vanilla/RP/textures/entity/illager/evoker.png
Binary file modified static/vanilla/RP/textures/entity/illager/fangs.png
Binary file modified static/vanilla/RP/textures/entity/iron_golem.png
Binary file modified static/vanilla/RP/textures/entity/lead_knot.png
Binary file modified static/vanilla/RP/textures/entity/lead_rope.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_black.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_blue.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_brown.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_cyan.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_gray.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_green.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_lime.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_magenta.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_orange.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_pink.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_purple.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_red.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_silver.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_white.png
Binary file modified static/vanilla/RP/textures/entity/llama/decor/decor_yellow.png
Binary file modified static/vanilla/RP/textures/entity/llama/llama.png
Binary file modified static/vanilla/RP/textures/entity/llama/llama_brown.png
Binary file modified static/vanilla/RP/textures/entity/llama/llama_creamy.png
Binary file modified static/vanilla/RP/textures/entity/llama/llama_gray.png
Binary file modified static/vanilla/RP/textures/entity/llama/llama_white.png
Binary file modified static/vanilla/RP/textures/entity/llama/spit.png
Binary file modified static/vanilla/RP/textures/entity/loyalty_rope.png
Binary file modified static/vanilla/RP/textures/entity/minecart.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_1.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_10.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_2.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_3.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_4.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_5.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_6.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_7.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_8.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_9.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_1.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_10.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_2.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_3.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_4.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_5.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_6.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_7.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_8.png
Binary file modified static/vanilla/RP/textures/entity/npc/npc_scientist_9.png
Binary file modified static/vanilla/RP/textures/entity/parrot/parrot_blue.png
Binary file modified static/vanilla/RP/textures/entity/parrot/parrot_green.png
Binary file modified static/vanilla/RP/textures/entity/parrot/parrot_grey.png
Binary file modified static/vanilla/RP/textures/entity/parrot/parrot_red_blue.png
Binary file modified static/vanilla/RP/textures/entity/parrot/parrot_yellow_blue.png
Binary file modified static/vanilla/RP/textures/entity/pig/pig.png
Binary file modified static/vanilla/RP/textures/entity/pig/pig_saddle.png
Binary file modified static/vanilla/RP/textures/entity/pig/pigzombie.png
Binary file modified static/vanilla/RP/textures/entity/pistonarm/pistonArm.png
Binary file modified static/vanilla/RP/textures/entity/pistonarm/pistonArmSticky.png
Binary file modified static/vanilla/RP/textures/entity/polarbear.png
Binary file modified static/vanilla/RP/textures/entity/rabbit/blackrabbit.png
Binary file modified static/vanilla/RP/textures/entity/rabbit/brown.png
Binary file modified static/vanilla/RP/textures/entity/rabbit/gold.png
Binary file modified static/vanilla/RP/textures/entity/rabbit/salt.png
Binary file modified static/vanilla/RP/textures/entity/rabbit/toast.png
Binary file modified static/vanilla/RP/textures/entity/rabbit/white.png
Binary file modified static/vanilla/RP/textures/entity/rabbit/white_splotched.png
Binary file modified static/vanilla/RP/textures/entity/saddle.png
Binary file modified static/vanilla/RP/textures/entity/sea_turtle.png
Binary file modified static/vanilla/RP/textures/entity/shield.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_black.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_blue.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_brown.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_cyan.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_gray.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_green.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_light_blue.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_lime.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_magenta.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_orange.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_pink.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_purple.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_red.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_silver.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_undyed.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_white.png
Binary file modified static/vanilla/RP/textures/entity/shulker/shulker_yellow.png
Binary file modified static/vanilla/RP/textures/entity/shulker/spark.png
Binary file modified static/vanilla/RP/textures/entity/sign.png
Binary file modified static/vanilla/RP/textures/entity/silverfish.png
Binary file modified static/vanilla/RP/textures/entity/skeleton/skeleton.png
Binary file modified static/vanilla/RP/textures/entity/skeleton/stray.png
Binary file modified static/vanilla/RP/textures/entity/skeleton/stray_overlay.png
Binary file modified static/vanilla/RP/textures/entity/skeleton/wither_skeleton.png
Binary file modified static/vanilla/RP/textures/entity/skulls/creeper.png
Binary file modified static/vanilla/RP/textures/entity/skulls/skeleton.png
Binary file modified static/vanilla/RP/textures/entity/skulls/wither_skeleton.png
Binary file modified static/vanilla/RP/textures/entity/skulls/zombie.png
Binary file modified static/vanilla/RP/textures/entity/slime/slime.png
Binary file modified static/vanilla/RP/textures/entity/snow_golem.png
Binary file modified static/vanilla/RP/textures/entity/squid.png
Binary file modified static/vanilla/RP/textures/entity/steve.png
Binary file modified static/vanilla/RP/textures/entity/trident_riptide.png
Binary file modified static/vanilla/RP/textures/entity/vex/vex.png
Binary file modified static/vanilla/RP/textures/entity/vex/vex_charging.png
Binary file modified static/vanilla/RP/textures/entity/vindicator.png
Binary file modified static/vanilla/RP/textures/entity/witch.png
Binary file modified static/vanilla/RP/textures/entity/wither_boss/wither.png
Binary file modified static/vanilla/RP/textures/entity/wolf/wolf.png
Binary file modified static/vanilla/RP/textures/entity/wolf/wolf_angry.png
Binary file modified static/vanilla/RP/textures/entity/zombie/husk.png
Binary file modified static/vanilla/RP/textures/entity/zombie/zombie.png

0 comments on commit 827ec40

Please sign in to comment.