-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add allowHomonymObjectName option for OBJModel.ModelSettings #9047
base: 1.19.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -57,6 +57,7 @@ public ObjModel read(JsonObject jsonObject, JsonDeserializationContext deseriali | |||||
boolean flipV = GsonHelper.getAsBoolean(jsonObject, "flip_v", false); | ||||||
boolean emissiveAmbient = GsonHelper.getAsBoolean(jsonObject, "emissive_ambient", true); | ||||||
String mtlOverride = GsonHelper.getAsString(jsonObject, "mtl_override", null); | ||||||
boolean allowHomonymObjectName = GsonHelper.getAsBoolean(jsonObject,"allow_homonym_object_name",false); | ||||||
|
||||||
// TODO: Deprecated names. To be removed in 1.20 | ||||||
var deprecationWarningsBuilder = ImmutableMap.<String, String>builder(); | ||||||
|
@@ -86,7 +87,7 @@ public ObjModel read(JsonObject jsonObject, JsonDeserializationContext deseriali | |||||
deprecationWarningsBuilder.put("materialLibraryOverride", "mtl_override"); | ||||||
} | ||||||
|
||||||
return loadModel(new ObjModel.ModelSettings(new ResourceLocation(modelLocation), automaticCulling, shadeQuads, flipV, emissiveAmbient, mtlOverride), deprecationWarningsBuilder.build()); | ||||||
return loadModel(new ObjModel.ModelSettings(new ResourceLocation(modelLocation), automaticCulling, shadeQuads, flipV, emissiveAmbient, mtlOverride,allowHomonymObjectName), deprecationWarningsBuilder.build()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting: spaces after commas.
Suggested change
|
||||||
} | ||||||
|
||||||
public ObjModel loadModel(ObjModel.ModelSettings settings) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -108,6 +108,8 @@ static ObjModel parse(ObjTokenizer tokenizer, ModelSettings settings, Map<String | |||||
{ | ||||||
var modelLocation = settings.modelLocation; | ||||||
var materialLibraryOverrideLocation = settings.mtlOverride; | ||||||
var allowHomonymObjectName = settings.allowHomonymObjectName; | ||||||
var hasHomonymObjectNameAppeared = false; | ||||||
var model = new ObjModel(settings, deprecationWarnings); | ||||||
|
||||||
// for relative references to material libraries | ||||||
|
@@ -280,6 +282,21 @@ static ObjModel parse(ObjTokenizer tokenizer, ModelSettings settings, Map<String | |||||
case "o": | ||||||
{ | ||||||
String name = line[1]; | ||||||
if (model.parts.containsKey(name)) | ||||||
{ | ||||||
hasHomonymObjectNameAppeared = true; | ||||||
if (allowHomonymObjectName) | ||||||
{ | ||||||
int suffixNum = 0; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should begin this at 1 instead, so the names would be: |
||||||
String renamed; | ||||||
do | ||||||
{ | ||||||
renamed = name + '_' + (suffixNum++); | ||||||
} | ||||||
while (model.parts.containsKey(renamed)); | ||||||
name = renamed; | ||||||
} | ||||||
} | ||||||
if (objAboveGroup || currentGroup == null) | ||||||
{ | ||||||
objAboveGroup = true; | ||||||
|
@@ -299,6 +316,10 @@ static ObjModel parse(ObjTokenizer tokenizer, ModelSettings settings, Map<String | |||||
} | ||||||
} | ||||||
} | ||||||
if (!allowHomonymObjectName && hasHomonymObjectNameAppeared) | ||||||
{ | ||||||
LOGGER.error("find homonym object in obj model:" + settings.modelLocation + ", use allow_homonym_object_name=true can rename them for you"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some error message cleanup, as well as using logger parameter substitution instead of manual string concatenation:
Suggested change
|
||||||
} | ||||||
return model; | ||||||
} | ||||||
|
||||||
|
@@ -687,6 +708,6 @@ public void bake(CompositeRenderable.PartBuilder<?> builder, IGeometryBakingCont | |||||
|
||||||
public record ModelSettings(@NotNull ResourceLocation modelLocation, | ||||||
boolean automaticCulling, boolean shadeQuads, boolean flipV, | ||||||
boolean emissiveAmbient, @Nullable String mtlOverride) | ||||||
boolean emissiveAmbient, @Nullable String mtlOverride, boolean allowHomonymObjectName) | ||||||
{ } | ||||||
Comment on lines
709
to
712
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking change because any callers to the previous constructor (without the new parameter) will break. Please add a new constructor to this record which calls the canonical constructor with an appropriate default value for the new parameter, mark that new constructor as deprecated for removal ( |
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting: spaces after commas.