clean up material class a bit
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-04-29 19:36:46 -04:00
parent 7f557d40c0
commit 76e0073177
10 changed files with 79 additions and 46 deletions

View File

@ -1600,6 +1600,7 @@ NoiseVoxelGen work to make elevation values align with voxel values that are gen
Non-procedural voxel generation fix Non-procedural voxel generation fix
Flower foliage item Flower foliage item
Texture loading from model files (ie can load texture path from model file) Texture loading from model files (ie can load texture path from model file)
Clean up material class a bit

View File

@ -662,8 +662,8 @@ public class Globals {
//create default material //create default material
materialDefault = new Material(); materialDefault = new Material();
materialDefault.set_diffuse(AssetDataStrings.TEXTURE_DEFAULT); materialDefault.setDiffuse(AssetDataStrings.TEXTURE_DEFAULT);
materialDefault.set_specular(AssetDataStrings.TEXTURE_DEFAULT); materialDefault.setSpecular(AssetDataStrings.TEXTURE_DEFAULT);
//create font manager //create font manager
fontManager = new FontManager(); fontManager = new FontManager();

View File

@ -389,7 +389,7 @@ public class RenderUtils {
//setup extra structures //setup extra structures
Material mat = new Material(); Material mat = new Material();
mat.set_diffuse(AssetDataStrings.TEXTURE_TEAL_TRANSPARENT); mat.setDiffuse(AssetDataStrings.TEXTURE_TEAL_TRANSPARENT);
sphereMesh.setMaterial(mat); sphereMesh.setMaterial(mat);
sphereMesh.setShader(VisualShader.smartAssembleShader(false, true)); sphereMesh.setShader(VisualShader.smartAssembleShader(false, true));
GL40.glBindVertexArray(0); GL40.glBindVertexArray(0);
@ -444,7 +444,7 @@ public class RenderUtils {
//setup extra structures //setup extra structures
Material mat = new Material(); Material mat = new Material();
mat.set_diffuse(AssetDataStrings.TEXTURE_TEAL_TRANSPARENT); mat.setDiffuse(AssetDataStrings.TEXTURE_TEAL_TRANSPARENT);
sphereMesh.setMaterial(mat); sphereMesh.setMaterial(mat);
sphereMesh.setShader(VisualShader.smartAssembleShader(false, true)); sphereMesh.setShader(VisualShader.smartAssembleShader(false, true));
GL40.glBindVertexArray(0); GL40.glBindVertexArray(0);
@ -531,7 +531,7 @@ public class RenderUtils {
//setup extra structures //setup extra structures
Material mat = new Material(); Material mat = new Material();
mat.set_diffuse(AssetDataStrings.TEXTURE_TEAL_TRANSPARENT); mat.setDiffuse(AssetDataStrings.TEXTURE_TEAL_TRANSPARENT);
sphereMesh.setMaterial(mat); sphereMesh.setMaterial(mat);
sphereMesh.setShader(VisualShader.smartAssembleShader(false, true)); sphereMesh.setShader(VisualShader.smartAssembleShader(false, true));
GL40.glBindVertexArray(0); GL40.glBindVertexArray(0);
@ -618,7 +618,7 @@ public class RenderUtils {
//setup extra structures //setup extra structures
Material mat = new Material(); Material mat = new Material();
mat.set_diffuse(AssetDataStrings.TEXTURE_BLOCK_ATLAS); mat.setDiffuse(AssetDataStrings.TEXTURE_BLOCK_ATLAS);
cubeMesh.setMaterial(mat); cubeMesh.setMaterial(mat);
cubeMesh.setShader(VisualShader.loadSpecificShader(AssetDataStrings.SHADER_BLOCK_SINGLE_VERT, AssetDataStrings.SHADER_BLOCK_SINGLE_FRAG)); cubeMesh.setShader(VisualShader.loadSpecificShader(AssetDataStrings.SHADER_BLOCK_SINGLE_VERT, AssetDataStrings.SHADER_BLOCK_SINGLE_FRAG));
GL40.glBindVertexArray(0); GL40.glBindVertexArray(0);
@ -709,8 +709,8 @@ public class RenderUtils {
Material uiMat = new Material(); Material uiMat = new Material();
Globals.assetManager.addTexturePathtoQueue("/Textures/Fonts/myfont1-harsher.png"); Globals.assetManager.addTexturePathtoQueue("/Textures/Fonts/myfont1-harsher.png");
uiMat.set_diffuse("/Textures/Fonts/myfont1-harsher.png"); uiMat.setDiffuse("/Textures/Fonts/myfont1-harsher.png");
uiMat.set_specular("/Textures/Fonts/myfont1-harsher.png"); uiMat.setSpecular("/Textures/Fonts/myfont1-harsher.png");
m.setMaterial(uiMat); m.setMaterial(uiMat);
rVal.getMaterials().add(uiMat); rVal.getMaterials().add(uiMat);
@ -1060,8 +1060,8 @@ public class RenderUtils {
Material groundMat = new Material(); Material groundMat = new Material();
Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png"); Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png");
groundMat.set_diffuse("/Textures/Ground/Dirt1.png"); groundMat.setDiffuse("/Textures/Ground/Dirt1.png");
groundMat.set_specular("/Textures/Ground/Dirt1.png"); groundMat.setSpecular("/Textures/Ground/Dirt1.png");
m.setMaterial(groundMat); m.setMaterial(groundMat);
rVal.getMeshes().add(m); rVal.getMeshes().add(m);
@ -1616,8 +1616,8 @@ public class RenderUtils {
Material groundMat = new Material(); Material groundMat = new Material();
Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png"); Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png");
groundMat.set_diffuse("/Textures/Ground/Dirt1.png"); groundMat.setDiffuse("/Textures/Ground/Dirt1.png");
groundMat.set_specular("/Textures/Ground/Dirt1.png"); groundMat.setSpecular("/Textures/Ground/Dirt1.png");
m.setMaterial(groundMat); m.setMaterial(groundMat);
rVal.getMeshes().add(m); rVal.getMeshes().add(m);

View File

@ -118,20 +118,20 @@ public class ModelLoader {
if(diffusePath != null){ if(diffusePath != null){
LoggerInterface.loggerRenderer.DEBUG(diffusePath); LoggerInterface.loggerRenderer.DEBUG(diffusePath);
Globals.assetManager.addTexturePathtoQueue(diffusePath); Globals.assetManager.addTexturePathtoQueue(diffusePath);
finalMat.set_diffuse(diffusePath); finalMat.setDiffuse(diffusePath);
LoggerInterface.loggerRenderer.DEBUG(diffusePath); LoggerInterface.loggerRenderer.DEBUG(diffusePath);
} else { } else {
finalMat.set_diffuse(Globals.textureDiffuseDefault); finalMat.setDiffuse(Globals.textureDiffuseDefault);
} }
//set specular //set specular
String specularPath = meshTextureData.getSpecular(); String specularPath = meshTextureData.getSpecular();
if(specularPath != null){ if(specularPath != null){
Globals.assetManager.addTexturePathtoQueue(specularPath); Globals.assetManager.addTexturePathtoQueue(specularPath);
finalMat.set_specular(specularPath); finalMat.setSpecular(specularPath);
LoggerInterface.loggerRenderer.DEBUG(specularPath); LoggerInterface.loggerRenderer.DEBUG(specularPath);
} else { } else {
finalMat.set_specular(Globals.textureSpecularDefault); finalMat.setSpecular(Globals.textureSpecularDefault);
} }
//once we've either added default textures or actual textures, //once we've either added default textures or actual textures,
//set the current mesh's material to this new one //set the current mesh's material to this new one

View File

@ -793,8 +793,8 @@ public class FluidChunkModelGeneration {
Material groundMat = new Material(); Material groundMat = new Material();
groundMat.set_diffuse("/Textures/Ground/Dirt1.png"); groundMat.setDiffuse("/Textures/Ground/Dirt1.png");
groundMat.set_specular("/Textures/Ground/Dirt1.png"); groundMat.setSpecular("/Textures/Ground/Dirt1.png");
Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png"); Globals.assetManager.addTexturePathtoQueue("/Textures/Ground/Dirt1.png");
m.setMaterial(groundMat); m.setMaterial(groundMat);

View File

@ -26,17 +26,36 @@ import java.nio.file.Path;
*/ */
public class Material { public class Material {
/**
* The path of the diffuse texture when using texture lookups
*/
String diffuse; String diffuse;
/**
* The path of the specular texture when using texture lookups
*/
String specular; String specular;
/**
* Tracks whether this material has transparency or not
*/
boolean hasTransparency = false; boolean hasTransparency = false;
//Sets whether this material should get its texture pointers from the assetManager by looking up diffuse and specular paths /**
//or whether it should have a manually set texturePointer and not look up while binding * Sets whether this material should get its texture pointers from the assetManager by looking up diffuse and specular paths
* or whether it should have a manually set texturePointer and not look up while binding
*/
boolean usesFetch = true; boolean usesFetch = true;
//texture pointer for the specular /**
* texture pointer for the specular
*/
int texturePointer; int texturePointer;
//texture pointer for the normal
/**
* texture pointer for the normal
*/
int normalPointer; int normalPointer;
/** /**
@ -60,7 +79,7 @@ public class Material {
* @param input The input ai material * @param input The input ai material
* @return The resulting engine material * @return The resulting engine material
*/ */
public static Material load_material_from_aimaterial(String path, AIScene scene, AIMaterial input){ public static Material loadMaterialFromAIMaterial(String path, AIScene scene, AIMaterial input){
Material rVal = new Material(); Material rVal = new Material();
AIString aiPathString = AIString.calloc(); AIString aiPathString = AIString.calloc();
@ -101,7 +120,12 @@ public class Material {
Globals.assetManager.addTexturePathtoQueue(rVal.diffuse); Globals.assetManager.addTexturePathtoQueue(rVal.diffuse);
} }
} else { } else {
throw new Error("Probably got an actual texture path, haven't written code to handle this.. " + texturePath); String resolved = Material.resolveTexturePath(path, texturePath);
if(resolved != null && resolved.length() > 0){
rVal.usesFetch = true;
rVal.diffuse = resolved;
Globals.assetManager.addTexturePathtoQueue(rVal.diffuse);
}
} }
} }
@ -131,7 +155,7 @@ public class Material {
} }
if(discovered == null){ if(discovered == null){
LoggerInterface.loggerRenderer.WARNING("Failed to find texture " + filename + " for model " + path); LoggerInterface.loggerRenderer.WARNING("Failed to find texture \"" + filename + "\" for model " + path);
return null; return null;
} else { } else {
Path relative = new File("./assets").toPath().relativize(discovered.toPath()); Path relative = new File("./assets").toPath().relativize(discovered.toPath());
@ -143,7 +167,7 @@ public class Material {
* Gets the path for the diffuse of the material * Gets the path for the diffuse of the material
* @return The path for the diffuse texture * @return The path for the diffuse texture
*/ */
public String get_diffuse(){ public String getDiffuse(){
return diffuse; return diffuse;
} }
@ -151,22 +175,30 @@ public class Material {
* Gets the path for the specular of the material * Gets the path for the specular of the material
* @return The path for the specular texture * @return The path for the specular texture
*/ */
public String get_specular(){ public String getSpecular(){
return specular; return specular;
} }
public void set_diffuse(String t){
/**
* Sets the diffuse texture
* @param t The texture path
*/
public void setDiffuse(String t){
diffuse = t; diffuse = t;
// if(t.isTransparent()){
// hasTransparency = true;
// }
} }
public void set_specular(String t){
/**
* Sets the specular texture path
* @param t The specular texture path
*/
public void setSpecular(String t){
specular = t; specular = t;
// if(t.isTransparent()){
// hasTransparency = true;
// }
} }
/**
* Sets the texture pointer
* @param pointer The texture pointer
*/
public void setTexturePointer(int pointer){ public void setTexturePointer(int pointer){
texturePointer = pointer; texturePointer = pointer;
usesFetch = false; usesFetch = false;

View File

@ -110,7 +110,7 @@ public class Model {
rVal.materials = new ArrayList<Material>(); rVal.materials = new ArrayList<Material>();
PointerBuffer material_buffer = scene.mMaterials(); PointerBuffer material_buffer = scene.mMaterials();
while(material_buffer.hasRemaining()){ while(material_buffer.hasRemaining()){
rVal.materials.add(Material.load_material_from_aimaterial(path,scene,AIMaterial.create(material_buffer.get()))); rVal.materials.add(Material.loadMaterialFromAIMaterial(path,scene,AIMaterial.create(material_buffer.get())));
} }
} }
@ -139,7 +139,7 @@ public class Model {
if(materialIndex < rVal.materials.size()){ if(materialIndex < rVal.materials.size()){
Material mat = rVal.materials.get(materialIndex); Material mat = rVal.materials.get(materialIndex);
//only assign if the diffuse is actually set (ie we've actually loaded it properly) //only assign if the diffuse is actually set (ie we've actually loaded it properly)
if(mat.get_diffuse() != null){ if(mat.getDiffuse() != null){
currentMesh.setMaterial(rVal.materials.get(materialIndex)); currentMesh.setMaterial(rVal.materials.get(materialIndex));
} }
} }

View File

@ -69,7 +69,7 @@ public class DebugBonesPipeline implements RenderPipeline {
// //
Actor targetActor = EntityUtils.getActor(targetEntity); Actor targetActor = EntityUtils.getActor(targetEntity);
Model boneModel = Globals.assetManager.fetchModel(AssetDataStrings.UNITCYLINDER); Model boneModel = Globals.assetManager.fetchModel(AssetDataStrings.UNITCYLINDER);
boneModel.getMaterials().get(0).set_diffuse(Globals.textureDiffuseDefault); boneModel.getMaterials().get(0).setDiffuse(Globals.textureDiffuseDefault);
for(Bone bone : targetActor.getBoneValues()){ for(Bone bone : targetActor.getBoneValues()){
Vector3d bonePos = MathBones.getBoneWorldPosition(targetEntity, bone.boneID); Vector3d bonePos = MathBones.getBoneWorldPosition(targetEntity, bone.boneID);
Quaterniond boneRot = MathBones.getBoneWorldRotation(targetEntity, bone.boneID); Quaterniond boneRot = MathBones.getBoneWorldRotation(targetEntity, bone.boneID);

View File

@ -87,8 +87,8 @@ public class Slider extends StandardDrawableElement implements ClickableElement,
super(); super();
if(mat == null){ if(mat == null){
mat = new Material(); mat = new Material();
mat.set_diffuse("Textures/ui/square.png"); mat.setDiffuse("Textures/ui/square.png");
mat.set_specular("Textures/ui/square.png"); mat.setSpecular("Textures/ui/square.png");
} }
setWidth(DEFAULT_WIDTH); setWidth(DEFAULT_WIDTH);
setHeight(DEFAULT_HEIGHT); setHeight(DEFAULT_HEIGHT);
@ -99,8 +99,8 @@ public class Slider extends StandardDrawableElement implements ClickableElement,
super(); super();
if(mat == null){ if(mat == null){
mat = new Material(); mat = new Material();
mat.set_diffuse("Textures/ui/square.png"); mat.setDiffuse("Textures/ui/square.png");
mat.set_specular("Textures/ui/square.png"); mat.setSpecular("Textures/ui/square.png");
} }
setPositionX(positionX); setPositionX(positionX);
setPositionY(positionY); setPositionY(positionY);

View File

@ -96,13 +96,13 @@ public class ToggleInput extends StandardDrawableElement implements ClickableEle
//material work //material work
if(circleMat == null){ if(circleMat == null){
circleMat = new Material(); circleMat = new Material();
circleMat.set_diffuse("Textures/ui/circle.png"); circleMat.setDiffuse("Textures/ui/circle.png");
circleMat.set_specular("Textures/ui/circle.png"); circleMat.setSpecular("Textures/ui/circle.png");
} }
if(barMat == null){ if(barMat == null){
barMat = new Material(); barMat = new Material();
barMat.set_diffuse("Textures/ui/square.png"); barMat.setDiffuse("Textures/ui/square.png");
barMat.set_specular("Textures/ui/square.png"); barMat.setSpecular("Textures/ui/square.png");
} }
this.setWidth(TOGGLE_PIXEL_WIDTH_DEFAULT); this.setWidth(TOGGLE_PIXEL_WIDTH_DEFAULT);