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

View File

@ -13,3 +13,11 @@
fix items falling through floor
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)
Fix depth texture for shadow rendering
Fix eyebrow weights on human model
# TODO
@ -538,6 +539,8 @@ Debug
Would be nice to be able to cut clients that stream their logs to my server
Refactor render flags
Data Cleanup
- Clean up creatures
- Remove unused ones

View File

@ -406,7 +406,7 @@ public class Globals {
//timekeeper
timekeeper = new Timekeeper();
//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
modelPretransforms = FileUtils.loadObjectFromAssetPath("Models/modelPretransforms.json", ModelPretransforms.class);
modelPretransforms.init();

View File

@ -14,8 +14,11 @@ import electrosphere.renderer.model.Mesh;
import electrosphere.renderer.model.Model;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.texture.TextureMap;
import electrosphere.server.poseactor.PoseModel;
import electrosphere.util.FileUtils;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -77,8 +80,12 @@ public class AssetManager {
for(String currentPath : modelsInQueue){
modelsInQueue.remove(currentPath);
AIScene aiScene = ModelLoader.loadAIScene(currentPath);
TextureMap textureMap = null;
if(getLocalTextureMapPath(currentPath) != null){
textureMap = TextureMap.construct(getLocalTextureMapPath(currentPath));
}
if(aiScene != null){
modelsLoadedIntoMemory.put(currentPath, ModelLoader.createModelFromAiScene(aiScene,currentPath));
modelsLoadedIntoMemory.put(currentPath, ModelLoader.createModelFromAiScene(aiScene,textureMap,currentPath));
for(PhysicsMeshQueueItem physicsMeshQueueItem : physicsMeshesToLoad){
if(physicsMeshQueueItem.modelPath.contains(currentPath)){
//create physics
@ -303,6 +310,26 @@ public class AssetManager {
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.Model;
import electrosphere.renderer.texture.TextureMap;
import electrosphere.renderer.texture.TextureMap.MeshTextureData;
import electrosphere.util.FileUtils;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.lwjgl.assimp.AIScene;
import static org.lwjgl.assimp.Assimp.*;
@ -44,63 +42,95 @@ public class ModelLoader {
return rVal;
}
public static Model createModelFromAiScene(AIScene scene, String path){
public static Model createModelFromAiScene(AIScene scene, TextureMap localTextureMap, String path){
Model rVal = null;
if(scene != null){
rVal = Model.createModelFromAiscene(path, scene);
attemptAddTexturesFromPathname(path, rVal);
attemptAddTexturesFromPathname(path, localTextureMap, 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){
//first we get the default texture map that's global
TextureMap global_map = Globals.textureMapDefault;
LoggerInterface.loggerRenderer.DEBUG(path);
//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);
//if it exists..
if(mesh_map != null){
//iterate through each mesh in the model that was provided as input
Iterator<Mesh> mesh_iterator = m.getMeshes().iterator();
while(mesh_iterator.hasNext()){
Mesh current_mesh = mesh_iterator.next();
LoggerInterface.loggerRenderer.DEBUG(current_mesh.getMeshName());
//if the current iteration is contained within the mesh map we procured from above
if(mesh_map.containsKey(current_mesh.getMeshName())){
//we create a new material, check if the diffuse or specular is not null,
//and if they aren't we add that path as a new texture of respective type to the material
Material final_material = new Material();
List<String> texture_path_list = mesh_map.get(current_mesh.getMeshName());
String diffuse_path = TextureMap.get_diffuse_path(texture_path_list);
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);
/**
* Attempt to assign textures to meshes on this model based on texture map entries
* @param path The path to the model
* @param localTextureMap The local texture map
* @param m The model
*/
static void attemptAddTexturesFromPathname(String path, TextureMap localTextureMap, Model m){
LoggerInterface.loggerRenderer.DEBUG("Load textures for " + path);
if(Globals.textureMapDefault.containsModel(path)){
//
//load from global map
//
MeshTextureData defaultMeshData = Globals.textureMapDefault.getDefaultMeshTextures(path);
for(Mesh mesh : m.getMeshes()){
MeshTextureData meshTextureData = Globals.textureMapDefault.getMeshTextures(path, mesh.getMeshName());
if(meshTextureData != null){
setMaterial(mesh,meshTextureData);
} else if(defaultMeshData != null){
setMaterial(mesh,defaultMeshData);
} else {
final_material.set_diffuse(Globals.textureDiffuseDefault);
LoggerInterface.loggerRenderer.WARNING("Model " + path + " does not have texture data defined for \"" + mesh.getMeshName() + "\"");
}
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 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 {
final_material.set_specular(Globals.textureSpecularDefault);
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
current_mesh.setMaterial(final_material);
} else {
LoggerInterface.loggerRenderer.WARNING("Failed to load texture for node " + current_mesh.getMeshName() + " of model " + path);
}
}
}
mesh.setMaterial(finalMat);
}
}

View File

@ -83,16 +83,20 @@ public class Material {
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
if(usesFetch){
if(diffuse != null){
Texture diffuseTexture = Globals.assetManager.fetchTexture(diffuse);
if(diffuseTexture != null){
diffuseTexture.bind(openGLState,0);
openGLState.getActiveShader().setUniform(openGLState, "material.diffuse", 0);
}
}
if(specular != null){
Texture specularTexture = Globals.assetManager.fetchTexture(specular);
if(specularTexture != null){
specularTexture.bind(openGLState,1);
openGLState.getActiveShader().setUniform(openGLState, "material.specular", 1);
}
}
} else {
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){
int uniformLocation = glGetUniformLocation(this.getShaderId(), uniformName);
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 {
setUniform(uniformLocation, value);
}

View File

@ -1,64 +1,219 @@
package electrosphere.renderer.texture;
import java.util.ArrayList;
import java.awt.IllegalComponentStateException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import electrosphere.logger.LoggerInterface;
import electrosphere.util.FileUtils;
/**
* A map of textures
*/
public class TextureMap {
//The convention is
//Map of strings (the name of a model) to a model
//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
//always in that order
//if either the diffuse or the specular isn't included then it should
//instead contain and empty string - ""
//this convention must be followed
Map<String,Map<String,List<String>>> texture_map = new HashMap<String,Map<String,List<String>>>();
/**
* The map of modelPath -> list of texture map entries
*/
Map<String,ModelTextureData> textureMap = new HashMap<String,ModelTextureData>();
public Map<String,List<String>> get_mesh_map(String name){
return texture_map.get(name);
}
public static List<String> get_mesh_textures(Map<String,List<String>> input, String name){
if(input == null){
//TODO: Add big fuckin' error here
/**
* Reads a texture map from a given path
* @param rawMapPath The path
* @return The texture map
*/
public static TextureMap construct(String rawMapPath){
TextureMapRaw rawData = FileUtils.loadObjectFromAssetPath(rawMapPath, TextureMapRaw.class);
if(rawData == null){
return null;
}
return input.get(name);
return TextureMap.construct(rawData);
}
//for the lazy
public static String get_diffuse_path(List<String> input){
if(input == null || input.size() < 2){
//TODO: Add big fuckin' error here
/**
* 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;
}
/**
* Gets the texture map entry for a mesh on a given model
* @param modelPath The model's path
* @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 input.get(0);
return modelTextureData.getMeshTextureData(meshName);
}
//for the lazy
public static String get_specular_path(List<String> input){
if(input == null || input.size() < 2){
//TODO: Add big fuckin' error here
/**
* Gets the texture map entry for a mesh on a given model
* @param modelPath The model's path
* @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 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;
}
public void add_mesh_to_model(String model_name, String mesh_name){
List<String> temp = new ArrayList<String>();
temp.add("");
temp.add("");
texture_map.get(model_name).put(mesh_name, temp);
}
}
/**
* 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;
}
}
/**
* Data for a mesh in a given model
*/
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){
TextureMap t = new TextureMap();
t.add_model("model1");
t.add_mesh_to_model("model1", "mesh1");
t.add_mesh_to_model("model1", "mesh2");
t.add_mesh_to_model("model1", "mesh3");
t.add_model("model2");
t.add_mesh_to_model("model2", "mesh1");
t.add_mesh_to_model("model2", "mesh2");
t.add_model("model3");
t.add_mesh_to_model("model3", "mesh1");
t.add_mesh_to_model("model3", "mesh2");
t.add_mesh_to_model("model3", "mesh3");
t.add_mesh_to_model("model3", "mesh4");
// t.add_model("model1");
// t.add_mesh_to_model("model1", "mesh1");
// t.add_mesh_to_model("model1", "mesh2");
// t.add_mesh_to_model("model1", "mesh3");
// t.add_model("model2");
// t.add_mesh_to_model("model2", "mesh1");
// t.add_mesh_to_model("model2", "mesh2");
// t.add_model("model3");
// t.add_mesh_to_model("model3", "mesh1");
// t.add_mesh_to_model("model3", "mesh2");
// t.add_mesh_to_model("model3", "mesh3");
// t.add_mesh_to_model("model3", "mesh4");
Gson gson = new Gson();
try {
Files.write(new File(s).toPath(), gson.toJson(t).getBytes());