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
Fixed bugs and added an experimental prefab export operator #49
Conversation
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.
Thanks for making a proper PR. Please have a look at my comments
@@ -664,6 +665,11 @@ def createSubMesh(blenderFacesWithRelativeVertexIndices, blenderMesh, blenderMes | |||
|
|||
Face(md5SubMesh, md5VerticesOfFace[0], md5VerticesOfFace[1], md5VerticesOfFace[2]) | |||
|
|||
def checkPath(filePath):#python does not create directory just the file. This function added to create t eh directory |
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.
In python methods get documented by adding a string as first statement in the method.
>>> def test(a):
... """This is the documentation"""
... return 5
...
>>> test.__doc__
'This is the documentation'
If you use """ to specify the string you can also have a string contain line breaks.
Besides that I would suggest to use a better method name. checkPath sounds like a function that checks if a path exists and does nothing otherwise. I would suggest to name the method createDirectoryForFileIfMissing
Also dir
is a build in python method and thus a different variable name should be used. The method dir
lists what attributes an object has. So it is a very helpful method for figuring out what attributes and methods an object has
@@ -801,26 +807,35 @@ def treat_bone(b, parent = None): | |||
for mesh in range (1, len(meshes)): | |||
for submesh in meshes[mesh].submeshes: | |||
submesh.bindtomesh(meshes[0]) | |||
checkPath(modelFilePath)#python does not create directory just the file. This function added to create t eh directory |
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.
Comment should not be necesary once the method has a proper name. Also there is a typo in it that you could fix in the methods documentation.
errmsg = "IOError " #%s: %s" % (errno, strerror) | ||
except Exception as e: | ||
print(str(e)) | ||
# errmsg = "IOError " #%s: %s" % (errno, strerror) |
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.
Commented out code looks like debug code. Your change is an improvement as errmsg does not seem to get used at all so the exception basically just got swallowed.
To me it seems like it might be best to just not catch the exception.
buffer = buffer + meshes[0].to_md5mesh() | ||
file.write(buffer) | ||
file.close() | ||
print( "saved mesh to " + modelFilePath ) | ||
|
||
|
||
if animationFilePath: | ||
if animationFilePath: |
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.
Added whitespace at the end, probably not intentional
#save animation file | ||
if modelFilePath == None: | ||
if len(meshes)>1: |
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.
maybe add spaces around >
with open(file_in_path, 'r') as inFile: | ||
data = json.load(inFile, object_pairs_hook=OrderedDict) | ||
|
||
ModelName=getSuggestedModelName() |
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.
At least in java it is convention to have methods name start lower case and classes upper case. Since it is an exporter for a java program it might be a good idea to follow that convention. Especially not using upper case for a variable
flag=1 | ||
return anim | ||
|
||
return null |
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.
That looks wrong to me. In python there is no null but only None
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.
Yeah sorry didn't realized this. Just added this as a prototype function for later use
data["skeletalmesh"]["material"]=ModelName+"Skin" | ||
data["skeletalmesh"]["animation"]=ModelName+"Idle"#later check if the animation actually exists | ||
data["WildAnimal"]["name"]=ModelName[:1].upper()+ModelName[1:] | ||
data["WildAnimal"]["icon"]="WildAnimals:"+ModelName+"Icon" |
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.
spaces around = and + would make it more readable in my option like spaces in normal sentances make it easier to see word borders.
data["WildAnimal"]["icon"]="WildAnimals:"+ModelName+"Icon" | ||
# data["Die"]["animationPool"]="["+findAnimation("death")+"]" | ||
assetDirectory=getTargetTerasologyAssetsDirectory(context) | ||
FileName=ModelName+".prefab" |
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.
should start with lower case as it is not a type
# value=context.scene.Scale | ||
# value=ExportMD5.md5scale.Scale | ||
# print("^^^^^^^^^^^",value) | ||
# col.prop(ExportMD5.md5scale,"Scale") |
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.
commented out code: should be removed. Version history can keep track of old code versions.
except IOError: | ||
errmsg = "IOError " #%s: %s" % (errno, strerror) | ||
except: | ||
pass |
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.
pass would mean simply ignoring the exception without any logging which would be bad
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.
I meant that the try and except get removed
@@ -664,6 +665,12 @@ def createSubMesh(blenderFacesWithRelativeVertexIndices, blenderMesh, blenderMes | |||
|
|||
Face(md5SubMesh, md5VerticesOfFace[0], md5VerticesOfFace[1], md5VerticesOfFace[2]) | |||
|
|||
def createDirectoryForFileIfMissing(filePath): | |||
"""Function check if the directory is present, if not then creates one""" | |||
directory=os.path.dirname(filePath) |
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.
another case where spaces could be added around the =
@@ -815,12 +822,19 @@ def treat_bone(b, parent = None): | |||
|
|||
if animationFilePath: | |||
#save animation file | |||
if modelFilePath == None: | |||
if len(meshes)>1: |
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.
another case where spaces could be added, please check for further cases by yourself
I also tested it out and the export panel was not visible. I had a look at the console and saw this error message:
|
Have a look at: I think for defined operators/lists etc. it might be necessary to follow blenders naming convention for them. It is a bit C like style. See that above docu also for an example. |
Bump - there are new commits. @flo @Quaternius @nihal111 might one or more of you have a moment to please try out the latest version and see if it works? :-) |
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.
I tested it out and found the following issues:
- The exported prefab is not usable ingame. I did some anlysis for you and found out that you export to the wrong directory (prefab instead of prefabs).
- Also I noticed that the exported prefab still contains animationPool fields that reference the deer animations. Please change them as well to just contain the exported animation.
- The prefab does not contain currently btw even in the animation field the proper animation. I exported the skeleton and the referenced animation was skeletonIdle but there was no such animation. I would have expected the selected animation to be chosen as animation.
- The zip export resutls for me in a zip that contains also completly unrelated prefabas, models and animations that were just in the same directory. Files that are needed to make it work as module were completly missing. I would propose you remove that feature from this PR and make a new branch in which you add that feature. Then when this PR is merged you can make again a PR for the zip export feature.
Please test also next time that the exported stuff also works ingame.
Tested locally - addon works! There are several outstanding issues but I'm documenting those with cards on the GitHub project page and merging this so we can start fresh with the remainder :-) Thanks all! |
Fixed the following bugs:
Prefab exporter:
Added a basic exporter script along with a template prefab to generate another prefab currently according to the model's name etc.