Skip to content

Commit a58aeea

Browse files
author
lml
committed
success
0 parents  commit a58aeea

File tree

723 files changed

+228267
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

723 files changed

+228267
-0
lines changed

FbxUtils.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import os
2+
import shutil
3+
import stat
4+
import subprocess
5+
import time
6+
import sys
7+
import platform
8+
9+
# Utility functions to manipulate/walk disks
10+
def FileExist(File):
11+
if os.access(File,os.F_OK):
12+
return 1
13+
else:
14+
return 0
15+
16+
17+
def FileDelete(File):
18+
try:
19+
os.chmod(File, stat.S_IWRITE)
20+
os.remove(File)
21+
except:
22+
raise
23+
24+
25+
def DirCopy(Src,Dst):
26+
if FileExist(Dst):
27+
try:
28+
Files = os.listdir(Src)
29+
for File in Files:
30+
if os.path.isdir(os.path.join(Src,File)):
31+
DirCopy(os.path.join(Src,File), os.path.join(Dst,File) )
32+
elif os.path.isfile(os.path.join(Src,File)):
33+
FileCopy( os.path.join(Src,File), os.path.join(Dst,File) )
34+
except:
35+
raise (RuntimeError, "Can't copy directory %s to %s" % (Src, Dst))
36+
else:
37+
try:
38+
shutil.copytree(Src, Dst)
39+
except:
40+
raise (RuntimeError,"Can't copy directory")
41+
42+
43+
def DirCreate(Dir):
44+
if not os.access(Dir,os.F_OK):
45+
os.makedirs ( Dir )
46+
47+
48+
def DirDelete(Dir):
49+
if FileExist(Dir):
50+
Files = os.listdir(Dir)
51+
for File in Files:
52+
full_path = os.path.join(Dir, File)
53+
if os.path.isdir(full_path):
54+
DirDelete(full_path)
55+
elif os.path.isfile(full_path):
56+
FileDelete(full_path)
57+
os.chmod( Dir,stat.S_IWRITE )
58+
os.rmdir(Dir)
59+
60+
# *************************************************************************
61+
# Log utility
62+
# 1 - Steps
63+
# 2 - Steps + Low level details when errors
64+
# 3 - Steps + Low level details when warnings
65+
# 4 - Steps + High level details
66+
# *************************************************************************
67+
LogLevel = 3
68+
def Log(Level,String,OutLogFile=None):
69+
if Level<=LogLevel:
70+
sys.stdout.write(String)
71+
sys.stdout.flush()
72+
if OutLogFile != None:
73+
OutLogFile.write(String)
74+
OutLogFile.flush()
75+
76+
def LogFlush():
77+
sys.stdout.flush()

License.rtf

Lines changed: 1111 additions & 0 deletions
Large diffs are not rendered by default.

PythonBindings.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import os, sys, shutil, time
2+
import platform, glob
3+
import FbxUtils
4+
5+
WINDOWS_PLATFORM = (platform.system() == 'Windows' or platform.system() == "Microsoft")
6+
7+
rootPath = os.path.dirname(os.path.abspath(sys.argv[0]))
8+
buildPath = os.path.join(rootPath, 'build')
9+
distribPath = os.path.join(buildPath, "Distrib", "fbxpythonsdk")
10+
cmdLineDescr = "PythonBindings.py"
11+
pythonExecutable = sys.executable
12+
13+
def PrintError(txt):
14+
print ("\n================================================================================================\n")
15+
FbxUtils.Log(2, "ERROR: " + txt)
16+
print ("\n================================================================================================\n")
17+
exit(1)
18+
19+
20+
def log(txt):
21+
msg = "=> " + txt + "\n"
22+
FbxUtils.Log(1, msg)
23+
24+
def install_SIP():
25+
log("")
26+
log("-=[ Installing SIP ]=-")
27+
log("")
28+
29+
command = pythonExecutable + ' -m pip install --force-reinstall -v "sip==6.6.2"'
30+
31+
log("%s" % command)
32+
os.system(command)
33+
34+
def generate_wheel(python_dir):
35+
log("")
36+
log("-=[ Generating wheel ]=-")
37+
log("")
38+
39+
os.chdir(python_dir)
40+
log("%s" % python_dir)
41+
command = pythonExecutable + " -m sipbuild.tools.wheel"
42+
43+
log("%s" % command)
44+
os.system(command)
45+
wheelFileName = glob.glob(os.path.join(python_dir,'*.whl'))
46+
return wheelFileName[0]
47+
48+
def install_wheel(python_dir):
49+
log("")
50+
log("-=[ Install wheel ]=-")
51+
log("")
52+
53+
os.chdir(python_dir)
54+
log("%s" % python_dir)
55+
wheelFileName = glob.glob(os.path.join(python_dir,'*.whl'))
56+
57+
command = pythonExecutable + " -m pip install " + wheelFileName[0]
58+
59+
log("%s" % command)
60+
os.system(command)
61+
62+
def test_python_fbx_examples(fbx_wrapper_dir, build_dir, sdk_lib_dir):
63+
log("")
64+
log("-=[ Testing the samples ]=-")
65+
log("")
66+
67+
src_samples_dir = os.path.join(fbx_wrapper_dir, 'samples')
68+
dst_samples_dir = os.path.join(build_dir, 'samples')
69+
try:
70+
FbxUtils.DirCopy(src_samples_dir, dst_samples_dir)
71+
except:
72+
PrintError("Failed to copy samples directories")
73+
exit(1)
74+
75+
example_dirs = (
76+
os.path.join(dst_samples_dir, 'Audio'),
77+
os.path.join(dst_samples_dir, 'ExportScene01'),
78+
os.path.join(dst_samples_dir, 'ExportScene02'),
79+
os.path.join(dst_samples_dir, 'ExportScene03'),
80+
os.path.join(dst_samples_dir, 'ExportScene04'),
81+
os.path.join(dst_samples_dir, 'Layers'),
82+
os.path.join(dst_samples_dir, 'SplitMeshPerMaterial'),
83+
)
84+
example_scripts = (
85+
'Audio.py',
86+
'ExportScene01.py',
87+
'ExportScene02.py',
88+
'ExportScene03.py',
89+
'ExportScene04.py',
90+
'Layers.py',
91+
'SplitMeshPerMaterial.py multiplematerials.FBX',
92+
)
93+
94+
os.environ['PYTHONPATH'] = build_dir
95+
for index in range(len(example_dirs)):
96+
os.chdir(example_dirs[index])
97+
command = " ".join(['"' + pythonExecutable + '"', example_scripts[index]])
98+
log(" RUN COMMAND : %s" % command)
99+
result = os.system(command)
100+
101+
os.chdir(os.path.join(dst_samples_dir, 'ImportScene'))
102+
files = (
103+
'../Audio/Audio.fbx',
104+
'../ExportScene01/ExportScene01.fbx',
105+
'../ExportScene02/ExportScene02.fbx',
106+
'../ExportScene03/ExportScene03.fbx',
107+
'../ExportScene04/ExportScene04.fbx',
108+
'../Layers/Layers.fbx'
109+
)
110+
111+
dump_output = '' if WINDOWS_PLATFORM else '> /dev/null'
112+
for index in range(len(files)):
113+
command = " ".join(['"' + pythonExecutable + '"', 'ImportScene.py', files[index], dump_output])
114+
log(" RUN COMMAND : %s" % command)
115+
result = os.system(command)
116+
117+
118+
def generate_python_fbx_documentation(python_dir, api_doc_dir):
119+
if WINDOWS_PLATFORM:
120+
# documentation can only be generated on Windows
121+
log("")
122+
log("-=[ Generating documentation ]=-")
123+
log("")
124+
125+
pydocInstallPath = os.path.dirname(pythonExecutable) + "/Lib"
126+
127+
os.chdir(python_dir)
128+
log("%s" % pydocInstallPath)
129+
command = pythonExecutable + " " + pydocInstallPath + "/pydoc.py -w fbx"
130+
log("%s" % command)
131+
os.system(command)
132+
133+
if not os.path.exists(api_doc_dir):
134+
os.mkdir(api_doc_dir)
135+
136+
# The generation with pydoc can take a while so wait until file exists before copying
137+
timeout = 0
138+
while ((not os.path.exists(os.path.join(python_dir, "fbx.html"))) and (timeout < 60)):
139+
time.sleep(1)
140+
timeout += 1
141+
142+
shutil.copyfile(os.path.join(python_dir, "fbx.html"), os.path.join(api_doc_dir, "fbx.html"))
143+
144+
145+
def main(args):
146+
147+
# Display help if wrong number arguments
148+
nbArgs = len(args)
149+
if nbArgs > 2:
150+
print ("Syntax: " + cmdLineDescr + " [test] [doc]\n")
151+
exit(1)
152+
153+
test = False
154+
doc = False
155+
156+
for i in range(2,nbArgs):
157+
if args[i].lower() == 'test': test = True;
158+
if args[i].lower() == 'doc': doc = True;
159+
160+
# --------------------------------------
161+
# compile fbx python binding
162+
# --------------------------------------
163+
164+
install_SIP()
165+
166+
wheel_filename = generate_wheel(buildPath)
167+
168+
sdk_lib_dir = distribPath
169+
log("Copy the results to the folder:" + sdk_lib_dir)
170+
if not os.path.exists(sdk_lib_dir):
171+
os.makedirs(sdk_lib_dir)
172+
173+
shutil.copyfile(wheel_filename, os.path.join(sdk_lib_dir, os.path.basename(wheel_filename)))
174+
175+
if test or doc:
176+
install_wheel(buildPath)
177+
178+
if test:
179+
test_python_fbx_examples(rootPath, buildPath, sdk_lib_dir)
180+
181+
if doc:
182+
python_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
183+
api_doc_dir = os.path.join(distribPath,"doc")
184+
if not os.path.exists(api_doc_dir):
185+
os.makedirs(api_doc_dir)
186+
generate_python_fbx_documentation(python_dir, api_doc_dir)
187+
188+
sys.exit(0)
189+
190+
191+
if __name__ == '__main__':
192+
main(sys.argv)

0 commit comments

Comments
 (0)