fixed double-sided switch and only-selectable

doublesided switch in blender 2.9x did not work before, it was always
rendered single sided in MG.
I added a new switch only-selectable which allows to create unvisible
but selectable meshes. This helps with selection of small units which
can now have an unvisible  hand craftet select object around them for
example..
This commit is contained in:
titiger 2021-04-05 23:32:17 +02:00
parent d890e865dc
commit 3fcaa22d10
7 changed files with 33 additions and 10 deletions

View File

@ -7896,7 +7896,7 @@ vector<Unit *> Renderer::renderUnitsFast(bool renderingShadows, bool colorPickin
unitsList.push_back(unit); unitsList.push_back(unit);
} }
modelRenderer->render(model,rmSelection); modelRenderer->render(model,renderingShadows?rmShadows:rmSelection);
glPopMatrix(); glPopMatrix();

View File

@ -74,6 +74,7 @@ private:
bool customColor; bool customColor;
bool noSelect; bool noSelect;
bool glow; bool glow;
bool onlySelect;
uint32 textureFlags; uint32 textureFlags;
@ -136,6 +137,7 @@ public:
bool getCustomTexture() const {return customColor;} bool getCustomTexture() const {return customColor;}
bool getNoSelect() const {return noSelect;} bool getNoSelect() const {return noSelect;}
bool getGlow() const {return glow;} bool getGlow() const {return glow;}
bool getOnlySelect() const {return onlySelect;}
string getName() const {return name;} string getName() const {return name;}
uint32 getTextureFlags() const { return textureFlags; } uint32 getTextureFlags() const { return textureFlags; }

View File

@ -44,7 +44,8 @@ enum MeshPropertyFlag{
mpfCustomColor= 1, mpfCustomColor= 1,
mpfTwoSided= 2, mpfTwoSided= 2,
mpfNoSelect= 4, mpfNoSelect= 4,
mpfGlow= 8 mpfGlow= 8,
mpfOnlySelect= 16
}; };
enum MeshTexture{ enum MeshTexture{

View File

@ -21,6 +21,7 @@ namespace Shared{ namespace Graphics{
enum RenderMode{ enum RenderMode{
rmNormal, rmNormal,
rmSelection, rmSelection,
rmShadows,
renderModeCount renderModeCount
}; };

View File

@ -163,6 +163,11 @@ void ModelRendererGl::renderMesh(Mesh *mesh,int renderMode) {
{// don't render this and do nothing {// don't render this and do nothing
return; return;
} }
if(renderMode!=rmSelection){
if(mesh->getOnlySelect()) {
return;
}
}
//assertions //assertions
assertGl(); assertGl();

View File

@ -226,6 +226,7 @@ Mesh::Mesh() {
customColor= false; customColor= false;
noSelect= false; noSelect= false;
glow= false; glow= false;
onlySelect=false;
textureFlags=0; textureFlags=0;
@ -448,6 +449,7 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex
customColor= false; customColor= false;
noSelect= false; noSelect= false;
glow= false; glow= false;
onlySelect= false;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v2, this = %p Found meshHeader.hasTexture = %d, texName [%s] mtDiffuse = %d meshIndex = %d modelFile [%s]\n",this,meshHeader.hasTexture,toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(),mtDiffuse,meshIndex,modelFile.c_str()); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v2, this = %p Found meshHeader.hasTexture = %d, texName [%s] mtDiffuse = %d meshIndex = %d modelFile [%s]\n",this,meshHeader.hasTexture,toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(),mtDiffuse,meshIndex,modelFile.c_str());
@ -589,6 +591,7 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f,
customColor= (meshHeader.properties & mp3CustomColor) != 0; customColor= (meshHeader.properties & mp3CustomColor) != 0;
noSelect = false; noSelect = false;
glow = false; glow = false;
onlySelect=false;
textureFlags= 0; textureFlags= 0;
if((meshHeader.properties & mp3NoTexture) != mp3NoTexture) { if((meshHeader.properties & mp3NoTexture) != mp3NoTexture) {
@ -785,6 +788,7 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
twoSided= (meshHeader.properties & mpfTwoSided) != 0; twoSided= (meshHeader.properties & mpfTwoSided) != 0;
noSelect= (meshHeader.properties & mpfNoSelect) != 0; noSelect= (meshHeader.properties & mpfNoSelect) != 0;
glow= (meshHeader.properties & mpfGlow) != 0; glow= (meshHeader.properties & mpfGlow) != 0;
onlySelect= (meshHeader.properties & mpfOnlySelect) != 0;
//material //material
diffuseColor= Vec3f(meshHeader.diffuseColor); diffuseColor= Vec3f(meshHeader.diffuseColor);
@ -916,6 +920,9 @@ void Mesh::save(int meshIndex, const string &dir, FILE *f, TextureManager *textu
if(glow) { if(glow) {
meshHeader.properties |= mpfGlow; meshHeader.properties |= mpfGlow;
} }
if(onlySelect){
meshHeader.properties|= mpfOnlySelect;
}
meshHeader.textures = textureFlags; meshHeader.textures = textureFlags;
fwrite(&meshHeader, sizeof(MeshHeader), 1, f); fwrite(&meshHeader, sizeof(MeshHeader), 1, f);
@ -1550,6 +1557,7 @@ void Mesh::copyInto(Mesh *dest, bool ignoreInterpolationData,
dest->customColor = this->customColor; dest->customColor = this->customColor;
dest->noSelect = this->noSelect; dest->noSelect = this->noSelect;
dest->glow = this->glow; dest->glow = this->glow;
dest->onlySelect = this->onlySelect;
dest->textureFlags = this->textureFlags; dest->textureFlags = this->textureFlags;

View File

@ -255,6 +255,7 @@ class G3DMeshHeaderv4: # Read Meshheader
self.istwosided = bool(self.properties & 2) self.istwosided = bool(self.properties & 2)
self.noselect = bool(self.properties & 4) self.noselect = bool(self.properties & 4)
self.glow = bool(self.properties & 8) self.glow = bool(self.properties & 8)
self.onlySelect = bool(self.properties & 16)
self.hastexture = False self.hastexture = False
self.diffusetexture = None self.diffusetexture = None
@ -432,14 +433,15 @@ def createMesh(filename, header, data, toblender, operator):
mesh.polygons.foreach_set( mesh.polygons.foreach_set(
"use_smooth", (True,)*len(mesh.polygons.data.polygons)) "use_smooth", (True,)*len(mesh.polygons.data.polygons))
mesh.g3d_customColor = header.customalpha mesh.g3d_customColor = header.customalpha
# mesh.show_double_sided = header.istwosided mesh.show_double_sided = header.istwosided
if header.isv4: if header.isv4:
mesh.g3d_noSelect = header.noselect mesh.g3d_noSelect = header.noselect
mesh.g3d_glow = header.glow mesh.g3d_glow = header.glow
mesh.g3d_onlySelect = header.onlySelect
else: else:
mesh.g3d_noSelect = False mesh.g3d_noSelect = False
mesh.glow = False mesh.glow = False
mesh.g3d_fullyOpaque = False #mesh.g3d_onlySelect = False
# =================================================================================================== # ===================================================================================================
# Material Setup # Material Setup
@ -895,11 +897,15 @@ def G3DSaver(filepath, context, toglest, operator):
properties |= 2 properties |= 2
except Exception as e: except Exception as e:
print("No material, backface culling not set: ", e) print("No material, backface culling not set: ", e)
if mesh.show_double_sided:
properties |= 2
if mesh.g3d_noSelect: if mesh.g3d_noSelect:
properties |= 4 properties |= 4
if mesh.g3d_glow: if mesh.g3d_glow:
properties |= 8 properties |= 8
if mesh.g3d_onlySelect:
properties |= 16
#MeshData #MeshData
vertices = [] vertices = []
@ -932,7 +938,7 @@ def G3DSaver(filepath, context, toglest, operator):
context.scene.frame_set(fcurrent) context.scene.frame_set(fcurrent)
if mesh.g3d_fullyOpaque: if mesh.g3d_onlySelect:
opacity = 1.0 opacity = 1.0
# MeshHeader # MeshHeader
@ -987,7 +993,7 @@ class G3DPanel(bpy.types.Panel):
"show_double_sided", "show_double_sided",
text="double sided") text="double sided")
self.layout.prop(context.object.data, "g3d_noSelect") self.layout.prop(context.object.data, "g3d_noSelect")
self.layout.prop(context.object.data, "g3d_fullyOpaque") self.layout.prop(context.object.data, "g3d_onlySelect")
self.layout.prop(context.object.data, "g3d_glow") self.layout.prop(context.object.data, "g3d_glow")
@ -1094,9 +1100,9 @@ def register():
description="replace alpha channel of texture with team color") description="replace alpha channel of texture with team color")
bpy.types.Mesh.g3d_noSelect = bpy.props.BoolProperty( bpy.types.Mesh.g3d_noSelect = bpy.props.BoolProperty(
name="non-selectable", description="click on mesh doesn't select unit") name="non-selectable", description="click on mesh doesn't select unit")
bpy.types.Mesh.g3d_fullyOpaque = bpy.props.BoolProperty( bpy.types.Mesh.g3d_onlySelect = bpy.props.BoolProperty(
name="fully opaque", name="only-selectable",
description="sets opacity to 1.0, ignoring what's set in materials") description="this mesh is not visible, only selectable")
bpy.types.Mesh.g3d_glow = bpy.props.BoolProperty( bpy.types.Mesh.g3d_glow = bpy.props.BoolProperty(
name="glow", description="let objects glow like particles") name="glow", description="let objects glow like particles")
bpy.types.Mesh.show_double_sided = bpy.props.BoolProperty( bpy.types.Mesh.show_double_sided = bpy.props.BoolProperty(