Skip to content

Commit

Permalink
Small clean-up for models with negative scales (#1083)
Browse files Browse the repository at this point in the history
* consistent spaces

* delete obsolete note regarding cesium
  • Loading branch information
tkazik committed Jun 8, 2023
1 parent d2469cd commit 17f481b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 33 deletions.
Expand Up @@ -37,7 +37,7 @@ partial class BabylonExporter
#if MAX2022 || MAX2023
ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand("obj = maxOps.getNodeByHandle " + gameNode.MaxNode.Handle + ";", ManagedServices.MaxscriptSDK.ScriptSource.NotSpecified);
#else
ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand("obj = maxOps.getNodeByHandle " + gameNode.MaxNode.Handle + ";");
ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand("obj = maxOps.getNodeByHandle " + gameNode.MaxNode.Handle + ";");
#endif

return _ExportExtraAttributes(gameNode.IGameObject.IPropertyContainer, babylonScene, excludeAttributes);
Expand Down
4 changes: 1 addition & 3 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.ExportItem.cs
Expand Up @@ -113,7 +113,7 @@ public bool KeepPosition
}
}

const char s_PropertySeparator = ';';
const char s_PropertySeparator = ';';
private const char s_ProperyLayerSeparator = '~';
const string s_PropertyFormat = "{0};{1};{2};{3};{4}";
const string s_PropertyNamePrefix = "babylonjs_ExportItem";
Expand Down Expand Up @@ -282,11 +282,9 @@ public void LoadFromData(string propertyName)
{
throw new Exception("Invalid property name, can't deserialize.");
}


string itemGuidStr = propertyName.Remove(0, s_PropertyNamePrefix.Length);


if (!Guid.TryParse(itemGuidStr, out itemGuid))
{
Loader.Core.PushPrompt("Error: Invalid ID, can't deserialize.");
Expand Down
18 changes: 9 additions & 9 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.Material.Pbr.cs
Expand Up @@ -45,7 +45,7 @@ public PbrMetalRoughDecorator(IIGameMaterial node) : base(node)
public ITexmap MetalnessMap => _getTexMap(_node, "metalness_map");
public float Roughness => Properties?.GetFloatProperty("roughness", 0) ?? 0;
public ITexmap RoughnessMap => _getTexMap(_node, "roughness_map");
}
}

public class PbrSpecGlossDecorator : PbrGameMaterialDecorator
{
Expand Down Expand Up @@ -290,14 +290,14 @@ private void ExportPbrSpecGlossMaterial(IIGameMaterial materialNode, BabylonScen
// the target material
var babylonMaterial = new BabylonPBRSpecularGlossinessMaterial(maxDecorator.Id)
{
maxGameMaterial = materialNode,
name = maxDecorator.Name,
backFaceCulling = babylonDecorator.BackFaceCulling,
doubleSided = !babylonDecorator.BackFaceCulling,
separateCullingPass = babylonDecorator.SeparateCullingPass,
isUnlit = babylonDecorator.IsUnlit,
baseColor = maxDecorator.BaseColor.ToArray(),
};
maxGameMaterial = materialNode,
name = maxDecorator.Name,
backFaceCulling = babylonDecorator.BackFaceCulling,
doubleSided = !babylonDecorator.BackFaceCulling,
separateCullingPass = babylonDecorator.SeparateCullingPass,
isUnlit = babylonDecorator.IsUnlit,
baseColor = maxDecorator.BaseColor.ToArray(),
};

// --- Global ---
if (babylonMaterial.isUnlit)
Expand Down
3 changes: 1 addition & 2 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.Material.cs
Expand Up @@ -406,7 +406,7 @@ private void ExportStandardMaterial(IIGameMaterial materialNode, IIPropertyConta
{
babylonMaterial.opacityFresnelParameters = fresnelParameters;
if (babylonMaterial.alpha == 1 &&
babylonMaterial.opacityTexture == null)
babylonMaterial.opacityTexture == null)
{
babylonMaterial.alpha = 0;
}
Expand Down Expand Up @@ -589,7 +589,6 @@ private void ExportPhysicalMaterial(IIGameMaterial materialNode, IIPropertyConta
babylonMaterial.roughness = 1 - babylonMaterial.roughness;
}


// Self illumination is computed from emission color, luminance, temperature and weight
babylonMaterial.emissive = materialNode.MaxMaterial.GetSelfIllumColorOn(0, false)
? materialNode.MaxMaterial.GetSelfIllumColor(0, false).Scale(selfIllumScale).ToArray()
Expand Down
9 changes: 2 additions & 7 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs
Expand Up @@ -1021,11 +1021,6 @@ private void ExtractFace(IIGameSkin skin, IIGameMesh unskinnedMesh, BabylonAbstr
{
int a, b, c;
// parity is TRUE, if determinant negative ( counter-intuitive convention of 3ds max, see docs... :/ )

// fix for cesium: currently, cesium does not expect a reversed winding order for negative scales
//if (false)

// for threejs and babylonjs (handle negative scales correctly (reversed winding order expected)
if (invertedWorldMatrix.Parity)
{
// flipped case: reverse winding order
Expand Down Expand Up @@ -1380,7 +1375,7 @@ private float GetW(IPoint3 normal, IPoint3 tangent, IPoint3 bitangent)
{
return 1;
}

float nx = MathUtilities.RoundToIfAlmostEqualTo(normal.X, 0, Tools.Epsilon);
float ny = MathUtilities.RoundToIfAlmostEqualTo(normal.Y, 0, Tools.Epsilon);
float nz = MathUtilities.RoundToIfAlmostEqualTo(normal.Z, 0, Tools.Epsilon);
Expand All @@ -1393,7 +1388,7 @@ private float GetW(IPoint3 normal, IPoint3 tangent, IPoint3 bitangent)

// theorical bittangent
MathUtilities.CrossProduct(nx, ny, nz, tx, ty, tz, out float x, out float y, out float z);

// Speaking in broadest terms, if the dot product of two non-zero vectors is positive,
// then the two vectors point in the same general direction, meaning less than 90 degrees.
// If the dot product is negative, then the two vectors point in opposite directions,
Expand Down
6 changes: 2 additions & 4 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.Texture.cs
Expand Up @@ -546,7 +546,7 @@ private BabylonTexture ExportSpecularGlossinessTexture(float[] specularColor, IT
{
var specularTexture = _getBitmapTex(specularTexMap);
var glossinessTexture = _getBitmapTex(glossinessTexMap);

// we are trying to get the best output format, function of source and policy.
var paths = new IBitmapTex[] { specularTexture, glossinessTexture}.Where(t => t != null).Select(t => t.Map.FileName);
var policy = exportParameters.textureFormatExportPolicy;
Expand Down Expand Up @@ -1217,8 +1217,6 @@ private IStdUVGen _exportUV(IStdUVGen uvGen, BabylonTexture babylonTexture)
RaiseMessage(MaxTextureTransformToString(uvGen));
#endif



var offset = new BabylonVector3(uvGen.GetUOffs(0), uvGen.GetVOffs(0), 0);
var scale = new BabylonVector3(uvGen.GetUScl(0), uvGen.GetVScl(0), 1);
//max rotation is horlogic, here we move using trigonometric, so anti - horlogic
Expand Down Expand Up @@ -1257,7 +1255,7 @@ private IStdUVGen _exportUV(IStdUVGen uvGen, BabylonTexture babylonTexture)
var translateBack = BabylonMatrix.Translation(center);
var t = translateToOrigin * scaling * rotate * translateBack ;
offset = origin * t;
}
}

babylonTexture.uOffset = offset.X%1;
babylonTexture.vOffset = (1 - offset.Y) % 1;
Expand Down
12 changes: 6 additions & 6 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.cs
Expand Up @@ -175,8 +175,8 @@ public void BakeAnimationsFrame(IINode node,BakeAnimationType bakeAnimationType)
tmp = Point()
--store anim to a point
for t = animationRange.start to animationRange.end do (
with animate on at time t tmp.transform = obj.transform
)
with animate on at time t tmp.transform = obj.transform
)
--remove constraint on original object
obj.pos.controller = Position_XYZ ()
Expand All @@ -186,11 +186,11 @@ public void BakeAnimationsFrame(IINode node,BakeAnimationType bakeAnimationType)
--copy back anim from point
for t = animationRange.start to animationRange.end do (
with animate on at time t obj.transform = tmp.transform
)
with animate on at time t obj.transform = tmp.transform
)
delete tmp
)
");
");
}

public void ExportClosedContainers()
Expand Down Expand Up @@ -333,7 +333,7 @@ public void Export(MaxExportParameters exportParameters)

var rawScene = Loader.Core.RootNode;

string outputFormat = exportParameters.outputFormat;
string outputFormat = exportParameters.outputFormat;
isBabylonExported = outputFormat == "babylon" || outputFormat == "binary babylon";
isGltfExported = outputFormat == "gltf" || outputFormat == "glb";

Expand Down
1 change: 0 additions & 1 deletion 3ds Max/Max2Babylon/Exporter/GlobalVertex.cs
Expand Up @@ -37,7 +37,6 @@ public GlobalVertex(GlobalVertex other)

public override int GetHashCode()
{

//return string.Format("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}-{8}-{9}",
// BaseIndex,
// CurrentIndex,
Expand Down

0 comments on commit 17f481b

Please sign in to comment.