do not convert mesh if instanced

This commit is contained in:
4sval
2022-09-19 06:39:19 +02:00
parent 7cff932a81
commit 656e1908f2
4 changed files with 41 additions and 42 deletions

View File

@@ -86,7 +86,8 @@ void main()
vec3 reflect_direction = reflect(-n_light_direction, n_normal_map); vec3 reflect_direction = reflect(-n_light_direction, n_normal_map);
float metallic = pow(max(dot(n_view_direction, reflect_direction), 0.0f), material.metallic_value); float metallic = pow(max(dot(n_view_direction, reflect_direction), 0.0f), material.metallic_value);
vec3 specular_map = vec3(texture(material.specularMap, fTexCoords)); vec3 specular_map = vec3(texture(material.specularMap, fTexCoords));
result += light.specular * metallic * specular_map.b * material.roughness_value * specular_map.g * specular_map.r; result += specular_map.r * light.specular * (metallic * specular_map.b);
result += material.roughness_value * specular_map.g;
} }
// emission // emission

View File

@@ -228,8 +228,8 @@ public class Section : IDisposable
} }
} }
Parameters.RoughnessValue = 1;
Parameters.MetallicValue = 1; Parameters.MetallicValue = 1;
Parameters.RoughnessValue = 0;
} }
public void Bind(Shader shader, uint instanceCount) public void Bind(Shader shader, uint instanceCount)

View File

@@ -97,20 +97,20 @@ public class Snooper
{ {
switch (export) switch (export)
{ {
case UStaticMesh st when st.TryConvert(out var mesh): case UStaticMesh st:
{ {
var guid = st.LightingGuid; var guid = st.LightingGuid;
if (!_models.TryGetValue(guid, out _)) if (!_models.TryGetValue(guid, out _) && st.TryConvert(out var mesh))
{ {
_models[guid] = new Model(export, st.Name, st.ExportType, mesh.LODs[0], mesh.LODs[0].Verts); _models[guid] = new Model(export, st.Name, st.ExportType, mesh.LODs[0], mesh.LODs[0].Verts);
SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO); SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO);
} }
break; break;
} }
case USkeletalMesh sk when sk.TryConvert(out var mesh): case USkeletalMesh sk:
{ {
var guid = Guid.NewGuid(); var guid = Guid.NewGuid();
if (!_models.TryGetValue(guid, out _)) if (!_models.TryGetValue(guid, out _) && sk.TryConvert(out var mesh))
{ {
_models[guid] = new Model(export, sk.Name, sk.ExportType, mesh.LODs[0], mesh.LODs[0].Verts, sk.MorphTargets, mesh.RefSkeleton); _models[guid] = new Model(export, sk.Name, sk.ExportType, mesh.LODs[0], mesh.LODs[0].Verts, sk.MorphTargets, mesh.RefSkeleton);
SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO); SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO);
@@ -137,13 +137,10 @@ public class Snooper
staticMeshComponent.Load() is not { } staticMeshComp) continue; staticMeshComponent.Load() is not { } staticMeshComp) continue;
if (!staticMeshComp.TryGetValue(out FPackageIndex staticMesh, "StaticMesh") && actor.Class is UBlueprintGeneratedClass) if (!staticMeshComp.TryGetValue(out FPackageIndex staticMesh, "StaticMesh") && actor.Class is UBlueprintGeneratedClass)
{
foreach (var actorExp in actor.Class.Owner.GetExports()) foreach (var actorExp in actor.Class.Owner.GetExports())
if (actorExp.TryGetValue(out staticMesh, "StaticMesh")) if (actorExp.TryGetValue(out staticMesh, "StaticMesh"))
break; break;
} if (staticMesh?.Load() is not UStaticMesh m)
if (staticMesh?.Load() is not UStaticMesh m || !m.TryConvert(out var mesh))
continue; continue;
var guid = m.LightingGuid; var guid = m.LightingGuid;
@@ -153,46 +150,47 @@ public class Snooper
Rotation = staticMeshComp.GetOrDefault("RelativeRotation", FRotator.ZeroRotator), Rotation = staticMeshComp.GetOrDefault("RelativeRotation", FRotator.ZeroRotator),
Scale = staticMeshComp.GetOrDefault("RelativeScale3D", FVector.OneVector) Scale = staticMeshComp.GetOrDefault("RelativeScale3D", FVector.OneVector)
}; };
// can't seem to find the problem here
// some meshes should have their yaw reversed and others not
transform.Rotation.Yaw = -transform.Rotation.Yaw; transform.Rotation.Yaw = -transform.Rotation.Yaw;
if (_models.TryGetValue(guid, out var model)) if (_models.TryGetValue(guid, out var model))
{ {
model.AddInstance(transform); model.AddInstance(transform);
continue;
} }
else if (m.TryConvert(out var mesh))
model = new Model(export, m.Name, m.ExportType, mesh.LODs[0], mesh.LODs[0].Verts, null, null, transform);
if (actor.TryGetAllValues(out FPackageIndex[] textureData, "TextureData"))
{ {
for (int j = 0; j < textureData.Length; j++) model = new Model(export, m.Name, m.ExportType, mesh.LODs[0], mesh.LODs[0].Verts, null, null, transform);
{
if (textureData[j].Load() is not { } textureDataIdx)
continue;
if (textureDataIdx.TryGetValue(out FPackageIndex diffuse, "Diffuse") && if (actor.TryGetAllValues(out FPackageIndex[] textureData, "TextureData"))
diffuse.Load() is UTexture2D diffuseTexture)
model.Sections[j].Parameters.Diffuse = diffuseTexture;
if (textureDataIdx.TryGetValue(out FPackageIndex normal, "Normal") &&
normal.Load() is UTexture2D normalTexture)
model.Sections[j].Parameters.Normal = normalTexture;
if (textureDataIdx.TryGetValue(out FPackageIndex specular, "Specular") &&
specular.Load() is UTexture2D specularTexture)
model.Sections[j].Parameters.Specular = specularTexture;
}
}
if (staticMeshComp.TryGetValue(out FPackageIndex[] overrideMaterials, "OverrideMaterials"))
{
var max = model.Sections.Length - 1;
for (var j = 0; j < overrideMaterials.Length; j++)
{ {
if (j > max) break; for (int j = 0; j < textureData.Length; j++)
if (overrideMaterials[j].Load() is not UMaterialInterface unrealMaterial) continue; {
model.Sections[j].SwapMaterial(unrealMaterial); if (textureData[j].Load() is not { } textureDataIdx)
} continue;
}
_models[guid] = model; if (textureDataIdx.TryGetValue(out FPackageIndex diffuse, "Diffuse") &&
diffuse.Load() is UTexture2D diffuseTexture)
model.Sections[j].Parameters.Diffuse = diffuseTexture;
if (textureDataIdx.TryGetValue(out FPackageIndex normal, "Normal") &&
normal.Load() is UTexture2D normalTexture)
model.Sections[j].Parameters.Normal = normalTexture;
if (textureDataIdx.TryGetValue(out FPackageIndex specular, "Specular") &&
specular.Load() is UTexture2D specularTexture)
model.Sections[j].Parameters.Specular = specularTexture;
}
}
if (staticMeshComp.TryGetValue(out FPackageIndex[] overrideMaterials, "OverrideMaterials"))
{
var max = model.Sections.Length - 1;
for (var j = 0; j < overrideMaterials.Length; j++)
{
if (j > max) break;
if (overrideMaterials[j].Load() is not UMaterialInterface unrealMaterial) continue;
model.Sections[j].SwapMaterial(unrealMaterial);
}
}
_models[guid] = model;
}
} }
_camera = new Camera(new Vector3(0f, 5f, 5f), Vector3.Zero, 0.01f, 1000f, 5f); _camera = new Camera(new Vector3(0f, 5f, 5f), Vector3.Zero, 0.01f, 1000f, 5f);
break; break;