private IStdUVGen _exportUV(IStdUVGen uvGen, BabylonTexture babylonTexture) { switch (uvGen.GetCoordMapping(0)) { case 1: //MAP_SPHERICAL babylonTexture.coordinatesMode = 1; break; case 2: //MAP_PLANAR babylonTexture.coordinatesMode = 2; break; default: babylonTexture.coordinatesMode = 0; break; } babylonTexture.coordinatesIndex = uvGen.MapChannel - 1; if (uvGen.MapChannel > 2) { RaiseWarning(string.Format("Unsupported map channel, Only channel 1 and 2 are supported."), 2); } babylonTexture.uOffset = uvGen.GetUOffs(0); babylonTexture.vOffset = uvGen.GetVOffs(0); babylonTexture.uScale = uvGen.GetUScl(0); babylonTexture.vScale = uvGen.GetVScl(0); if (Path.GetExtension(babylonTexture.name).ToLower() == ".dds") { babylonTexture.vScale *= -1; // Need to invert Y-axis for DDS texture } babylonTexture.uAng = uvGen.GetUAng(0); babylonTexture.vAng = uvGen.GetVAng(0); babylonTexture.wAng = uvGen.GetWAng(0); babylonTexture.wrapU = BabylonTexture.AddressMode.CLAMP_ADDRESSMODE; // CLAMP if ((uvGen.TextureTiling & 1) != 0) // WRAP { babylonTexture.wrapU = BabylonTexture.AddressMode.WRAP_ADDRESSMODE; } else if ((uvGen.TextureTiling & 4) != 0) // MIRROR { babylonTexture.wrapU = BabylonTexture.AddressMode.MIRROR_ADDRESSMODE; } babylonTexture.wrapV = BabylonTexture.AddressMode.CLAMP_ADDRESSMODE; // CLAMP if ((uvGen.TextureTiling & 2) != 0) // WRAP { babylonTexture.wrapV = BabylonTexture.AddressMode.WRAP_ADDRESSMODE; } else if ((uvGen.TextureTiling & 8) != 0) // MIRROR { babylonTexture.wrapV = BabylonTexture.AddressMode.MIRROR_ADDRESSMODE; } return(uvGen); }
private IStdUVGen _exportUV(IStdUVGen uvGen, BabylonTexture babylonTexture) { switch (uvGen.GetCoordMapping(0)) { case 1: //MAP_SPHERICAL babylonTexture.coordinatesMode = BabylonTexture.CoordinatesMode.SPHERICAL_MODE; break; case 2: //MAP_PLANAR babylonTexture.coordinatesMode = BabylonTexture.CoordinatesMode.PLANAR_MODE; break; default: babylonTexture.coordinatesMode = BabylonTexture.CoordinatesMode.EXPLICIT_MODE; break; } babylonTexture.coordinatesIndex = uvGen.MapChannel - 1; if (uvGen.MapChannel > 2) { RaiseWarning(string.Format("Unsupported map channel, Only channel 1 and 2 are supported."), 3); } babylonTexture.uOffset = uvGen.GetUOffs(0); babylonTexture.vOffset = -uvGen.GetVOffs(0); babylonTexture.uScale = uvGen.GetUScl(0); babylonTexture.vScale = uvGen.GetVScl(0); var offset = new BabylonVector3(babylonTexture.uOffset, -babylonTexture.vOffset, 0); var scale = new BabylonVector3(babylonTexture.uScale, babylonTexture.vScale, 1); var rotationEuler = new BabylonVector3(uvGen.GetUAng(0), uvGen.GetVAng(0), uvGen.GetWAng(0)); var rotation = BabylonQuaternion.FromEulerAngles(rotationEuler.X, rotationEuler.Y, rotationEuler.Z); var pivotCenter = new BabylonVector3(-0.5f, -0.5f, 0); var transformMatrix = MathUtilities.ComputeTextureTransformMatrix(pivotCenter, offset, rotation, scale); transformMatrix.decompose(scale, rotation, offset); var texTransformRotationEuler = rotation.toEulerAngles(); babylonTexture.uOffset = -offset.X; babylonTexture.vOffset = -offset.Y; babylonTexture.uScale = scale.X; babylonTexture.vScale = -scale.Y; babylonTexture.uRotationCenter = 0.0f; babylonTexture.vRotationCenter = 0.0f; babylonTexture.invertY = false; babylonTexture.uAng = texTransformRotationEuler.X; babylonTexture.vAng = texTransformRotationEuler.Y; babylonTexture.wAng = texTransformRotationEuler.Z; if (Path.GetExtension(babylonTexture.name).ToLower() == ".dds") { babylonTexture.vScale *= -1; // Need to invert Y-axis for DDS texture } if (babylonTexture.wAng != 0f && (babylonTexture.uScale != 1f || babylonTexture.vScale != 1f) && (Math.Abs(babylonTexture.uScale) - Math.Abs(babylonTexture.vScale)) > float.Epsilon) { RaiseWarning("Rotation and non-uniform tiling (scale) on a texture is not supported as it will cause texture shearing. You can use the map UV of the mesh for those transformations.", 3); } babylonTexture.wrapU = BabylonTexture.AddressMode.CLAMP_ADDRESSMODE; // CLAMP if ((uvGen.TextureTiling & 1) != 0) // WRAP { babylonTexture.wrapU = BabylonTexture.AddressMode.WRAP_ADDRESSMODE; } else if ((uvGen.TextureTiling & 4) != 0) // MIRROR { babylonTexture.wrapU = BabylonTexture.AddressMode.MIRROR_ADDRESSMODE; } babylonTexture.wrapV = BabylonTexture.AddressMode.CLAMP_ADDRESSMODE; // CLAMP if ((uvGen.TextureTiling & 2) != 0) // WRAP { babylonTexture.wrapV = BabylonTexture.AddressMode.WRAP_ADDRESSMODE; } else if ((uvGen.TextureTiling & 8) != 0) // MIRROR { babylonTexture.wrapV = BabylonTexture.AddressMode.MIRROR_ADDRESSMODE; } return(uvGen); }
private IStdUVGen _exportUV(IStdUVGen uvGen, BabylonTexture babylonTexture) { switch (uvGen.GetCoordMapping(0)) { case 1: //MAP_SPHERICAL babylonTexture.coordinatesMode = BabylonTexture.CoordinatesMode.SPHERICAL_MODE; break; case 2: //MAP_PLANAR babylonTexture.coordinatesMode = BabylonTexture.CoordinatesMode.PLANAR_MODE; break; default: babylonTexture.coordinatesMode = BabylonTexture.CoordinatesMode.EXPLICIT_MODE; break; } babylonTexture.coordinatesIndex = uvGen.MapChannel - 1; if (uvGen.MapChannel > 2) { RaiseWarning(string.Format("Unsupported map channel, Only channel 1 and 2 are supported."), 3); } babylonTexture.uOffset = -uvGen.GetUOffs(0); babylonTexture.vOffset = -uvGen.GetVOffs(0); babylonTexture.uScale = uvGen.GetUScl(0); babylonTexture.vScale = uvGen.GetVScl(0); if (Path.GetExtension(babylonTexture.name).ToLower() == ".dds") { babylonTexture.vScale *= -1; // Need to invert Y-axis for DDS texture } babylonTexture.uAng = uvGen.GetUAng(0); babylonTexture.vAng = uvGen.GetVAng(0); babylonTexture.wAng = uvGen.GetWAng(0); // Fix offset according to the rotation // 3DS Max and babylon don't use the same origin for the rotation if (babylonTexture.wAng != 0f) { var angle = -babylonTexture.wAng; var cos = (float)Math.Cos(angle); var sin = (float)Math.Sin(angle); var u = babylonTexture.uOffset; var v = babylonTexture.vOffset; // uOffset babylonTexture.uOffset = u * cos; babylonTexture.vOffset = u * -sin; // vOffset babylonTexture.uOffset += v * sin; babylonTexture.vOffset += v * cos; // rotation babylonTexture.uOffset -= sin; babylonTexture.vOffset -= cos; } // Fix offset according to the scale // 3DS Max keep the tiling symmetrical if (babylonTexture.uScale != 0f) { babylonTexture.uOffset += (1f - babylonTexture.uScale) / 2f; } if (babylonTexture.vScale != 0f) { babylonTexture.vOffset += (1f - babylonTexture.vScale) * 1.5f; } // TODO - rotation and scale if (babylonTexture.wAng != 0f && (babylonTexture.uScale != 1f || babylonTexture.vScale != 1f)) { RaiseWarning("Rotation and tiling (scale) on a texture are only supported separatly. You can use the map UV of the mesh for those transformation.", 3); } babylonTexture.wrapU = BabylonTexture.AddressMode.CLAMP_ADDRESSMODE; // CLAMP if ((uvGen.TextureTiling & 1) != 0) // WRAP { babylonTexture.wrapU = BabylonTexture.AddressMode.WRAP_ADDRESSMODE; } else if ((uvGen.TextureTiling & 4) != 0) // MIRROR { babylonTexture.wrapU = BabylonTexture.AddressMode.MIRROR_ADDRESSMODE; } babylonTexture.wrapV = BabylonTexture.AddressMode.CLAMP_ADDRESSMODE; // CLAMP if ((uvGen.TextureTiling & 2) != 0) // WRAP { babylonTexture.wrapV = BabylonTexture.AddressMode.WRAP_ADDRESSMODE; } else if ((uvGen.TextureTiling & 8) != 0) // MIRROR { babylonTexture.wrapV = BabylonTexture.AddressMode.MIRROR_ADDRESSMODE; } return(uvGen); }