Skip to content
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

Merged
merged 7 commits into from Jul 25, 2017

Conversation

kartikey0303
Copy link
Contributor

Fixed the following bugs:

  1. Bounding box
  2. File directory not being created
  3. Matrix error is also not present.

Prefab exporter:
Added a basic exporter script along with a template prefab to generate another prefab currently according to the model's name etc.

Copy link
Contributor

@flo flo left a 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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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:
Copy link
Contributor

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:
Copy link
Contributor

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()
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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"
Copy link
Contributor

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"
Copy link
Contributor

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")
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

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)
Copy link
Contributor

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:
Copy link
Contributor

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

@flo
Copy link
Contributor

flo commented Jul 12, 2017

I also tested it out and the export panel was not visible.

I had a look at the console and saw this error message:
found

Traceback (most recent call last):
  File "/home/flo/programs/blender-2.77a-linux-glibc211-x86_64/2.77/scripts/modules/addon_utils.py", line 330, in enable
    mod = __import__(module_name)
  File "/home/flo/.config/blender/2.77/scripts/addons/io_export_md5.py", line 1052, in <module>
    class actionlist_UL(UIList):
NameError: name 'UIList' is not defined

@flo
Copy link
Contributor

flo commented Jul 12, 2017

Have a look at:
https://docs.blender.org/api/blender_python_api_2_70_5/bpy.types.UIList.html

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.

@Cervator
Copy link
Member

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? :-)

@Cervator Cervator requested a review from Quaternius July 18, 2017 04:20
Copy link
Contributor

@flo flo left a 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.

@Cervator Cervator merged commit bca5330 into MovingBlocks:master Jul 25, 2017
Cervator added a commit that referenced this pull request Jul 25, 2017
@Cervator
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants