public override void loadImageMap(string fileName, int frame, MImage image) { image.readFromFile(fileName); uint width; uint height; image.getSize(out width, out height); uint size = width * height; blendPixel(image, size); MPlug depthMap = new MPlug(thisMObject(), useDepthMap); bool value = false; depthMap.getValue(ref value); if (value) { setDepthMap(image, width, height); } return; }
public override void glBind(MDagPath shapePath) { // ONLY push and pop required attributes performance reasons... // OpenGL.glPushAttrib(OpenGL.GL_LIGHTING_BIT); lightingOn = OpenGL.glIsEnabled(OpenGL.GL_LIGHTING); if (lightingOn > 0) { OpenGL.glEnable(OpenGL.GL_COLOR_MATERIAL); OpenGL.glColorMaterial(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_DIFFUSE); } // Base colour is always white OpenGL.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Bind texture if (libOpenMayaNet.MAYA_API_VERSION >= 800) { MObject l_object = shapePath.node; MFnMesh mesh = new MFnMesh(l_object); String uvSetName = "map1"; MObjectArray textures = new MObjectArray(); boundTexture = false; mesh.getAssociatedUVSetTextures(uvSetName, textures); if (textures.length > 0) { MImageFileInfo.MHwTextureType hwType = new MImageFileInfo.MHwTextureType(); MHwTextureManager.glBind(textures[0], ref hwType); boundTexture = true; } if (!boundTexture) { OpenGL.glDisable(OpenGL.GL_TEXTURE_2D); OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, 0); } } else { // To get this code branch to compile, replace <change file name here> // with an appropriate file name if (id == 0) { MImage fileImage = new MImage(); fileImage.readFromFile("<change file name here>"); uint[] param = new uint[1]; OpenGL.glGenTextures(1, param); id = param[0]; OpenGL.glEnable(OpenGL.GL_TEXTURE_2D); OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, id); unsafe { uint width = 0, height = 0; fileImage.getSize(out width, out height); byte *pPixels = fileImage.pixels(); OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA8, (int)width, (int)height, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, pPixels); } } else { OpenGL.glEnable(OpenGL.GL_TEXTURE_2D); OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, id); } boundTexture = true; } if (boundTexture) { OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_REPEAT); OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_REPEAT); OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR); OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR); } OpenGL.glEnableClientState(OpenGL.GL_VERTEX_ARRAY); return; }
public override void glBind(MDagPath shapePath) { // ONLY push and pop required attributes performance reasons... // OpenGL.glPushAttrib(OpenGL.GL_LIGHTING_BIT); lightingOn = OpenGL.glIsEnabled(OpenGL.GL_LIGHTING); if (lightingOn > 0) { OpenGL.glEnable(OpenGL.GL_COLOR_MATERIAL); OpenGL.glColorMaterial(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_DIFFUSE); } // Base colour is always white OpenGL.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Bind texture if(libOpenMayaNet.MAYA_API_VERSION >= 800) { MObject l_object = shapePath.node; MFnMesh mesh = new MFnMesh(l_object); String uvSetName = "map1"; MObjectArray textures = new MObjectArray(); boundTexture = false; mesh.getAssociatedUVSetTextures(uvSetName, textures); if (textures.length > 0) { MImageFileInfo.MHwTextureType hwType = new MImageFileInfo.MHwTextureType(); MHwTextureManager.glBind(textures[0], ref hwType); boundTexture = true; } if( !boundTexture) { OpenGL.glDisable(OpenGL.GL_TEXTURE_2D); OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, 0); } } else { // To get this code branch to compile, replace <change file name here> // with an appropriate file name if (id == 0) { MImage fileImage = new MImage(); fileImage.readFromFile("<change file name here>"); uint[] param = new uint[1]; OpenGL.glGenTextures(1, param); id = param[0]; OpenGL.glEnable(OpenGL.GL_TEXTURE_2D); OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, id); unsafe { uint width = 0, height = 0; fileImage.getSize(out width, out height); byte* pPixels = fileImage.pixels(); OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA8, (int)width, (int)height, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, pPixels); } } else { OpenGL.glEnable(OpenGL.GL_TEXTURE_2D); OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, id); } boundTexture = true; } if( boundTexture) { OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_REPEAT); OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_REPEAT); OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR); OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR); } OpenGL.glEnableClientState(OpenGL.GL_VERTEX_ARRAY); return; }