For some reason, I had to call the FBX SDK Python from Node.js, so I created a Docker image.
The created Docker image is published below. https://hub.docker.com/r/seguropus/fbx-sdk-python-nodejs
Place the sample code below. https://github.com/segurvita/docker-fbx-sdk-python-nodejs
#Build Docker image
docker-compose build
#Launch Docker container
docker-compose up
With this, if the following display appears, it is successful.
fbx-sdk-python-nodejs | # FBX SDK can read the following formats.
fbx-sdk-python-nodejs | 00 FBX (*.fbx)
fbx-sdk-python-nodejs | 01 AutoCAD DXF (*.dxf)
fbx-sdk-python-nodejs | 02 Alias OBJ (*.obj)
fbx-sdk-python-nodejs | 03 3D Studio 3DS (*.3ds)
fbx-sdk-python-nodejs | 04 Collada DAE (*.dae)
fbx-sdk-python-nodejs | 05 Alembic ABC (*.abc)
fbx-sdk-python-nodejs | 06 Biovision BVH (*.bvh)
fbx-sdk-python-nodejs | 07 Motion Analysis HTR (*.htr)
fbx-sdk-python-nodejs | 08 Motion Analysis TRC (*.trc)
fbx-sdk-python-nodejs | 09 Acclaim ASF (*.asf)
fbx-sdk-python-nodejs | 10 Acclaim AMC (*.amc)
fbx-sdk-python-nodejs | 11 Vicon C3D (*.c3d)
fbx-sdk-python-nodejs | 12 Adaptive Optics AOA (*.aoa)
fbx-sdk-python-nodejs | 13 Superfluo MCD (*.mcd)
fbx-sdk-python-nodejs | 14 (*.zip)
fbx-sdk-python-nodejs exited with code 0
What you see is a list of file formats that the FBX SDK can read.
If you see this, you have successfully accessed the FBX SDK Python.
First, docker-compose up
launches the Docker container.
Once started, the Docker container runs the Node.js code ʻindex.js`.
ʻIndex.js calls the Python code
main.py`.
main.py
gets a list of supported formats from the FBX SDK Python and displays it.
Dockerfile
There was a person who published a Docker image in which Python and Node.js lived together, so I created a Dockerfile
based on that.
Dockerfile
# Python 2.7 and Node.Alpine with js 12
FROM nikolaik/python-nodejs:python2.7-nodejs12-alpine
#Library update with apk
RUN apk update && \
apk add \
curl \
libxml2 \
libstdc++
#Download FBX SDK
RUN curl -L \
https://damassets.autodesk.net/content/dam/autodesk/www/adn/fbx/20195/fbx20195_fbxpythonsdk_linux.tar.gz \
-o /tmp/fbx20195_fbxpythonsdk_linux.tar.gz
#Create installation folder
RUN mkdir -p /python-fbx/install
#Unzip the FBX SDK
RUN tar -zxvf \
/tmp/fbx20195_fbxpythonsdk_linux.tar.gz \
-C /python-fbx && \
printf "yes\nn" | \
/python-fbx/fbx20195_fbxpythonsdk_linux \
/python-fbx/install
#Install FBX SDK
RUN cp /python-fbx/install/lib/Python27_ucs4_x64/* \
/usr/local/lib/python2.7/site-packages/
# python-install shell
RUN npm install -g python-shell
#Delete temporary files
RUN rm -r /python-fbx
RUN rm /tmp/fbx20195_fbxpythonsdk_linux.tar.gz
#Environment variable NODE_Set PATH
ENV NODE_PATH /usr/local/lib/node_modules
python-shell
is a library for calling Python from Node.js.
Since I installed it in the global area, I set the environment variable NODE_PATH
so that index.js can be obtained with require
.
docker-compose.yml
docker-compose.yml
looks like this.
docker-compose.yml
version: '3'
services:
fbx-sdk-python-nodejs:
image: 'seguropus/fbx-sdk-python-nodejs'
container_name: 'fbx-sdk-python-nodejs'
build:
context: ./
dockerfile: ./Dockerfile
volumes:
- .:/src
working_dir: /src
command: node index.js
ʻIndex.js` is executed when the Docker container is started.
index.js
index.js looks like this.
index.js
const pythonShell = require('python-shell');
// python-shell options
const pyOption = {
mode: 'text',
pythonPath: '/usr/local/bin/python',
pythonOptions: ['-u'],
scriptPath: '/src',
}
// main.Run py
const pyShell = new pythonShell.PythonShell('main.py', pyOption);
//Show Python standard output
pyShell.on('message', (message) => {
console.log(message);
});
//End processing
pyShell.end(function (err, code, signal) {
if (err) {
console.error(err);
}
console.log('The exit code was: ' + code);
});
I'm calling main.py
with python-shell
.
main.py
main.py
looks like this.
main.py
from fbx import *
def list_reader_format(manager):
print('# FBX SDK can read the following formats.')
for formatIndex in range(manager.GetIOPluginRegistry().GetReaderFormatCount()):
description = manager.GetIOPluginRegistry().GetReaderFormatDescription(formatIndex)
print(formatIndex, description)
def main():
# Create
manager = FbxManager.Create()
scene = FbxScene.Create(manager, "fbxScene")
# List
list_reader_format(manager)
# Destroy
scene.Destroy()
manager.Destroy()
if __name__ == '__main__':
main()
I'm loading the FBX SDK Python with from fbx import *
.
A function called list_reader_format ()
displays a list of file formats that the FBX SDK Python can read in standard output.
You have successfully created a Docker image that can call the FBX SDK Python from Node.js!
It's a big deal, so I'll publish it to Docker Hub.
#log in
docker login
#Push Docker image
docker push seguropus/fbx-sdk-python-nodejs
Published below. https://hub.docker.com/r/seguropus/fbx-sdk-python-nodejs
In creating this article, I referred to the following pages. Thank you very much.