Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.nio.ByteBuffer;
- import java.util.ArrayList;
- import java.util.BitSet;
- import java.util.EnumSet;
- import org.lwjgl.PointerBuffer;
- import static org.lwjgl.system.MemoryUtil.memUTF8;
- import static org.lwjgl.vulkan.VK10.VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
- import static org.lwjgl.vulkan.VK10.VK_DESCRIPTOR_TYPE_SAMPLER;
- import static org.lwjgl.vulkan.VK10.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
- import static org.lwjgl.vulkan.VK10.VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
- import static org.lwjgl.vulkan.VK10.VK_SHADER_STAGE_FRAGMENT_BIT;
- import static org.lwjgl.system.MemoryUtil.memAllocPointer;
- import static org.lwjgl.system.MemoryUtil.memFree;
- import static org.lwjgl.system.MemoryUtil.memAddress;
- import static org.lwjgl.system.MemoryUtil.memAlloc;
- import org.lwjgl.assimp.AIColor4D;
- import org.lwjgl.assimp.AIMaterial;
- import org.lwjgl.assimp.AIMaterialProperty;
- import org.lwjgl.assimp.AIString;
- import org.lwjgl.assimp.AIUVTransform;
- import org.lwjgl.assimp.AIVector3D;
- import org.lwjgl.vulkan.VkDescriptorSetLayoutBinding;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_NAME;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_COLOR_DIFFUSE;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_COLOR_SPECULAR;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_COLOR_AMBIENT;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_COLOR_EMISSIVE;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_COLOR_TRANSPARENT;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_COLOR_REFLECTIVE;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_ENABLE_WIREFRAME;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_SHADING_MODEL;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_BLEND_FUNC;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_TWOSIDED;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_OPACITY;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_REFLECTIVITY;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_SHININESS;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_SHININESS_STRENGTH;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_REFRACTI;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_BUMPSCALING;
- import static org.lwjgl.assimp.Assimp.AI_MATKEY_GLOBAL_BACKGROUND_IMAGE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_TEXTURE_BASE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_MAPPING_BASE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_MAPPINGMODE_U_BASE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_MAPPINGMODE_V_BASE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_TEXBLEND_BASE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_TEXOP_BASE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_TEXFLAGS_BASE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_TEXMAP_AXIS_BASE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_UVTRANSFORM_BASE;
- import static org.lwjgl.assimp.Assimp._AI_MATKEY_UVWSRC_BASE;
- import static org.lwjgl.assimp.Assimp.aiTextureType_NONE;
- import static org.lwjgl.assimp.Assimp.aiTextureType_DIFFUSE;
- import static org.lwjgl.assimp.Assimp.aiTextureType_SPECULAR;
- import static org.lwjgl.assimp.Assimp.aiTextureType_AMBIENT;
- import static org.lwjgl.assimp.Assimp.aiTextureType_EMISSIVE;
- import static org.lwjgl.assimp.Assimp.aiTextureType_HEIGHT;
- import static org.lwjgl.assimp.Assimp.aiTextureType_NORMALS;
- import static org.lwjgl.assimp.Assimp.aiTextureType_OPACITY;
- import static org.lwjgl.assimp.Assimp.aiTextureType_SHININESS;
- import static org.lwjgl.assimp.Assimp.aiTextureType_DISPLACEMENT;
- import static org.lwjgl.assimp.Assimp.aiTextureType_LIGHTMAP;
- import static org.lwjgl.assimp.Assimp.aiTextureType_REFLECTION;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_Flat;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_Gouraud;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_Phong;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_Blinn;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_Toon;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_OrenNayar;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_Minnaert;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_CookTorrance;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_NoShading;
- import static org.lwjgl.assimp.Assimp.aiShadingMode_Fresnel;
- import static org.lwjgl.assimp.Assimp.aiBlendMode_Default;
- import static org.lwjgl.assimp.Assimp.aiBlendMode_Additive;
- import static org.lwjgl.assimp.Assimp.aiTextureOp_Multiply;
- import static org.lwjgl.assimp.Assimp.aiTextureOp_Add;
- import static org.lwjgl.assimp.Assimp.aiTextureOp_Subtract;
- import static org.lwjgl.assimp.Assimp.aiTextureOp_Divide;
- import static org.lwjgl.assimp.Assimp.aiTextureOp_SmoothAdd;
- import static org.lwjgl.assimp.Assimp.aiTextureOp_SignedAdd;
- import static org.lwjgl.assimp.Assimp.aiTextureMapping_UV;
- import static org.lwjgl.assimp.Assimp.aiTextureMapping_SPHERE;
- import static org.lwjgl.assimp.Assimp.aiTextureMapping_CYLINDER;
- import static org.lwjgl.assimp.Assimp.aiTextureMapping_BOX;
- import static org.lwjgl.assimp.Assimp.aiTextureMapping_PLANE;
- import static org.lwjgl.assimp.Assimp.aiTextureMapping_OTHER;
- import static org.lwjgl.assimp.Assimp.aiTextureMapMode_Wrap;
- import static org.lwjgl.assimp.Assimp.aiTextureMapMode_Clamp;
- import static org.lwjgl.assimp.Assimp.aiTextureMapMode_Decal;
- import static org.lwjgl.assimp.Assimp.aiTextureMapMode_Mirror;
- import static org.lwjgl.assimp.Assimp.aiTextureFlags_Invert;
- import static org.lwjgl.assimp.Assimp.aiTextureFlags_UseAlpha;
- import static org.lwjgl.assimp.Assimp.aiTextureFlags_IgnoreAlpha;
- import static org.lwjgl.assimp.Assimp.aiGetMaterialString;
- import static org.lwjgl.assimp.Assimp.aiGetMaterialColor;
- import static org.lwjgl.assimp.Assimp.aiGetMaterialIntegerArray;
- import static org.lwjgl.assimp.Assimp.aiGetMaterialFloatArray;
- import static org.lwjgl.assimp.Assimp.aiGetMaterialUVTransform;
- public class Material {
- public static enum TextureType {NONE, DIFFUSE, SPECULAR, AMBIENT, EMISSIVE, HEIGHT, NORMALS, SHININESS, OPACITY, DISPLACEMENT, LIGHTMAP, REFLECTION, UNKNOWN};
- public static enum ShadingMode {FLAT, GOURAUD, PHONG, BLINN, TOON, OREN_NAYAR, MINNAERT, COOK_TORRANCE, NO_SHADING, FRESNEL};
- public static enum BlendFunc {DEFAULT, ADDITIVE};
- public static enum TextureOp {MULTIPLY, ADD, SUBTRACT, DIVIDE, SMOOTH_ADD, SIGNED_ADD};
- public static enum TextureMapping {UV, SPHERE, CYLINDER, BOX, PLANE, OTHER};
- public static enum TextureMappingMode {WRAP, CLAMP, DECAL, MIRROR};
- public static enum TextureFlag {INVERT, USE_ALPHA, IGNORE_ALPHA};
- public final MaterialProperty[] materialProperties;
- public final String name;
- public final double[] diffuseColor;//default is black; Is allready multiplied with export diffuse factor
- public final double[] specularColor;//default is black
- public final double[] ambientColor;//default is black
- public final double[] emissiveColor;//default is black
- public final double[] transparentColor;//default is black
- public final double[] reflectiveColor;//default is black
- public final boolean wireframe;//default is false
- public final boolean twosided;//default is false
- public final ShadingMode shadingModel;//Default is Phong
- public final BlendFunc blendFunc;//Default is Default
- public final float opacity;//When not 1 => not cull faces; default is 1.0
- public float shininess;//0 means shadingMode Gouraud; Default is 0.0
- public final float shininessStrength;//Default is 1.0;scales specular color
- public final float refractionIndex;//Interesting for Raytracing; default is 1.0
- //TODO:Reflectivity, bumpscaling, etc.
- public final float bumpScaling;
- public final float reflectivity;//Needed in shader. than higher, than more incoming light is reflected.
- public final boolean globalBackgroundImage;//Not yet used
- //TODO: Normalmap, heightmap, shininessMap, dosplacemep, lightmap, reflectionmap
- public final TextureStack diffuseTextureStack;
- public final TextureStack specularTextureStack;
- public final TextureStack ambientTextureStack;
- public final TextureStack emissiveTextureStack;
- public final TextureStack heightTextureStack;
- public final TextureStack normalsTextureStack;
- public final TextureStack shininessTextureStack;
- public final TextureStack opacityTextureStack;
- public final TextureStack displacementTextureStack;
- public final TextureStack lightmapTextureStack;
- public final TextureStack reflectionTextureStack;
- public final BitSet activeTextures;
- public final BitSet activeColors;
- public static final VkDescriptorSetLayoutBinding.Buffer advancedLayoutBindings = VkDescriptorSetLayoutBinding.calloc(2);
- static {
- //Image binding
- advancedLayoutBindings.get(0).binding(0);
- advancedLayoutBindings.get(0).descriptorType(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
- advancedLayoutBindings.get(0).descriptorCount(1);
- advancedLayoutBindings.get(0).pImmutableSamplers(null);
- advancedLayoutBindings.get(0).stageFlags(VK_SHADER_STAGE_FRAGMENT_BIT);
- //Sampler binding
- advancedLayoutBindings.get(1).binding(1);
- advancedLayoutBindings.get(1).descriptorType(VK_DESCRIPTOR_TYPE_SAMPLER);
- advancedLayoutBindings.get(1).descriptorCount(1);
- advancedLayoutBindings.get(1).pImmutableSamplers(null);
- advancedLayoutBindings.get(1).stageFlags(VK_SHADER_STAGE_FRAGMENT_BIT);
- }
- public static final VkDescriptorSetLayoutBinding.Buffer layoutBindings = VkDescriptorSetLayoutBinding.calloc(3);
- static {
- //Image binding
- layoutBindings.get(0).binding(0);
- layoutBindings.get(0).descriptorType(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
- layoutBindings.get(0).descriptorCount(1);
- layoutBindings.get(0).pImmutableSamplers(null);
- layoutBindings.get(0).stageFlags(VK_SHADER_STAGE_FRAGMENT_BIT);
- //Sampler binding
- layoutBindings.get(1).binding(1);
- layoutBindings.get(1).descriptorType(VK_DESCRIPTOR_TYPE_SAMPLER);
- layoutBindings.get(1).descriptorCount(1);
- layoutBindings.get(1).pImmutableSamplers(null);
- layoutBindings.get(1).stageFlags(VK_SHADER_STAGE_FRAGMENT_BIT);
- //Dst-Image binding
- layoutBindings.get(2).binding(2);
- layoutBindings.get(2).descriptorType(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT);
- layoutBindings.get(2).descriptorCount(1);
- layoutBindings.get(2).pImmutableSamplers(null);
- layoutBindings.get(2).stageFlags(VK_SHADER_STAGE_FRAGMENT_BIT);
- }
- //TODO: gltf
- public Material(AIMaterial material) {
- this.materialProperties = new MaterialProperty[material.mNumProperties()];
- PointerBuffer aiMaterialProperties = material.mProperties();
- for(int i=0;i<material.mNumProperties();++i) {
- this.materialProperties[i] = new MaterialProperty(AIMaterialProperty.create(aiMaterialProperties.get(i)));
- }
- //Get Data
- AIString aiName = AIString.calloc();
- int found = aiGetMaterialString(material, AI_MATKEY_NAME, aiTextureType_NONE, 0, aiName);
- if(found == 0) {
- this.name = memUTF8(aiName.data());
- }else {
- this.name = null;
- }
- aiName.free();
- this.activeColors = new BitSet(6);
- AIColor4D aiColor = AIColor4D.calloc();
- found = aiGetMaterialColor(material, AI_MATKEY_COLOR_DIFFUSE, aiTextureType_NONE, 0, aiColor);
- if(found == 0) {
- this.diffuseColor = new double[] {aiColor.r(), aiColor.g(), aiColor.b(), aiColor.a()};
- this.activeColors.flip(0);
- }else {
- this.diffuseColor = null;
- }
- found = aiGetMaterialColor(material, AI_MATKEY_COLOR_SPECULAR, aiTextureType_NONE, 0, aiColor);
- if(found == 0) {
- this.specularColor = new double[] {aiColor.r(), aiColor.g(), aiColor.b(), aiColor.a()};
- this.activeColors.flip(1);
- }else {
- this.specularColor = null;
- }
- found = aiGetMaterialColor(material, AI_MATKEY_COLOR_AMBIENT, aiTextureType_NONE, 0, aiColor);
- if(found == 0) {
- this.ambientColor = new double[] {aiColor.r(), aiColor.g(), aiColor.b(), aiColor.a()};
- this.activeColors.flip(2);
- }else {
- this.ambientColor = null;
- }
- found = aiGetMaterialColor(material, AI_MATKEY_COLOR_EMISSIVE, aiTextureType_NONE, 0, aiColor);
- if(found == 0) {
- this.emissiveColor = new double[] {aiColor.r(), aiColor.g(), aiColor.b(), aiColor.a()};
- this.activeColors.flip(3);
- }else {
- this.emissiveColor = null;
- }
- found = aiGetMaterialColor(material, AI_MATKEY_COLOR_TRANSPARENT, aiTextureType_NONE, 0, aiColor);
- if(found == 0) {
- this.transparentColor = new double[] {aiColor.r(), aiColor.g(), aiColor.b(), aiColor.a()};
- this.activeColors.flip(4);
- }else {
- this.transparentColor = null;
- }
- found = aiGetMaterialColor(material, AI_MATKEY_COLOR_REFLECTIVE, aiTextureType_NONE, 0, aiColor);
- if(found == 0) {
- this.reflectiveColor = new double[] {aiColor.r(), aiColor.g(), aiColor.b(), aiColor.a()};
- this.activeColors.flip(5);
- }else {
- this.reflectiveColor = null;
- }
- aiColor.free();
- int[] aiInteger = new int[1];
- found = aiGetMaterialIntegerArray(material, AI_MATKEY_ENABLE_WIREFRAME, aiTextureType_NONE, 0, aiInteger, new int[] {1});
- if(found == 0) {
- this.wireframe = (aiInteger[0] != 0);
- }else {
- this.wireframe = false;
- }
- found = aiGetMaterialIntegerArray(material, AI_MATKEY_SHADING_MODEL, aiTextureType_NONE, 0, aiInteger, new int[] {1});
- this.shadingModel = ShadingMode.PHONG;
- /*
- if(found == 0) {
- switch(aiInteger[0]) {
- case aiShadingMode_Flat:
- this.shadingModel = ShadingMode.FLAT;
- break;
- case aiShadingMode_Gouraud:
- this.shadingModel = ShadingMode.GOURAUD;
- break;
- case aiShadingMode_Phong:
- this.shadingModel = ShadingMode.PHONG;
- break;
- case aiShadingMode_Blinn:
- this.shadingModel = ShadingMode.BLINN;
- break;
- case aiShadingMode_Toon:
- this.shadingModel = ShadingMode.TOON;
- break;
- case aiShadingMode_OrenNayar:
- this.shadingModel = ShadingMode.OREN_NAYAR;
- break;
- case aiShadingMode_Minnaert:
- this.shadingModel = ShadingMode.MINNAERT;
- break;
- case aiShadingMode_CookTorrance:
- this.shadingModel = ShadingMode.COOK_TORRANCE;
- break;
- case aiShadingMode_NoShading:
- this.shadingModel = ShadingMode.NO_SHADING;
- break;
- case aiShadingMode_Fresnel:
- this.shadingModel = ShadingMode.FRESNEL;
- break;
- default:
- throw new AssertionError("Unspecified type!");
- }
- }else {
- this.shadingModel = ShadingMode.PHONG;
- }
- */
- found = aiGetMaterialIntegerArray(material, AI_MATKEY_BLEND_FUNC, aiTextureType_NONE, 0, aiInteger, new int[] {1});
- if(found == 0) {
- switch(aiInteger[0]) {
- case aiBlendMode_Default:
- this.blendFunc = BlendFunc.DEFAULT;
- break;
- case aiBlendMode_Additive:
- this.blendFunc = BlendFunc.ADDITIVE;
- break;
- default:
- throw new AssertionError("Unspecified type!");
- }
- }else {
- this.blendFunc = BlendFunc.DEFAULT;
- }
- found = aiGetMaterialIntegerArray(material, AI_MATKEY_GLOBAL_BACKGROUND_IMAGE, aiTextureType_NONE, 0, aiInteger, new int[] {1});
- if(found == 0) {
- this.globalBackgroundImage = (aiInteger[0] != 0);//TODO: What is backgroundimage; Probably no index but boolean?
- }else {
- this.globalBackgroundImage = false;
- }
- float[] aiFloat = new float[1];
- found = aiGetMaterialFloatArray(material, AI_MATKEY_OPACITY, aiTextureType_NONE, 0, aiFloat, new int[] {1});
- if(found == 0) {
- this.opacity = aiFloat[0];
- }else {
- this.opacity = 1.0f;
- }
- found = aiGetMaterialIntegerArray(material, AI_MATKEY_TWOSIDED, aiTextureType_NONE, 0, aiInteger, new int[] {1});
- if(found == 0) {
- //this.twosided = (aiInteger[0] != 0);
- //FIXME:
- this.twosided = true;//Set for Debug reason
- }else {
- this.twosided = true;//Should depend on global all opacity values.
- }
- found = aiGetMaterialFloatArray(material, AI_MATKEY_SHININESS, aiTextureType_NONE, 0, aiFloat, new int[] {1});
- if(found == 0) {
- this.shininess = aiFloat[0];
- }else {
- this.shininess = 0.0f;
- }
- found = aiGetMaterialFloatArray(material, AI_MATKEY_SHININESS_STRENGTH, aiTextureType_NONE, 0, aiFloat, new int[] {1});
- if(found == 0) {
- this.shininessStrength = aiFloat[0];
- }else {
- this.shininessStrength = 1.0f;
- }
- found = aiGetMaterialFloatArray(material, AI_MATKEY_REFRACTI, aiTextureType_NONE, 0, aiFloat, new int[] {1});
- if(found == 0) {
- this.refractionIndex = aiFloat[0];
- }else {
- this.refractionIndex = 1.0f;
- }
- found = aiGetMaterialFloatArray(material, AI_MATKEY_BUMPSCALING, aiTextureType_NONE, 0, aiFloat, new int[] {1});
- if(found == 0) {
- this.bumpScaling = aiFloat[0];
- }else {
- this.bumpScaling = 1.0f;
- }
- found = aiGetMaterialFloatArray(material, AI_MATKEY_REFLECTIVITY, aiTextureType_NONE, 0, aiFloat, new int[] {1});
- if(found == 0) {
- this.reflectivity = aiFloat[0];
- }else {
- this.reflectivity = 0.0f;
- }
- ArrayList<TextureStackItem> diffuseTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> specularTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> ambientTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> emissiveTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> heightTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> normalsTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> shininessTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> opacityTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> displacementTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> lightmapTextureStackItems = new ArrayList<TextureStackItem>();
- ArrayList<TextureStackItem> reflectionTextureStackItems = new ArrayList<TextureStackItem>();
- for(int i=0;i<materialProperties.length;++i) {
- switch(materialProperties[i].semantic) {
- case NONE:
- break;
- case DIFFUSE:
- handleProperty(diffuseTextureStackItems, aiTextureType_DIFFUSE, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case SPECULAR:
- handleProperty(specularTextureStackItems, aiTextureType_SPECULAR, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case AMBIENT:
- handleProperty(ambientTextureStackItems, aiTextureType_AMBIENT, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case EMISSIVE:
- handleProperty(emissiveTextureStackItems, aiTextureType_EMISSIVE, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case HEIGHT:
- handleProperty(heightTextureStackItems, aiTextureType_HEIGHT, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case NORMALS:
- handleProperty(normalsTextureStackItems, aiTextureType_NORMALS, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case SHININESS:
- handleProperty(shininessTextureStackItems, aiTextureType_SHININESS, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case OPACITY:
- handleProperty(opacityTextureStackItems, aiTextureType_OPACITY, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case DISPLACEMENT:
- handleProperty(displacementTextureStackItems, aiTextureType_DISPLACEMENT, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case LIGHTMAP:
- handleProperty(lightmapTextureStackItems, aiTextureType_LIGHTMAP, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case REFLECTION:
- handleProperty(reflectionTextureStackItems, aiTextureType_REFLECTION, materialProperties[i].key, materialProperties[i].index, material, materialProperties[i].data);
- break;
- case UNKNOWN:
- break;
- default:
- throw new AssertionError("Unspecified type!");
- }
- }
- this.diffuseTextureStack = new TextureStack(diffuseTextureStackItems.toArray(new TextureStackItem[0]), TextureType.DIFFUSE, this);
- this.specularTextureStack = new TextureStack(specularTextureStackItems.toArray(new TextureStackItem[0]), TextureType.SPECULAR, this);
- this.ambientTextureStack = new TextureStack(ambientTextureStackItems.toArray(new TextureStackItem[0]), TextureType.AMBIENT, this);
- this.emissiveTextureStack = new TextureStack(emissiveTextureStackItems.toArray(new TextureStackItem[0]), TextureType.EMISSIVE, this);
- this.heightTextureStack = new TextureStack(heightTextureStackItems.toArray(new TextureStackItem[0]), TextureType.HEIGHT, this);
- this.normalsTextureStack = new TextureStack(normalsTextureStackItems.toArray(new TextureStackItem[0]), TextureType.NORMALS, this);
- this.shininessTextureStack = new TextureStack(shininessTextureStackItems.toArray(new TextureStackItem[0]), TextureType.SHININESS, this);
- this.opacityTextureStack = new TextureStack(opacityTextureStackItems.toArray(new TextureStackItem[0]), TextureType.OPACITY, this);
- this.displacementTextureStack = new TextureStack(displacementTextureStackItems.toArray(new TextureStackItem[0]), TextureType.DISPLACEMENT, this);
- this.lightmapTextureStack = new TextureStack(lightmapTextureStackItems.toArray(new TextureStackItem[0]), TextureType.LIGHTMAP, this);
- this.reflectionTextureStack = new TextureStack(reflectionTextureStackItems.toArray(new TextureStackItem[0]), TextureType.REFLECTION, this);
- this.activeTextures = new BitSet(11);
- if(diffuseTextureStackItems.size() > 0) {
- this.activeTextures.flip(0);
- }
- if(specularTextureStackItems.size() > 0) {
- this.activeTextures.flip(1);
- }
- if(ambientTextureStackItems.size() > 0) {
- this.activeTextures.flip(2);
- }
- if(emissiveTextureStackItems.size() > 0) {
- this.activeTextures.flip(3);
- }
- if(heightTextureStackItems.size() > 0) {
- this.activeTextures.flip(4);
- }
- if(normalsTextureStackItems.size() > 0) {
- this.activeTextures.flip(5);
- }
- if(shininessTextureStackItems.size() > 0) {
- this.activeTextures.flip(6);
- }
- if(opacityTextureStackItems.size() > 0) {
- this.activeTextures.flip(7);
- }
- if(displacementTextureStackItems.size() > 0) {
- this.activeTextures.flip(8);
- }
- if(lightmapTextureStackItems.size() > 0) {
- this.activeTextures.flip(9);
- }
- if(reflectionTextureStackItems.size() > 0) {
- this.activeTextures.flip(10);
- }
- if(!activeTextures.get(1) && specularColor != null) {//TODO:Premultiply specularColor with it's strength, when no texture is applied. Otherwise blend texture
- shininess *= shininessStrength;
- }
- this.printOut();
- }
- public static void handleProperty(ArrayList<TextureStackItem> currentList, int textureType, String materialKey, int textureIndex, AIMaterial material, ByteBuffer data) {
- if(textureIndex > currentList.size()-1) {
- for(int j=currentList.size();j<textureIndex;++j) {
- currentList.add(null);
- }
- currentList.add(new TextureStackItem());
- }else if(currentList.get(textureIndex) == null) {
- currentList.set(textureIndex, new TextureStackItem());
- }
- switch(materialKey) {
- case _AI_MATKEY_TEXTURE_BASE:
- data.getInt();
- String path = memUTF8(data);
- path = path.substring(0, path.length()-1);
- //System.out.println(path);
- data.rewind();
- currentList.get(textureIndex).texturePath = path;//TODO: When embeeded special path. Preload all Textures in Texelbuffers.
- break;
- case _AI_MATKEY_TEXBLEND_BASE:
- float[] aiFloat = new float[1];
- int found = aiGetMaterialFloatArray(material, _AI_MATKEY_TEXBLEND_BASE, textureType, textureIndex, aiFloat, new int[] {1});
- if(found == 0) {
- currentList.get(textureIndex).textureStrength = aiFloat[0];
- }else {
- currentList.get(textureIndex).textureStrength = 1.0f;
- }
- break;
- case _AI_MATKEY_TEXOP_BASE:
- int[] aiInteger = new int[1];
- found = aiGetMaterialIntegerArray(material, _AI_MATKEY_TEXOP_BASE, textureType, textureIndex, aiInteger, new int[] {1});
- if(found == 0) {
- switch(aiInteger[0]) {
- case aiTextureOp_Multiply:
- currentList.get(textureIndex).textureOp = TextureOp.MULTIPLY;
- break;
- case aiTextureOp_Add:
- currentList.get(textureIndex).textureOp = TextureOp.ADD;
- break;
- case aiTextureOp_Subtract:
- currentList.get(textureIndex).textureOp = TextureOp.SUBTRACT;
- break;
- case aiTextureOp_Divide:
- currentList.get(textureIndex).textureOp = TextureOp.DIVIDE;
- break;
- case aiTextureOp_SmoothAdd:
- currentList.get(textureIndex).textureOp = TextureOp.SMOOTH_ADD;
- break;
- case aiTextureOp_SignedAdd:
- currentList.get(textureIndex).textureOp = TextureOp.SIGNED_ADD;
- break;
- default:
- throw new AssertionError("Unknown operation!");
- }
- }else {
- currentList.get(textureIndex).textureOp = TextureOp.MULTIPLY;
- }
- break;
- case _AI_MATKEY_MAPPING_BASE:
- aiInteger = new int[1];
- found = aiGetMaterialIntegerArray(material, _AI_MATKEY_MAPPING_BASE, textureType, textureIndex, aiInteger, new int[] {1});
- if(found == 0) {
- switch(aiInteger[0]) {
- case aiTextureMapping_UV:
- currentList.get(textureIndex).textureMapping = TextureMapping.UV;
- break;
- case aiTextureMapping_SPHERE:
- currentList.get(textureIndex).textureMapping = TextureMapping.SPHERE;
- break;
- case aiTextureMapping_CYLINDER:
- currentList.get(textureIndex).textureMapping = TextureMapping.CYLINDER;
- break;
- case aiTextureMapping_BOX:
- currentList.get(textureIndex).textureMapping = TextureMapping.BOX;
- break;
- case aiTextureMapping_PLANE:
- currentList.get(textureIndex).textureMapping = TextureMapping.PLANE;
- break;
- case aiTextureMapping_OTHER:
- currentList.get(textureIndex).textureMapping = TextureMapping.OTHER;
- break;
- default:
- throw new AssertionError("Unknown mapping!");
- }
- }else {
- currentList.get(textureIndex).textureMapping = TextureMapping.UV;
- }
- break;
- case _AI_MATKEY_UVWSRC_BASE:
- aiInteger = new int[1];
- found = aiGetMaterialIntegerArray(material, _AI_MATKEY_UVWSRC_BASE, textureType, textureIndex, aiInteger, new int[] {1});
- if(found == 0) {
- currentList.get(textureIndex).textureUVChannel = aiInteger[0];
- }else {
- currentList.get(textureIndex).textureUVChannel = 0;
- }
- break;
- case _AI_MATKEY_MAPPINGMODE_U_BASE:
- aiInteger = new int[1];
- found = aiGetMaterialIntegerArray(material, _AI_MATKEY_MAPPINGMODE_U_BASE, textureType, textureIndex, aiInteger, new int[] {1});
- if(found == 0) {
- switch(aiInteger[0]) {
- case aiTextureMapMode_Wrap:
- currentList.get(textureIndex).textureMappingModeU = TextureMappingMode.WRAP;
- break;
- case aiTextureMapMode_Clamp:
- currentList.get(textureIndex).textureMappingModeU = TextureMappingMode.CLAMP;
- break;
- case aiTextureMapMode_Decal:
- currentList.get(textureIndex).textureMappingModeU = TextureMappingMode.DECAL;
- break;
- case aiTextureMapMode_Mirror:
- currentList.get(textureIndex).textureMappingModeU = TextureMappingMode.MIRROR;
- break;
- default:
- throw new AssertionError("Unknown mappingmode!");
- }
- }else {
- currentList.get(textureIndex).textureMappingModeU = TextureMappingMode.WRAP;
- }
- break;
- case _AI_MATKEY_MAPPINGMODE_V_BASE:
- aiInteger = new int[1];
- found = aiGetMaterialIntegerArray(material, _AI_MATKEY_MAPPINGMODE_V_BASE, textureType, textureIndex, aiInteger, new int[] {1});
- if(found == 0) {
- switch(aiInteger[0]) {
- case aiTextureMapMode_Wrap:
- currentList.get(textureIndex).textureMappingModeV = TextureMappingMode.WRAP;
- break;
- case aiTextureMapMode_Clamp:
- currentList.get(textureIndex).textureMappingModeV = TextureMappingMode.CLAMP;
- break;
- case aiTextureMapMode_Decal:
- currentList.get(textureIndex).textureMappingModeV = TextureMappingMode.DECAL;
- break;
- case aiTextureMapMode_Mirror:
- currentList.get(textureIndex).textureMappingModeV = TextureMappingMode.MIRROR;
- break;
- default:
- throw new AssertionError("Unknown mappingmode!");
- }
- }else {
- currentList.get(textureIndex).textureMappingModeV = TextureMappingMode.WRAP;
- }
- break;
- case _AI_MATKEY_TEXMAP_AXIS_BASE:
- currentList.get(textureIndex).textureMappingBaseAxis = new double[] {data.getFloat(), data.getFloat(), data.getFloat()};//TODO: test and probably add align at the front
- data.rewind();
- break;
- case _AI_MATKEY_TEXFLAGS_BASE:
- aiInteger = new int[1];
- found = aiGetMaterialIntegerArray(material, _AI_MATKEY_TEXFLAGS_BASE, textureType, textureIndex, aiInteger, new int[] {1});
- if(found == 0) {
- currentList.get(textureIndex).textureFlags = EnumSet.noneOf(TextureFlag.class);
- if((aiInteger[0] & aiTextureFlags_Invert) == aiTextureFlags_Invert){
- currentList.get(textureIndex).textureFlags.add(TextureFlag.INVERT);
- }
- if((aiInteger[0] & aiTextureFlags_UseAlpha) == aiTextureFlags_UseAlpha){
- currentList.get(textureIndex).textureFlags.add(TextureFlag.USE_ALPHA);
- }
- if((aiInteger[0] & aiTextureFlags_IgnoreAlpha) == aiTextureFlags_IgnoreAlpha){
- currentList.get(textureIndex).textureFlags.add(TextureFlag.IGNORE_ALPHA);
- }
- }else {
- currentList.get(textureIndex).textureFlags = EnumSet.noneOf(TextureFlag.class);
- }
- break;
- case _AI_MATKEY_UVTRANSFORM_BASE:
- AIUVTransform aiUVTransform = AIUVTransform.calloc();
- found = aiGetMaterialUVTransform(material, _AI_MATKEY_UVTRANSFORM_BASE, textureType, textureIndex, aiUVTransform);
- if(found == 0) {
- currentList.get(textureIndex).textureUVTranslation = new double[] {aiUVTransform.mTranslation().x(), aiUVTransform.mTranslation().y()};
- currentList.get(textureIndex).textureUVScaling = new double[] {aiUVTransform.mScaling().x(), aiUVTransform.mScaling().y()};
- currentList.get(textureIndex).textureUVRotation = aiUVTransform.mRotation();
- }else {
- currentList.get(textureIndex).textureUVTranslation = new double[2];
- currentList.get(textureIndex).textureUVScaling = new double[] {1.0, 1.0};
- currentList.get(textureIndex).textureUVRotation = 0.0f;
- }
- aiUVTransform.free();
- break;
- default:
- throw new AssertionError("Unknown key!");
- }
- }
- public static VkDescriptorSetLayoutBinding.Buffer createLayoutBindings(int descriptorCount) {
- VkDescriptorSetLayoutBinding.Buffer layoutBindings = VkDescriptorSetLayoutBinding.calloc(1+2*7);
- layoutBindings.get(0).binding(0);
- layoutBindings.get(0).descriptorType(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
- layoutBindings.get(0).descriptorCount(descriptorCount);
- layoutBindings.get(0).stageFlags(VK_SHADER_STAGE_FRAGMENT_BIT);
- layoutBindings.get(0).pImmutableSamplers(null);
- for(int i=0;i<7;++i) {
- layoutBindings.get(2*i+1).binding(2*i+1);
- layoutBindings.get(2*i+1).descriptorType(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
- layoutBindings.get(2*i+1).descriptorCount(descriptorCount);
- layoutBindings.get(2*i+1).stageFlags(VK_SHADER_STAGE_FRAGMENT_BIT);
- layoutBindings.get(2*i+1).pImmutableSamplers(null);
- layoutBindings.get(2*i+2).binding(2*i+2);
- layoutBindings.get(2*i+2).descriptorType(VK_DESCRIPTOR_TYPE_SAMPLER);
- layoutBindings.get(2*i+2).descriptorCount(descriptorCount);
- layoutBindings.get(2*i+2).stageFlags(VK_SHADER_STAGE_FRAGMENT_BIT);
- layoutBindings.get(2*i+2).pImmutableSamplers(null);
- }
- return layoutBindings;
- }
- public ByteBuffer getPerMaterialUniformData(long minUniformBufferOffsetAlignment) {
- ArrayList<double[]> colors = new ArrayList<double[]>();
- double[] zeroVal = new double[] {0.0, 0.0, 0.0, 0.0};
- if(diffuseColor!=null) {
- colors.add(diffuseColor);
- }else {
- colors.add(zeroVal);
- }
- if(specularColor!=null) {
- colors.add(specularColor);
- }else {
- colors.add(zeroVal);
- }
- if(ambientColor!=null) {
- colors.add(ambientColor);
- }else {
- colors.add(zeroVal);
- }
- if(emissiveColor!=null) {
- colors.add(emissiveColor);
- }else {
- colors.add(zeroVal);
- }
- if(transparentColor!=null) {
- colors.add(transparentColor);
- }else {
- colors.add(zeroVal);
- }
- int shadingType;
- switch(shadingModel) {
- case FLAT:
- shadingType = 0;
- break;
- case GOURAUD:
- shadingType = 1;
- break;
- case PHONG:
- shadingType = 2;
- break;
- case BLINN:
- shadingType = 3;
- break;
- case TOON:
- shadingType = 4;
- break;
- case OREN_NAYAR:
- shadingType = 5;
- break;
- case MINNAERT:
- shadingType = 6;
- break;
- case COOK_TORRANCE:
- shadingType = 7;
- break;
- case NO_SHADING:
- shadingType = 9;
- break;
- case FRESNEL:
- shadingType = 8;
- break;
- default:
- shadingType = -1;
- throw new AssertionError("Unreachable state!");
- }
- ByteBuffer out = memAlloc((colors.size()*4 + 4)*(Float.SIZE/Byte.SIZE));
- for(int i=0;i<colors.size();++i) {
- for(int j=0;j<4;++j) {
- out.putFloat((float)colors.get(i)[j]);
- }
- }
- out.putFloat(reflectivity);
- out.putFloat(opacity);
- out.putFloat(shininess);
- out.putFloat(Float.intBitsToFloat(shadingType));
- while(!(out.position()%16==0)){
- out.put((byte)0);
- }
- out.flip();
- return out;
- }
- public TextureStack[] getTextureStacks() {
- TextureStack[] out = new TextureStack[11];
- out[0] = diffuseTextureStack;
- out[1] = specularTextureStack;
- out[2] = ambientTextureStack;
- out[3] = emissiveTextureStack;
- out[4] = heightTextureStack;
- out[5] = normalsTextureStack;
- out[6] = shininessTextureStack;
- out[7] = opacityTextureStack;
- out[8] = displacementTextureStack;
- out[9] = lightmapTextureStack;
- out[10] = reflectionTextureStack;
- return out;
- }
- public void printOut() {
- System.out.println("Name: "+name);
- System.out.println("diffuseColor: "+(diffuseColor==null?"null":diffuseColor[0]+" "+diffuseColor[1]+" "+diffuseColor[2]));
- System.out.println("specularColor: "+(specularColor==null?"null":specularColor[0]+" "+specularColor[1]+" "+specularColor[2]));
- System.out.println("ambientColor: "+(ambientColor==null?"null":ambientColor[0]+" "+ambientColor[1]+" "+ambientColor[2]));
- System.out.println("emissiveColor: "+(emissiveColor==null?"null":emissiveColor[0]+" "+emissiveColor[1]+" "+emissiveColor[2]));
- System.out.println("transparentColor: "+(transparentColor==null?"null":transparentColor[0]+" "+transparentColor[1]+" "+transparentColor[2]));
- System.out.println("reflectiveColor: "+(reflectiveColor==null?"null":reflectiveColor[0]+" "+reflectiveColor[1]+" "+reflectiveColor[2]));
- System.out.println("Wireframe: "+wireframe);
- System.out.println("Twosided: "+twosided);
- System.out.println("GlobalBackgroundImage: "+globalBackgroundImage);
- System.out.println("Shading Model: "+shadingModel);
- System.out.println("Blend Function: "+blendFunc);
- System.out.println("Opacity: "+opacity);
- System.out.println("Shininess: "+shininess);
- System.out.println("Shininess Strength: "+shininessStrength);
- System.out.println("Refraction Index: "+refractionIndex);
- System.out.println("Bump Scaling: "+bumpScaling);
- System.out.println("Reflectivity: "+reflectivity);
- printTextureStacks();
- }
- public void printTextureStacks() {
- if(diffuseTextureStack.texturePaths.length != 0) {
- System.out.println("Diffuse TextureStack:");
- diffuseTextureStack.printOut();
- }
- if(specularTextureStack.texturePaths.length != 0) {
- System.out.println("Specular TextureStack:");
- specularTextureStack.printOut();
- }
- if(ambientTextureStack.texturePaths.length != 0) {
- System.out.println("Ambient TextureStack:");
- ambientTextureStack.printOut();
- }
- if(emissiveTextureStack.texturePaths.length != 0) {
- System.out.println("Emissive TextureStack:");
- emissiveTextureStack.printOut();
- }
- if(heightTextureStack.texturePaths.length != 0) {
- System.out.println("Height TextureStack:");
- heightTextureStack.printOut();
- }
- if(normalsTextureStack.texturePaths.length != 0) {
- System.out.println("Normals TextureStack:");
- normalsTextureStack.printOut();
- }
- if(shininessTextureStack.texturePaths.length != 0) {
- System.out.println("Shininess TextureStack:");
- shininessTextureStack.printOut();
- }
- if(opacityTextureStack.texturePaths.length != 0) {
- System.out.println("Opacity TextureStack:");
- opacityTextureStack.printOut();
- }
- if(displacementTextureStack.texturePaths.length != 0) {
- System.out.println("Displacement TextureStack:");
- displacementTextureStack.printOut();
- }
- if(lightmapTextureStack.texturePaths.length != 0) {
- System.out.println("Lightmap TextureStack:");
- lightmapTextureStack.printOut();
- }
- if(reflectionTextureStack.texturePaths.length != 0) {
- System.out.println("Reflection TextureStack:");
- reflectionTextureStack.printOut();
- }
- }
- public static class TextureStack{
- public final String[] texturePaths;
- public final float[] textureStrengths;
- public final TextureOp[] textureOps;
- public final int[] textureUVChannels;
- public final TextureMapping[] textureMappings;
- public final TextureMappingMode[] textureMappingModesU;
- public final TextureMappingMode[] textureMappingModesV;
- public final double[][] textureMappingBaseAxis;
- public final EnumSet<TextureFlag>[] textureFlags;
- public final double[][] textureUVTranslations;
- public final double[][] textureUVScalings;
- public final float[] textureUVRotations;
- public int[] textureIndices;
- public final TextureType textureType;
- public final boolean mustBeBlended;
- public final boolean colorIsDefault;
- public final Material material;
- public final double[] baseColor;
- public TextureStack(String[] texturePaths, float[] textureStrengths, TextureOp[] textureOps, int[] textureUVChannels, TextureMapping[] textureMappings,
- TextureMappingMode[] textureMappingModesU, TextureMappingMode[] textureMappingModesV, double[][] textureMappingBaseAxis,
- EnumSet<TextureFlag>[] textureFlags, double[][] textureUVTranslations, double[][] textureUVScalings, float[] textureUVRotations, TextureType textureType, Material material) {
- this.texturePaths = texturePaths;
- this.textureStrengths = textureStrengths;
- this.textureOps = textureOps;
- this.textureUVChannels = textureUVChannels;
- this.textureMappings = textureMappings;
- this.textureMappingModesU = textureMappingModesU;
- this.textureMappingModesV = textureMappingModesV;
- this.textureMappingBaseAxis = textureMappingBaseAxis;
- this.textureFlags = textureFlags;
- this.textureUVTranslations = textureUVTranslations;
- this.textureUVScalings = textureUVScalings;
- this.textureUVRotations = textureUVRotations;
- this.textureIndices = new int[texturePaths.length];
- this.textureType = textureType;
- this.material = material;
- this.colorIsDefault = calculateColorIsDefault();
- if(!colorIsDefault) {
- baseColor = fetchBaseColor();
- }else {
- baseColor = null;
- }
- this.mustBeBlended = calculateMustBeBlended();
- }
- public TextureStack(TextureStackItem[] stackItems, TextureType textureType, Material material) {
- this.textureType = textureType;
- this.texturePaths = new String[stackItems.length];
- this.textureStrengths = new float[stackItems.length];
- this.textureOps = new TextureOp[stackItems.length];
- this.textureUVChannels = new int[stackItems.length];
- this.textureMappings = new TextureMapping[stackItems.length];
- this.textureMappingModesU = new TextureMappingMode[stackItems.length];
- this.textureMappingModesV = new TextureMappingMode[stackItems.length];
- this.textureMappingBaseAxis = new double[stackItems.length][];
- @SuppressWarnings("unchecked")
- EnumSet<TextureFlag>[] tmp = (EnumSet<TextureFlag>[]) new EnumSet<?>[stackItems.length];
- this.textureFlags = tmp;
- this.textureUVTranslations = new double[stackItems.length][];
- this.textureUVScalings = new double[stackItems.length][];
- this.textureUVRotations = new float[stackItems.length];
- this.textureIndices = new int[texturePaths.length];
- for(int i=0;i<stackItems.length;++i) {
- this.texturePaths[i] = stackItems[i].texturePath;
- this.textureStrengths[i] = stackItems[i].textureStrength;
- this.textureOps[i] = (stackItems[i].textureOp==null?TextureOp.MULTIPLY:stackItems[i].textureOp);
- this.textureUVChannels[i] = (stackItems[i].textureUVChannel == -1?i:stackItems[i].textureUVChannel);
- this.textureMappings[i] = (stackItems[i].textureMapping==null?stackItems[i].textureMapping.UV:stackItems[i].textureMapping);//All converted to UV currently...
- this.textureMappingModesU[i] = (stackItems[i].textureMappingModeU==null?TextureMappingMode.WRAP:stackItems[i].textureMappingModeU);
- this.textureMappingModesV[i] = (stackItems[i].textureMappingModeV==null?TextureMappingMode.WRAP:stackItems[i].textureMappingModeV);
- this.textureMappingBaseAxis[i] = stackItems[i].textureMappingBaseAxis;
- this.textureFlags[i] = (stackItems[i].textureFlags==null?EnumSet.noneOf(TextureFlag.class):stackItems[i].textureFlags);
- this.textureUVTranslations[i] = stackItems[i].textureUVTranslation;
- this.textureUVScalings[i] = stackItems[i].textureUVScaling;
- this.textureUVRotations[i] = stackItems[i].textureUVRotation;
- }
- this.material = material;
- this.colorIsDefault = calculateColorIsDefault();
- if(!colorIsDefault) {
- baseColor = fetchBaseColor();
- }else {
- baseColor = null;
- }
- this.mustBeBlended = calculateMustBeBlended();
- }
- private boolean calculateColorIsDefault() {
- if(this.textureType != TextureType.DIFFUSE && this.textureType != TextureType.SPECULAR && this.textureType != TextureType.AMBIENT && this.textureType != TextureType.EMISSIVE &&
- this.textureType != TextureType.REFLECTION && this.textureType != TextureType.SHININESS) {
- return true;
- }else {
- boolean colorIsDefault;
- switch(this.textureType) {
- case DIFFUSE:
- colorIsDefault = (this.material.diffuseColor == null || (this.material.diffuseColor[0] == 0.0 && this.material.diffuseColor[1] == 0.0 && this.material.diffuseColor[2] == 0.0));
- break;
- case SPECULAR:
- colorIsDefault = (this.material.specularColor == null || (this.material.specularColor[0] == 0.0 && this.material.specularColor[1] == 0.0 && this.material.specularColor[2] == 0.0));
- break;
- case AMBIENT:
- colorIsDefault = (this.material.ambientColor == null || (this.material.ambientColor[0] == 0.0 && this.material.ambientColor[1] == 0.0 && this.material.ambientColor[2] == 0.0));
- break;
- case EMISSIVE:
- colorIsDefault = (this.material.emissiveColor == null || (this.material.emissiveColor[0] == 0.0 && this.material.emissiveColor[1] == 0.0 && this.material.emissiveColor[2] == 0.0));
- break;
- case REFLECTION:
- colorIsDefault = (this.material.reflectiveColor == null || (this.material.reflectiveColor[0] == 0.0 && this.material.reflectiveColor[1] == 0.0 && this.material.reflectiveColor[2] == 0.0));
- break;
- case SHININESS:
- colorIsDefault = (this.material.shininessStrength != 0.0);
- break;
- default:
- throw new AssertionError("Unreachable!");
- }
- return colorIsDefault;
- }
- }
- private double[] fetchBaseColor() {
- switch(this.textureType) {
- case DIFFUSE:
- return this.material.diffuseColor;
- case SPECULAR:
- return this.material.specularColor;
- case AMBIENT:
- return this.material.ambientColor;
- case EMISSIVE:
- return this.material.emissiveColor;
- case REFLECTION:
- return this.material.reflectiveColor;
- case SHININESS:
- return new double[] {this.material.shininessStrength, this.material.shininessStrength, this.material.shininessStrength, this.material.shininessStrength};
- default:
- throw new AssertionError("Unreachable!");
- }
- }
- private boolean calculateMustBeBlended() {
- if(colorIsDefault && this.textureIndices.length<2) {
- return false;
- }
- if(this.textureIndices.length<1) {
- return false;
- }else {
- return true;
- }
- }
- public boolean equalsBlendKind(TextureStack t) {
- if(this.mustBeBlended == false && t.mustBeBlended == false) {
- return true;
- }else if(this.textureIndices.length == t.textureIndices.length) {
- return true;
- }else {
- return false;
- }
- }
- public void printOut() {
- int pathWidth = 0, strengthWidth = 0, channelWidth = 0, axisWidth = 0, flagsWidth = 0, translationWidth = 0, scalingWidth = 0, rotationWidth = 0, indexWidth = 0;
- final int opWidth = 10;
- final int mappingWidth = 8;
- final int mappingModeWidth = 12;
- for(int i=0;i<texturePaths.length;++i) {
- if(texturePaths[i].length() > pathWidth) {
- pathWidth = texturePaths[i].length();
- }
- if((textureStrengths[i]+"").length() > strengthWidth) {
- strengthWidth = (textureStrengths[i]+"").length();
- }
- if((textureUVChannels[i]+"").length() > channelWidth) {
- channelWidth = (textureUVChannels[i]+"").length();
- }
- if(textureMappingBaseAxis[i] != null) {
- if((textureMappingBaseAxis[i][0]+" "+textureMappingBaseAxis[i][1]+" "+textureMappingBaseAxis[i][2]).length() > axisWidth) {
- axisWidth = (textureMappingBaseAxis[i][0]+" "+textureMappingBaseAxis[i][1]+" "+textureMappingBaseAxis[i][2]).length();
- }
- }else {
- if(4 > axisWidth) {
- axisWidth = 4;
- }
- }
- if(this.textureFlags[i] != null) {
- String tmp = "";
- TextureFlag[] dum = this.textureFlags[i].toArray(new TextureFlag[0]);
- for(int j=0;j<dum.length;++j) {
- tmp += dum[j]+"";
- if(j!=dum.length-1) {
- tmp += "|";
- }
- }
- if(tmp.length() > flagsWidth) {
- flagsWidth = tmp.length();
- }
- }else {
- if(4 > flagsWidth) {
- flagsWidth = 4;
- }
- }
- if(textureUVTranslations[i] != null) {
- if((textureUVTranslations[i][0]+" "+textureUVTranslations[i][1]).length() > translationWidth) {
- translationWidth = (textureUVTranslations[i][0]+" "+textureUVTranslations[i][1]).length();
- }
- if((textureUVScalings[i][0]+" "+textureUVScalings[i][1]).length() > scalingWidth) {
- scalingWidth = (textureUVScalings[i][0]+" "+textureUVScalings[i][1]).length();
- }
- }else {
- if(4 > translationWidth) {
- translationWidth = 4;
- }
- if(4 > scalingWidth) {
- scalingWidth = 4;
- }
- }
- if((textureUVRotations[i]+"").length() > rotationWidth) {
- rotationWidth = (textureUVRotations[i]+"").length();
- }
- indexWidth = (i+"").length();
- }
- String out = "Index";
- if(indexWidth < 5) {
- indexWidth = 5;
- }
- for(int i=0;i<indexWidth-5;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "Path";
- if(pathWidth < 4) {
- pathWidth = 4;
- }
- for(int i=0;i<pathWidth-4;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "Strength";
- if(strengthWidth < 8) {
- strengthWidth = 8;
- }
- for(int i=0;i<strengthWidth-8;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "Operation";
- for(int i=0;i<opWidth-9;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "UVChannel";
- if(channelWidth < 9) {
- channelWidth = 9;
- }
- for(int i=0;i<channelWidth-9;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "Mapping";
- for(int i=0;i<mappingWidth-7;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "MappingModeU";
- for(int i=0;i<mappingModeWidth-12;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "MappingModeV";
- for(int i=0;i<mappingModeWidth-12;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "MappingBaseAxis";
- if(axisWidth < 15) {
- axisWidth = 15;
- }
- for(int i=0;i<axisWidth-15;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "TextureFlags";
- if(flagsWidth < 12) {
- flagsWidth = 12;
- }
- for(int i=0;i<flagsWidth-12;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "UVTranslation";
- if(translationWidth < 13) {
- translationWidth = 13;
- }
- for(int i=0;i<translationWidth-13;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "UVScaling";
- if(scalingWidth < 9) {
- scalingWidth = 9;
- }
- for(int i=0;i<scalingWidth-9;++i) {
- out +=" ";
- }
- out +=" | ";
- out += "UVRotation";
- if(rotationWidth < 10) {
- rotationWidth = 10;
- }
- for(int i=0;i<rotationWidth-10;++i) {
- out +=" ";
- }
- System.out.println(out);
- for(int j=0;j<texturePaths.length;++j) {
- String tmp = j+"";
- out = tmp;
- for(int i=0;i<indexWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- tmp = texturePaths[j];
- out += tmp;
- for(int i=0;i<pathWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- tmp = textureStrengths[j]+"";
- out += tmp;
- for(int i=0;i<strengthWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- tmp = textureOps[j]+"";
- out += tmp;
- for(int i=0;i<opWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- tmp = textureUVChannels[j]+"";
- out += tmp;
- for(int i=0;i<channelWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- tmp = textureMappings[j]+"";
- out += tmp;
- for(int i=0;i<mappingWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- tmp = textureMappingModesU[j]+"";
- out += tmp;
- for(int i=0;i<mappingModeWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- tmp = textureMappingModesV[j]+"";
- out += tmp;
- for(int i=0;i<mappingModeWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- if(textureMappingBaseAxis[j] != null) {
- tmp = textureMappingBaseAxis[j][0]+" "+textureMappingBaseAxis[j][1]+" "+textureMappingBaseAxis[j][2];
- }else {
- tmp = "null";
- }
- out += tmp;
- for(int i=0;i<axisWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- tmp = textureFlags[j]+"";
- out += tmp;
- for(int i=0;i<flagsWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- if(textureUVTranslations[j] != null) {
- tmp = textureUVTranslations[j][0]+" "+textureUVTranslations[j][1];
- }else {
- tmp = "null";
- }
- out += tmp;
- for(int i=0;i<translationWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- if(textureUVScalings[j] != null) {
- tmp = textureUVScalings[j][0]+" "+textureUVScalings[j][1];
- }else {
- tmp = "null";
- }
- out += tmp;
- for(int i=0;i<scalingWidth-tmp.length();++i) {
- out +=" ";
- }
- out +=" | ";
- tmp = textureUVRotations[j]+"";
- out += tmp;
- for(int i=0;i<rotationWidth-tmp.length();++i) {
- out +=" ";
- }
- System.out.println(out);
- }
- }
- }
- private static class TextureStackItem{
- public String texturePath = "";
- public float textureStrength = 1.0f;
- public TextureOp textureOp = TextureOp.MULTIPLY;
- public int textureUVChannel;
- public TextureMapping textureMapping = TextureMapping.UV;
- public TextureMappingMode textureMappingModeU = TextureMappingMode.WRAP;
- public TextureMappingMode textureMappingModeV = TextureMappingMode.WRAP;
- public double[] textureMappingBaseAxis;
- public EnumSet<TextureFlag> textureFlags;
- public double[] textureUVTranslation;
- public double[] textureUVScaling;
- public float textureUVRotation;
- public TextureStackItem() {
- textureUVChannel = -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement