texture map refactor

This commit is contained in:
austin 2024-07-30 17:31:47 -04:00
parent bfbdf5cf3e
commit 9941dd333e
12 changed files with 660 additions and 571 deletions

View File

@ -0,0 +1,35 @@
{
"textureMap": {
"Models/creatures/person2/person2_1.glb": [
{
"meshName" : "Torso.001",
"diffuse" : "/Textures/skin1.png",
"isDefault" : true
},
{
"meshName" : "Eyebrow.R",
"diffuse" : "/Textures/b1.png"
},
{
"meshName" : "Eyebrow.L",
"diffuse" : "/Textures/b1.png"
},
{
"meshName" : "Eye.R",
"diffuse" : "/Textures/w1.png"
},
{
"meshName" : "Eye.L",
"diffuse" : "/Textures/w1.png"
},
{
"meshName" : "Iris.R",
"diffuse" : "/Textures/b1.png"
},
{
"meshName" : "Iris.L",
"diffuse" : "/Textures/b1.png"
}
]
}
}

View File

@ -0,0 +1,11 @@
{
"textureMap": {
"Models/creatures/viewmodel.glb": [
{
"meshName" : "hands",
"diffuse" : "/Textures/skin1.png",
"isDefault" : true
}
]
}
}

View File

@ -1,462 +1,277 @@
{ {
"texture_map": { "textureMap": {
"Models/plane.fbx": { "Models/plane.fbx": [
"Cube": [ {
"/Textures/Ground/Dirt1.png", "meshName" : "Cube",
"/Textures/Ground/Dirt1.png" "diffuse" : "/Textures/Ground/Dirt1.png"
] }
}, ],
"Models/arcdock5deg1notex.fbx": { "Models/basic/geometry/unitsphere.glb": [
"Cube": [ {
"/Textures/w1.png", "meshName" : "Sphere",
"/Textures/w1.png" "diffuse" : "/Textures/transparent_blue.png"
] }
}, ],
"Models/wheat1.fbx": { "Models/basic/geometry/unitsphere.fbx": [
"Cube": [ {
"/Textures/wheat1.png", "meshName" : "Sphere",
"/Textures/wheat1.png" "diffuse" : "/Textures/transparent_blue.png"
] }
}, ],
"Models/wheat2.fbx": { "Models/basic/geometry/unitsphere_1.fbx": [
"Wheat": [ {
"/Textures/wheat2.png", "meshName" : "Sphere",
"/Textures/wheat2.png" "diffuse" : "/Textures/transparent_red.png"
] }
}, ],
"Models/unitsphere.fbx": { "Models/basic/geometry/unitsphere_grey.fbx": [
"Sphere": [ {
"/Textures/transparent_blue.png", "meshName" : "Sphere",
"/Textures/transparent_blue.png" "diffuse" : "/Textures/transparent_grey.png"
] }
}, ],
"Models/basic/geometry/unitsphere_1.fbx": { "Models/basic/geometry/SmallCube.fbx": [
"Sphere": [ {
"/Textures/transparent_red.png", "meshName" : "Sphere",
"/Textures/transparent_red.png" "diffuse" : "/Textures/transparent_grey.png",
] "isDefault": true
}, }
"Models/unitsphere_grey.fbx": { ],
"Sphere": [ "Models/basic/geometry/unitcapsule.glb": [
"/Textures/transparent_grey.png", {
"/Textures/transparent_grey.png" "meshName" : "Sphere",
] "diffuse" : "/Textures/transparent_grey.png",
}, "isDefault": true
"Models/katana1alt.fbx": { }
"Cube.001": [ ],
"/Textures/katana1.png", "Models/items/weapons/katana1alt.fbx": [
"/Textures/katana1.png" {
] "meshName" : "Cube.001",
}, "diffuse" : "/Textures/katana1.png"
"Models/tree1.fbx": { }
"Cube.002": [ ],
"/Textures/Branch.png", "Models/tree1.fbx": [
"/Textures/Branch.png" {
], "meshName" : "Cube.002",
"Cylinder": [ "diffuse" : "/Textures/Branch.png"
"/Textures/Branch.png", },
"/Textures/Branch.png" {
] "meshName" : "Cylinder",
}, "diffuse" : "/Textures/Branch.png"
"Models/goblin1.fbx" : { }
"makehuman1" : [ ],
"/Textures/GoblinSkin.png", "Models/goblin1.fbx" : [
"/Textures/GoblinSkin.png" {
], "meshName" : "makehuman1",
"high-poly" : [ "diffuse" : "/Textures/GoblinSkin.png",
"/Textures/GoblinEyes.png", "isDefault" : true
"/Textures/GoblinEyes.png" },
] {
}, "meshName" : "high-poly",
"Models/baseman5.glb" : { "diffuse" : "/Textures/GoblinEyes.png"
"Torso.001" : [ }
"/Textures/skin1.png", ],
"/Textures/skin1.png" "Models/elf1.fbx" : [
], {
"Hand.L" : [ "meshName" : "Torso.001",
"/Textures/skin1.png", "diffuse" : "/Textures/skin1.png",
"/Textures/skin1.png" "isDefault" : true
], },
"Forearm.L" : [ {
"/Textures/skin1.png", "meshName" : "Eyebrow.R",
"/Textures/skin1.png" "diffuse" : "/Textures/b1.png"
], },
"Bicep.L.001" : [ {
"/Textures/skin1.png", "meshName" : "Eyebrow.L",
"/Textures/skin1.png" "diffuse" : "/Textures/b1.png"
], },
"Hand.R" : [ {
"/Textures/skin1.png", "meshName" : "Eye.R",
"/Textures/skin1.png" "diffuse" : "/Textures/w1.png"
], },
"Forearm.R" : [ {
"/Textures/skin1.png", "meshName" : "Eye.L",
"/Textures/skin1.png" "diffuse" : "/Textures/w1.png"
], },
"Bicep.R.001" : [ {
"/Textures/skin1.png", "meshName" : "Iris.R",
"/Textures/skin1.png" "diffuse" : "/Textures/b1.png"
], },
"Foot.L" : [ {
"/Textures/skin1.png", "meshName" : "Iris.L",
"/Textures/skin1.png" "diffuse" : "/Textures/b1.png"
], }
"Foot.R" : [ ],
"/Textures/skin1.png", "Models/building1.fbx" : [
"/Textures/skin1.png" {
], "meshName" : "Cube.001",
"LowerLeg.L" : [ "diffuse" : "/Textures/building_diffuse.png"
"/Textures/skin1.png", }
"/Textures/skin1.png" ],
], "Models/basic/geometry/unitcylinder.fbx" : [
"LowerLeg.R" : [ {
"/Textures/skin1.png", "meshName" : "Cylinder",
"/Textures/skin1.png" "diffuse" : "/Textures/transparent_blue.png"
], }
"UpperLeg.L" : [ ],
"/Textures/skin1.png", "Models/basic/geometry/unitplane.fbx" : [
"/Textures/skin1.png" {
], "meshName" : "Plane",
"UpperLeg.R" : [ "diffuse" : "/Textures/transparent_blue.png"
"/Textures/skin1.png", }
"/Textures/skin1.png" ],
], "Models/basic/geometry/unitcube.fbx" : [
"Shorts" : [ {
"/Textures/skin1.png", "meshName" : "Cube",
"/Textures/skin1.png" "diffuse" : "/Textures/transparent_blue.png"
], }
"Shoulder.L.001" : [ ],
"/Textures/skin1.png", "Models/falloak1.fbx" : [
"/Textures/skin1.png" {
], "meshName" : "Tree",
"Shoulder.R.001" : [ "diffuse" : "/Textures/transparent_blue.png",
"/Textures/skin1.png", "isDefault" : true
"/Textures/skin1.png" }
], ],
"Neck.001" : [ "Models/deer1.fbx" : [
"/Textures/skin1.png", {
"/Textures/skin1.png" "meshName" : "Cube.001",
], "diffuse" : "/Textures/transparent_blue.png",
"Head" : [ "isDefault" : true
"/Textures/skin1.png", }
"/Textures/skin1.png" ],
], "Models/bow1.fbx" : [
"Eyebrow.R" : [ {
"/Textures/b1.png", "meshName" : "BowMesh",
"/Textures/b1.png" "diffuse" : "/Textures/bow1.png",
], "isDefault" : true
"Eyebrow.L" : [ }
"/Textures/b1.png", ],
"/Textures/b1.png" "Models/arrow1.fbx" : [
], {
"Eye.R" : [ "meshName" : "ArrowMesh",
"/Textures/w1.png", "diffuse" : "/Textures/arrow1.png",
"/Textures/w1.png" "isDefault" : true
], }
"Eye.L" : [ ],
"/Textures/w1.png", "/Models/engine/lockoncrosshair1.fbx" : [
"/Textures/w1.png" {
], "meshName" : "Cube",
"Ear.R" : [ "diffuse" : "/Textures/w1.png",
"/Textures/skin1.png", "isDefault" : true
"/Textures/skin1.png" }
], ],
"Ear.L" : [ "Models/creatures/person2/clothing/shorts1.fbx" : [
"/Textures/skin1.png", {
"/Textures/skin1.png" "meshName" : "ClothingItem",
], "diffuse" : "/Textures/shorts1.png",
"Iris.R" : [ "isDefault" : true
"/Textures/b1.png", }
"/Textures/b1.png" ],
], "Models/creatures/person2/hair/hairshort1meshed.fbx" : [
"Iris.L" : [ {
"/Textures/b1.png", "meshName" : "Hair",
"/Textures/b1.png" "diffuse" : "/Textures/b1.png",
] "isDefault" : true
}, }
"Models/elf1.fbx" : { ],
"Torso" : [ "Models/boots1.fbx" : [
"/Textures/skin1.png", {
"/Textures/skin1.png" "meshName" : "BootLeft",
], "diffuse" : "/Textures/boots1.png"
"Hand.L" : [ },
"/Textures/skin1.png", {
"/Textures/skin1.png" "meshName" : "BootRight",
], "diffuse" : "/Textures/boots1.png"
"Forearm.L" : [ }
"/Textures/skin1.png", ],
"/Textures/skin1.png" "Models/shirt1.fbx" : [
], {
"Bicep.L" : [ "meshName" : "ClothingItem",
"/Textures/skin1.png", "diffuse" : "/Textures/shirt1.png",
"/Textures/skin1.png" "isDefault" : true
], }
"Hand.R" : [ ],
"/Textures/skin1.png", "Models/environment/cloudRing.fbx" : [
"/Textures/skin1.png" {
], "meshName" : "Sphere",
"Forearm.R" : [ "diffuse" : "/Textures/cloudRing.png",
"/Textures/skin1.png", "isDefault" : true
"/Textures/skin1.png" }
], ],
"Bicep.R" : [ "Models/environment/skyboxSphere.fbx" : [
"/Textures/skin1.png", {
"/Textures/skin1.png" "meshName" : "Sphere",
], "diffuse" : "/Textures/starrySky.png",
"Foot.L" : [ "isDefault" : true
"/Textures/skin1.png", }
"/Textures/skin1.png" ],
], "Models/campfire1.fbx" : [
"Foot.R" : [ {
"/Textures/skin1.png", "meshName" : "Cylinder",
"/Textures/skin1.png" "diffuse" : "/Textures/campfire1.png",
], "isDefault" : true
"LowerLeg.L" : [ }
"/Textures/skin1.png", ],
"/Textures/skin1.png" "Models/crate2.fbx" : [
], {
"LowerLeg.R" : [ "meshName" : "Cube",
"/Textures/skin1.png", "diffuse" : "/Textures/woodplanks1.png",
"/Textures/skin1.png" "isDefault" : true
], }
"UpperLeg.L" : [ ],
"/Textures/skin1.png", "Models/shrine2.fbx" : [
"/Textures/skin1.png" {
], "meshName" : "Roof",
"UpperLeg.R" : [ "diffuse" : "/Textures/shrine2Roof.png"
"/Textures/skin1.png", },
"/Textures/skin1.png" {
], "meshName" : "MainWalls",
"Shorts" : [ "diffuse" : "/Textures/shrine2MainWalls.png"
"/Textures/skin1.png", },
"/Textures/skin1.png" {
], "meshName" : "Feet",
"Shoulder.L" : [ "diffuse" : "/Textures/shrine2Feet.png"
"/Textures/skin1.png", },
"/Textures/skin1.png" {
], "meshName" : "Platform",
"Shoulder.R" : [ "diffuse" : "/Textures/shrine2Platform.png"
"/Textures/skin1.png", },
"/Textures/skin1.png" {
], "meshName" : "SupportBeams",
"Neck" : [ "diffuse" : "/Textures/shrine2SupportBeams.png"
"/Textures/skin1.png", },
"/Textures/skin1.png" {
], "meshName" : "Stairs",
"Head" : [ "diffuse" : "/Textures/shrine2Stairs.png"
"/Textures/skin1.png", }
"/Textures/skin1.png" ],
], "Models/foliage/foliageBlockTemplate1Test1.fbx" : [
"Eyebrow.R" : [ {
"/Textures/b1.png", "meshName" : "Plane",
"/Textures/b1.png" "diffuse" : "/Textures/leaf3layer1.png",
], "isDefault" : true
"Eyebrow.L" : [ }
"/Textures/b1.png", ],
"/Textures/b1.png" "Models/proceduralTree2/proceduralTree2.fbx": [
], {
"Eye.R" : [ "meshName" : "Trunk",
"/Textures/w1.png", "diffuse" : "/Textures/proceduralTree2/Trunk.png",
"/Textures/w1.png" "isDefault" : true
], }
"Eye.L" : [ ],
"/Textures/w1.png", "Models/proceduralTree2/proceduralTree2v2.fbx": [
"/Textures/w1.png" {
], "meshName" : "Trunk",
"Iris.R" : [ "diffuse" : "/Textures/foliage/proceduralTree2/Trunk.png",
"/Textures/b1.png", "isDefault" : true
"/Textures/b1.png" }
], ],
"Iris.L" : [ "Models/foliage/grass2.fbx": [
"/Textures/b1.png", {
"/Textures/b1.png" "meshName": "Plane",
] "diffuse": "/Textures/b1.png"
}, }
"Models/building1.fbx" : { ]
"Cube.001" : [
"/Textures/building_diffuse.png",
"/Textures/building_diffuse.png"
]
},
"Models/unitcylinder.fbx" : {
"Cylinder" : [
"/Textures/transparent_blue.png",
"/Textures/transparent_blue.png"
]
},
"Models/unitplane.fbx" : {
"Plane" : [
"/Textures/transparent_blue.png",
"/Textures/transparent_blue.png"
]
},
"Models/unitcube.fbx" : {
"Cube" : [
"/Textures/transparent_blue.png",
"/Textures/transparent_blue.png"
]
},
"Models/falloak1.fbx" : {
"Tree" : [
"/Textures/falloak1.png",
"/Textures/falloak1.png"
],
"Cube.003" : [
"/Textures/falloak1.png",
"/Textures/falloak1.png"
]
},
"Models/deer1.fbx" : {
"Cube.001" : [
"/Textures/deer1.png",
"/Textures/deer1.png"
]
},
"Models/bow1.fbx" : {
"BowMesh" : [
"/Textures/bow1.png",
"/Textures/bow1.png"
]
},
"Models/arrow1.fbx" : {
"ArrowMesh" : [
"/Textures/arrow1.png",
"/Textures/arrow1.png"
]
},
"Models/engine/lockoncrosshair1.fbx" : {
"Cube" : [
"/Textures/w1.png",
"/Textures/w1.png"
]
},
"Models/creatures/person2/clothing/shorts1.fbx" : {
"ClothingItem" : [
"/Textures/shorts1.png",
"/Textures/shorts1.png"
]
},
"Models/creatures/person2/hair/hairshort1meshed.fbx" : {
"Hair" : [
"/Textures/b1.png",
"/Textures/b1.png"
]
},
"Models/boots1.fbx" : {
"BootLeft" : [
"/Textures/boots1.png",
"/Textures/boots1.png"
],
"BootRight" : [
"/Textures/boots1.png",
"/Textures/boots1.png"
]
},
"Models/shirt1.fbx" : {
"ClothingItem" : [
"/Textures/shirt1.png",
"/Textures/shirt1.png"
]
},
"Models/environment/cloudRing.fbx" : {
"Sphere" : [
"/Textures/cloudRing.png",
"/Textures/cloudRing.png"
]
},
"Models/environment/skyboxSphere.fbx" : {
"Sphere" : [
"/Textures/starrySky.png",
"/Textures/starrySky.png"
]
},
"Models/campfire1.fbx" : {
"Cylinder" : [
"/Textures/campfire1.png",
"/Textures/campfire1.png"
]
},
"Models/crate2.fbx" : {
"Cube" : [
"/Textures/woodplanks1.png",
"/Textures/woodplanks1.png"
]
},
"Models/shrine2.fbx" : {
"Roof" : [
"/Textures/shrine2Roof.png",
"/Textures/shrine2Roof.png"
],
"MainWalls" : [
"/Textures/shrine2MainWalls.png",
"/Textures/shrine2MainWalls.png"
],
"Feet" : [
"/Textures/shrine2Feet.png",
"/Textures/shrine2Feet.png"
],
"Platform" : [
"/Textures/shrine2Platform.png",
"/Textures/shrine2Platform.png"
],
"SupportBeams" : [
"/Textures/shrine2SupportBeams.png",
"/Textures/shrine2SupportBeams.png"
],
"Stairs" : [
"/Textures/shrine2Stairs.png",
"/Textures/shrine2Stairs.png"
]
},
"Models/floatingisland1.fbx" : {
"Cube" : [
"/Textures/floatingisland1.png",
"/Textures/floatingisland1.png"
]
},
"Models/testvalley.fbx" : {
"Plane.001" : [
"/Textures/grass1.png",
"/Textures/grass1.png"
]
},
"Models/f15.fbx" : {
"Cube.001" : [
"/Textures/f15.png",
"/Textures/f15.png"
]
},
"Models/skyscraper1.fbx" : {
"Cube.001" : [
"Textures/skyscraper1.png",
"Textures/skyscraper1.png"
]
},
"Models/foliage/foliageBlockTemplate1Test1.fbx" : {
"Plane" : [
"Textures/leaf3layer1.png",
"Textures/leaf3layer1.png"
],
"Plane.001" : [
"Textures/leaf3layer1.png",
"Textures/leaf3layer1.png"
],
"Plane.002" : [
"Textures/leaf3layer1.png",
"Textures/leaf3layer1.png"
]
},
"Models/proceduralTree2/proceduralTree2.fbx": {
"Trunk" : [
"Models/proceduralTree2/Trunk.png",
"Models/proceduralTree2/Trunk.png"
]
},
"Models/proceduralTree2/proceduralTree2v2.fbx": {
"Trunk" : [
"Models/foliage/proceduralTree2/Trunk.png",
"Models/foliage/proceduralTree2/Trunk.png"
]
}
} }
} }

View File

@ -13,3 +13,11 @@
fix items falling through floor fix items falling through floor
fix jump tree not applying force while movement tree is active fix jump tree not applying force while movement tree is active
Things that feel bad:
No audio
Can't instantly start/stop blocking
Short movement bursts feel jittery
Jumping client side only
First person blocking angle doesn't line up
Attack animation feels slow

View File

@ -484,6 +484,7 @@ Refactor network protocols to enforce async/sync split
(07/30/2024) (07/30/2024)
Fix depth texture for shadow rendering Fix depth texture for shadow rendering
Fix eyebrow weights on human model
# TODO # TODO
@ -538,6 +539,8 @@ Debug
Would be nice to be able to cut clients that stream their logs to my server Would be nice to be able to cut clients that stream their logs to my server
Refactor render flags
Data Cleanup Data Cleanup
- Clean up creatures - Clean up creatures
- Remove unused ones - Remove unused ones

View File

@ -406,7 +406,7 @@ public class Globals {
//timekeeper //timekeeper
timekeeper = new Timekeeper(); timekeeper = new Timekeeper();
//load in default texture map //load in default texture map
textureMapDefault = FileUtils.loadObjectFromAssetPath("Textures/default_texture_map.json", TextureMap.class); textureMapDefault = TextureMap.construct("Textures/default_texture_map.json");
//load model pretransforms //load model pretransforms
modelPretransforms = FileUtils.loadObjectFromAssetPath("Models/modelPretransforms.json", ModelPretransforms.class); modelPretransforms = FileUtils.loadObjectFromAssetPath("Models/modelPretransforms.json", ModelPretransforms.class);
modelPretransforms.init(); modelPretransforms.init();

View File

@ -14,8 +14,11 @@ import electrosphere.renderer.model.Mesh;
import electrosphere.renderer.model.Model; import electrosphere.renderer.model.Model;
import electrosphere.renderer.shader.ShaderProgram; import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.texture.Texture; import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.texture.TextureMap;
import electrosphere.server.poseactor.PoseModel; import electrosphere.server.poseactor.PoseModel;
import electrosphere.util.FileUtils;
import java.io.File;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -77,8 +80,12 @@ public class AssetManager {
for(String currentPath : modelsInQueue){ for(String currentPath : modelsInQueue){
modelsInQueue.remove(currentPath); modelsInQueue.remove(currentPath);
AIScene aiScene = ModelLoader.loadAIScene(currentPath); AIScene aiScene = ModelLoader.loadAIScene(currentPath);
TextureMap textureMap = null;
if(getLocalTextureMapPath(currentPath) != null){
textureMap = TextureMap.construct(getLocalTextureMapPath(currentPath));
}
if(aiScene != null){ if(aiScene != null){
modelsLoadedIntoMemory.put(currentPath, ModelLoader.createModelFromAiScene(aiScene,currentPath)); modelsLoadedIntoMemory.put(currentPath, ModelLoader.createModelFromAiScene(aiScene,textureMap,currentPath));
for(PhysicsMeshQueueItem physicsMeshQueueItem : physicsMeshesToLoad){ for(PhysicsMeshQueueItem physicsMeshQueueItem : physicsMeshesToLoad){
if(physicsMeshQueueItem.modelPath.contains(currentPath)){ if(physicsMeshQueueItem.modelPath.contains(currentPath)){
//create physics //create physics
@ -302,6 +309,26 @@ public class AssetManager {
public boolean hasLoadedTexture(String path){ public boolean hasLoadedTexture(String path){
return texturesLoadedIntoMemory.containsKey(path); return texturesLoadedIntoMemory.containsKey(path);
} }
/**
* Gets a local texture map's path from a model's path
* @param modelPath The model's path
*/
private String getLocalTextureMapPath(String modelPath){
File modelFile = FileUtils.getAssetFile(modelPath);
File containingDirectory = modelFile.getParentFile();
File[] children = containingDirectory.listFiles();
if(children != null){
for(File child : children){
if(child.getName().equals("texturemap.json")){
String rVal = child.getPath();
String fixed = rVal.replace(".\\assets", "");
return fixed;
}
}
}
return null;
}

View File

@ -6,12 +6,10 @@ import electrosphere.renderer.model.Material;
import electrosphere.renderer.model.Mesh; import electrosphere.renderer.model.Mesh;
import electrosphere.renderer.model.Model; import electrosphere.renderer.model.Model;
import electrosphere.renderer.texture.TextureMap; import electrosphere.renderer.texture.TextureMap;
import electrosphere.renderer.texture.TextureMap.MeshTextureData;
import electrosphere.util.FileUtils; import electrosphere.util.FileUtils;
import java.io.File; import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.lwjgl.assimp.AIScene; import org.lwjgl.assimp.AIScene;
import static org.lwjgl.assimp.Assimp.*; import static org.lwjgl.assimp.Assimp.*;
@ -44,63 +42,95 @@ public class ModelLoader {
return rVal; return rVal;
} }
public static Model createModelFromAiScene(AIScene scene, String path){ public static Model createModelFromAiScene(AIScene scene, TextureMap localTextureMap, String path){
Model rVal = null; Model rVal = null;
if(scene != null){ if(scene != null){
rVal = Model.createModelFromAiscene(path, scene); rVal = Model.createModelFromAiscene(path, scene);
attemptAddTexturesFromPathname(path, rVal); attemptAddTexturesFromPathname(path, localTextureMap, rVal);
} }
return rVal; return rVal;
} }
//TODO: this logic should exclusively use functions provided in the TextureMap class
//this way if we change the underlying structure of the TextureMap it doesn't fuck over this logic /**
static void attemptAddTexturesFromPathname(String path, Model m){ * Attempt to assign textures to meshes on this model based on texture map entries
//first we get the default texture map that's global * @param path The path to the model
TextureMap global_map = Globals.textureMapDefault; * @param localTextureMap The local texture map
LoggerInterface.loggerRenderer.DEBUG(path); * @param m The model
//then we try to get the path of our model from the map */
Map<String,List<String>> mesh_map = global_map.get_mesh_map(path); static void attemptAddTexturesFromPathname(String path, TextureMap localTextureMap, Model m){
//if it exists..
if(mesh_map != null){ LoggerInterface.loggerRenderer.DEBUG("Load textures for " + path);
//iterate through each mesh in the model that was provided as input
Iterator<Mesh> mesh_iterator = m.getMeshes().iterator(); if(Globals.textureMapDefault.containsModel(path)){
while(mesh_iterator.hasNext()){ //
Mesh current_mesh = mesh_iterator.next(); //load from global map
LoggerInterface.loggerRenderer.DEBUG(current_mesh.getMeshName()); //
//if the current iteration is contained within the mesh map we procured from above MeshTextureData defaultMeshData = Globals.textureMapDefault.getDefaultMeshTextures(path);
if(mesh_map.containsKey(current_mesh.getMeshName())){ for(Mesh mesh : m.getMeshes()){
//we create a new material, check if the diffuse or specular is not null, MeshTextureData meshTextureData = Globals.textureMapDefault.getMeshTextures(path, mesh.getMeshName());
//and if they aren't we add that path as a new texture of respective type to the material if(meshTextureData != null){
Material final_material = new Material(); setMaterial(mesh,meshTextureData);
List<String> texture_path_list = mesh_map.get(current_mesh.getMeshName()); } else if(defaultMeshData != null){
String diffuse_path = TextureMap.get_diffuse_path(texture_path_list); setMaterial(mesh,defaultMeshData);
LoggerInterface.loggerRenderer.DEBUG(current_mesh.getMeshName() + "->" + diffuse_path);
if(diffuse_path != null){
LoggerInterface.loggerRenderer.DEBUG(diffuse_path);
// Texture diffuse = new Texture(diffuse_path);
Globals.assetManager.addTexturePathtoQueue(diffuse_path);
final_material.set_diffuse(diffuse_path);
LoggerInterface.loggerRenderer.DEBUG(diffuse_path);
} else {
final_material.set_diffuse(Globals.textureDiffuseDefault);
}
String specular_path = TextureMap.get_specular_path(texture_path_list);
if(specular_path != null){
// Texture specular = new Texture(specular_path);
Globals.assetManager.addTexturePathtoQueue(specular_path);
final_material.set_specular(specular_path);
LoggerInterface.loggerRenderer.DEBUG(specular_path);
} else {
final_material.set_specular(Globals.textureSpecularDefault);
}
//once we've either added default textures or actual textures,
//set the current mesh's material to this new one
current_mesh.setMaterial(final_material);
} else { } else {
LoggerInterface.loggerRenderer.WARNING("Failed to load texture for node " + current_mesh.getMeshName() + " of model " + path); LoggerInterface.loggerRenderer.WARNING("Model " + path + " does not have texture data defined for \"" + mesh.getMeshName() + "\"");
} }
} }
} else if(localTextureMap != null && localTextureMap.containsModel(path)) {
//
//load from local folder for model
//
MeshTextureData defaultMeshData = localTextureMap.getDefaultMeshTextures(path);
for(Mesh mesh : m.getMeshes()){
MeshTextureData meshTextureData = localTextureMap.getMeshTextures(path, mesh.getMeshName());
if(meshTextureData != null){
setMaterial(mesh,meshTextureData);
} else if(defaultMeshData != null){
setMaterial(mesh,defaultMeshData);
} else {
LoggerInterface.loggerRenderer.WARNING("Model " + path + " does not have texture data defined for \"" + mesh.getMeshName() + "\"");
}
}
} else {
LoggerInterface.loggerRenderer.WARNING("Trying to get textures for model that doesn't have local or global texture map entries! " + path);
} }
} }
/**
* Sets the material for the mesh
* @param mesh The mesh
* @param meshTextureData The texture data for the mesh
*/
private static void setMaterial(Mesh mesh, MeshTextureData meshTextureData){
Material finalMat = new Material();
//set diffuse
String diffusePath = meshTextureData.getDiffuse();
LoggerInterface.loggerRenderer.DEBUG(mesh.getMeshName() + "->" + diffusePath);
if(diffusePath != null){
LoggerInterface.loggerRenderer.DEBUG(diffusePath);
// Texture diffuse = new Texture(diffuse_path);
Globals.assetManager.addTexturePathtoQueue(diffusePath);
finalMat.set_diffuse(diffusePath);
LoggerInterface.loggerRenderer.DEBUG(diffusePath);
} else {
finalMat.set_diffuse(Globals.textureDiffuseDefault);
}
//set specular
String specularPath = meshTextureData.getSpecular();
if(specularPath != null){
// Texture specular = new Texture(specular_path);
Globals.assetManager.addTexturePathtoQueue(specularPath);
finalMat.set_specular(specularPath);
LoggerInterface.loggerRenderer.DEBUG(specularPath);
} else {
finalMat.set_specular(Globals.textureSpecularDefault);
}
//once we've either added default textures or actual textures,
//set the current mesh's material to this new one
mesh.setMaterial(finalMat);
}
} }

View File

@ -83,15 +83,19 @@ public class Material {
public void apply_material(OpenGLState openGLState){ public void apply_material(OpenGLState openGLState){
//Controls whether the texturePointer should be resolved by looking up the diffuse in asset manager or using the texture pointer already set in this material //Controls whether the texturePointer should be resolved by looking up the diffuse in asset manager or using the texture pointer already set in this material
if(usesFetch){ if(usesFetch){
Texture diffuseTexture = Globals.assetManager.fetchTexture(diffuse); if(diffuse != null){
if(diffuseTexture != null){ Texture diffuseTexture = Globals.assetManager.fetchTexture(diffuse);
diffuseTexture.bind(openGLState,0); if(diffuseTexture != null){
openGLState.getActiveShader().setUniform(openGLState, "material.diffuse", 0); diffuseTexture.bind(openGLState,0);
openGLState.getActiveShader().setUniform(openGLState, "material.diffuse", 0);
}
} }
Texture specularTexture = Globals.assetManager.fetchTexture(specular); if(specular != null){
if(specularTexture != null){ Texture specularTexture = Globals.assetManager.fetchTexture(specular);
specularTexture.bind(openGLState,1); if(specularTexture != null){
openGLState.getActiveShader().setUniform(openGLState, "material.specular", 1); specularTexture.bind(openGLState,1);
openGLState.getActiveShader().setUniform(openGLState, "material.specular", 1);
}
} }
} else { } else {
openGLState.glBindTextureUnit(GL_TEXTURE0, texturePointer, GL_TEXTURE_2D); openGLState.glBindTextureUnit(GL_TEXTURE0, texturePointer, GL_TEXTURE_2D);

View File

@ -774,7 +774,7 @@ public class ShaderProgram {
public void setUniform(OpenGLState openGLState, String uniformName, Object value){ public void setUniform(OpenGLState openGLState, String uniformName, Object value){
int uniformLocation = glGetUniformLocation(this.getShaderId(), uniformName); int uniformLocation = glGetUniformLocation(this.getShaderId(), uniformName);
if(uniformLocation == INVALID_UNIFORM_NAME){ if(uniformLocation == INVALID_UNIFORM_NAME){
LoggerInterface.loggerRenderer.INFO("Searched for uniform in a shader that does not contain it. Uniform name: \"" + uniformName + "\""); LoggerInterface.loggerRenderer.DEBUG_LOOP("Searched for uniform in a shader that does not contain it. Uniform name: \"" + uniformName + "\"");
} else { } else {
setUniform(uniformLocation, value); setUniform(uniformLocation, value);
} }

View File

@ -1,64 +1,219 @@
package electrosphere.renderer.texture; package electrosphere.renderer.texture;
import java.util.ArrayList; import java.awt.IllegalComponentStateException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import electrosphere.logger.LoggerInterface;
import electrosphere.util.FileUtils;
/** /**
* A map of textures * A map of textures
*/ */
public class TextureMap { public class TextureMap {
//The convention is /**
//Map of strings (the name of a model) to a model * The map of modelPath -> list of texture map entries
//each model is a map of a string (the name of a mesh) to a list which contains */
//First the model's diffuse, then the model's specular Map<String,ModelTextureData> textureMap = new HashMap<String,ModelTextureData>();
//always in that order
//if either the diffuse or the specular isn't included then it should /**
//instead contain and empty string - "" * Reads a texture map from a given path
//this convention must be followed * @param rawMapPath The path
Map<String,Map<String,List<String>>> texture_map = new HashMap<String,Map<String,List<String>>>(); * @return The texture map
*/
public Map<String,List<String>> get_mesh_map(String name){ public static TextureMap construct(String rawMapPath){
return texture_map.get(name); TextureMapRaw rawData = FileUtils.loadObjectFromAssetPath(rawMapPath, TextureMapRaw.class);
} if(rawData == null){
public static List<String> get_mesh_textures(Map<String,List<String>> input, String name){
if(input == null){
//TODO: Add big fuckin' error here
return null; return null;
} }
return input.get(name); return TextureMap.construct(rawData);
}
/**
* Constructs a texture map from raw data
* @param rawData The raw data
* @return The texture map
*/
private static TextureMap construct(TextureMapRaw rawData){
TextureMap rVal = new TextureMap();
Map<String,List<MeshTextureData>> rawMap = rawData.getTextureMap();
Set<String> modelPaths = rawMap.keySet();
for(String modelPath : modelPaths){
ModelTextureData modelTextureData = new ModelTextureData(modelPath, rawMap.get(modelPath));
rVal.textureMap.put(modelPath,modelTextureData);
}
return rVal;
} }
//for the lazy /**
public static String get_diffuse_path(List<String> input){ * Gets the texture map entry for a mesh on a given model
if(input == null || input.size() < 2){ * @param modelPath The model's path
//TODO: Add big fuckin' error here * @param meshName The mesh's name
* @return The texture map's entry if it exists, null otherwise
*/
public MeshTextureData getMeshTextures(String modelPath, String meshName){
ModelTextureData modelTextureData = textureMap.get(modelPath);
if(modelTextureData == null){
LoggerInterface.loggerRenderer.WARNING("Trying to get texture for model that is not in texture map!");
return null; return null;
} }
return input.get(0); return modelTextureData.getMeshTextureData(meshName);
} }
//for the lazy /**
public static String get_specular_path(List<String> input){ * Gets the texture map entry for a mesh on a given model
if(input == null || input.size() < 2){ * @param modelPath The model's path
//TODO: Add big fuckin' error here * @return The texture map's entry if it exists, null otherwise
*/
public MeshTextureData getDefaultMeshTextures(String modelPath){
ModelTextureData modelTextureData = textureMap.get(modelPath);
if(modelTextureData == null){
LoggerInterface.loggerRenderer.WARNING("Trying to get texture for model that is not in texture map!");
return null; return null;
} }
return input.get(1); return modelTextureData.getDefaultMeshTextures();
} }
public TextureMap(){
texture_map = new HashMap<String,Map<String,List<String>>>(); /**
* Checks if the texture map contains the model
* @param modelPath The model's path
* @return true if the texture map contains the model, false otherwise
*/
public boolean containsModel(String modelPath){
return textureMap.containsKey(modelPath);
} }
public void add_model(String model_name){
texture_map.put(model_name, new HashMap<String, List<String>>());
/**
* Texture data for a given model
*/
static class ModelTextureData {
/**
* The map of mesh name -> texture data
*/
Map<String,MeshTextureData> meshData = new HashMap<String,MeshTextureData>();
/**
* The default data to apply
*/
MeshTextureData defaultMeshData = null;
/**
* Constructs an object to track texture data for a whole model
* @param rawMeshData The raw mesh texture data
*/
public ModelTextureData(String modelPath, List<MeshTextureData> rawMeshData){
for(MeshTextureData rawMesh: rawMeshData){
meshData.put(rawMesh.getMeshName(),rawMesh);
if(rawMesh.isDefault && this.defaultMeshData != null){
LoggerInterface.loggerEngine.ERROR(new IllegalComponentStateException("Two default meshes are defined in model " + modelPath));
} else if(rawMesh.isDefault){
this.defaultMeshData = rawMesh;
}
}
}
/**
* Gets the texture data for a given mesh
* @param meshName The name of the mesh
* @return The texture data
*/
public MeshTextureData getMeshTextureData(String meshName){
return meshData.get(meshName);
}
/**
* Gets the default mesh texture data
* @return The default mesh texture data
*/
public MeshTextureData getDefaultMeshTextures(){
return this.defaultMeshData;
}
} }
public void add_mesh_to_model(String model_name, String mesh_name){
List<String> temp = new ArrayList<String>(); /**
temp.add(""); * Data for a mesh in a given model
temp.add(""); */
texture_map.get(model_name).put(mesh_name, temp); public static class MeshTextureData {
/**
* The name of the mesh
*/
String meshName;
/**
* The specular texture's path
*/
String specular;
/**
* The diffuse texture's path
*/
String diffuse;
/**
* If this is true, this entry will be used for all meshes that don't have a defined entry
*/
boolean isDefault;
/**
* Gets the name of the mesh
* @return The name of the mesh
*/
String getMeshName(){
return meshName;
}
/**
* Gets the specular texture's path
* @return The specular texture's path
*/
public String getSpecular(){
return specular;
}
/**
* Gets the diffuse texture's path
* @return The diffuse texture's path
*/
public String getDiffuse(){
return diffuse;
}
/**
* Checks if this is the default entry or not
* @return true if is default, false otherwise
*/
public boolean isDefault(){
return isDefault;
}
}
/**
* The raw texture map data on disk
*/
static class TextureMapRaw {
/**
* Raw format on disk
*/
Map<String,List<MeshTextureData>> textureMap;
/**
* Gets the raw texture map data
* @return The raw texture map data
*/
public Map<String,List<MeshTextureData>> getTextureMap(){
return textureMap;
}
} }
} }

View File

@ -131,20 +131,21 @@ public class Utilities {
@Deprecated
public static void saveTestTextureMapToLocation(String s){ public static void saveTestTextureMapToLocation(String s){
TextureMap t = new TextureMap(); TextureMap t = new TextureMap();
t.add_model("model1"); // t.add_model("model1");
t.add_mesh_to_model("model1", "mesh1"); // t.add_mesh_to_model("model1", "mesh1");
t.add_mesh_to_model("model1", "mesh2"); // t.add_mesh_to_model("model1", "mesh2");
t.add_mesh_to_model("model1", "mesh3"); // t.add_mesh_to_model("model1", "mesh3");
t.add_model("model2"); // t.add_model("model2");
t.add_mesh_to_model("model2", "mesh1"); // t.add_mesh_to_model("model2", "mesh1");
t.add_mesh_to_model("model2", "mesh2"); // t.add_mesh_to_model("model2", "mesh2");
t.add_model("model3"); // t.add_model("model3");
t.add_mesh_to_model("model3", "mesh1"); // t.add_mesh_to_model("model3", "mesh1");
t.add_mesh_to_model("model3", "mesh2"); // t.add_mesh_to_model("model3", "mesh2");
t.add_mesh_to_model("model3", "mesh3"); // t.add_mesh_to_model("model3", "mesh3");
t.add_mesh_to_model("model3", "mesh4"); // t.add_mesh_to_model("model3", "mesh4");
Gson gson = new Gson(); Gson gson = new Gson();
try { try {
Files.write(new File(s).toPath(), gson.toJson(t).getBytes()); Files.write(new File(s).toPath(), gson.toJson(t).getBytes());