Skip to content

Commit

Permalink
Create main.yml (#2)
Browse files Browse the repository at this point in the history
* Create main.yml

* add openctm as submodule, update dev environment

* fix config, fix linux build, ...

* fix config

* debug config

* debug further

* this should fix it

* test package publish

* fix config typo

* make setup.py python 2.7 compatible

* remove travis

* fix typo

* remove pathlib

* fix pipfile

* fix win32 lib path

* debug

* fix windows build

* debug

* debug

* debug

* fix paths

* this should fix it

* fix publish

* try and fix build

* fix config

* clean up

* skip testing 3.5 and 3.4

* fix build

* fix build

* change test versions

* update readme and worflow
  • Loading branch information
lejafar authored May 5, 2020
1 parent 5681d11 commit 9900173
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 115 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: OpenCTM Release

on: [push]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: [3.8, 3.7, 3.6, 3.5]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
- name: Run tests
run: |
python -m pip install pipenv==2018.11.26
pipenv install -d --python ${{ matrix.python }}
pipenv run pytest tests
shell: bash

package-source:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Build source package
run: python setup.py sdist
- name: Upload source package
uses: actions/upload-artifact@v1
with:
name: dist
path: dist/

package-wheel:
runs-on: ${{ matrix.os }}
needs: [test]
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Build wheels
env:
CIBW_SKIP: cp27-* pp27-* cp34-*
run: |
pip install cibuildwheel
cibuildwheel --output-dir dist
shell: bash
- name: Upload wheels
uses: actions/upload-artifact@v1
with:
name: dist
path: dist/

publish:
runs-on: ubuntu-latest
needs: [test, package-source, package-wheel]
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v1
with:
name: dist
path: dist/
- name: Publish to PyPI
if: github.event_name == 'push' && contains(github.event.ref, 'master')
uses: pypa/gh-action-pypi-publish@master
with:
user: ${{ secrets.pypi_user }}
password: ${{ secrets.pypi_password }}
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/OpenCTM"]
path = submodules/OpenCTM
url = https://github.com/Danny02/OpenCTM.git
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[dev-packages]
openctm = { path="." }
trimesh = "*"
pytest = "*"
importlib-metadata = { version= ">=0.12", markers = "python_version < '3.8'"}
atomicwrites = { version = ">=1.0", markers = "sys_platform=='win32'"}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Python-OpenCTM
==============
[![Build Status](https://travis-ci.org/lejafar/Python-OpenCTM.svg?branch=master)](https://travis-ci.org/lejafar/Python-OpenCTM) [![PyPI version](https://badge.fury.io/py/python-openctm.svg)](https://badge.fury.io/py/python-openctm)
![](https://github.com/lejafar/python-openctm/workflows/OpenCTM%20Release/badge.svg) [![PyPI version](https://badge.fury.io/py/python-openctm.svg)](https://badge.fury.io/py/python-openctm)
### Python Interface for the Open-CTM File Format

Python-OpenCTM is a Python interface for the [OpenCTM](https://github.com/Danny02/OpenCTM) file format. A format that allows a geometry to be compressed to a fraction of comparable file formats (3DS, STL, COLLADA...).

Pre-built python (**3.5**-**3.8**) wheels available for **Linux**, **MacOS** and **Windows**

## Installation

```shell
Expand Down
29 changes: 16 additions & 13 deletions openctm/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class CTM:
"""
Object that encapsulates a CTM file
"""

def __init__(self, _vertices, _faces, _normals=None):
self.vertices = _vertices
self.faces = _faces
self.normals = _normals

def __eq__(self, other):
return (self.vertices == other.vertices).all() and (self.faces == other.faces).all()
return (self.vertices == other.vertices).all() and (
self.faces == other.faces).all()


def import_mesh(_filename):
Expand All @@ -35,8 +35,7 @@ def import_mesh(_filename):
# read faces
face_count = ctmGetInteger(ctm_context, CTM_TRIANGLE_COUNT)
face_ctm = ctmGetIntegerArray(ctm_context, CTM_INDICES)
faces = np.fromiter(face_ctm,
dtype=np.int,
faces = np.fromiter(face_ctm, dtype=np.int,
count=face_count * 3).reshape((-1, 3))

# read face normals
Expand All @@ -54,37 +53,42 @@ def import_mesh(_filename):

def export_mesh(_ctm, _filename):
ctm_context = ctmNewContext(CTM_EXPORT)

if not str(_filename).lower().endswith('.ctm'):
_filename += '.ctm'

try:
vertex_count = len(_ctm.vertices)
vertices = _ctm.vertices.reshape((-1, 1))
p_vertices = ctypes.cast((CTMfloat * vertex_count * 3)(), ctypes.POINTER(CTMfloat))
p_vertices = ctypes.cast((CTMfloat * vertex_count * 3)(),
ctypes.POINTER(CTMfloat))
for i in range(vertex_count * 3):
p_vertices[i] = CTMfloat(vertices[i])
p_vertices[i] = CTMfloat(vertices[i].item())

face_count = len(_ctm.faces)
faces = _ctm.faces.reshape((-1, 1))
p_faces = ctypes.cast((CTMuint * face_count * 3)(), ctypes.POINTER(CTMuint))
p_faces = ctypes.cast((CTMuint * face_count * 3)(),
ctypes.POINTER(CTMuint))
for i in range(face_count * 3):
p_faces[i] = CTMuint(faces[i])
p_faces[i] = CTMuint(faces[i].item())

if _ctm.normals is not None:
normal_count = len(_ctm.normals)
normals = _ctm.normals.reshape((-1, 1))
p_normals = ctypes.cast((CTMfloat * normal_count * 3)(), ctypes.POINTER(CTMfloat))
p_normals = ctypes.cast((CTMfloat * normal_count * 3)(),
ctypes.POINTER(CTMfloat))
for i in range(normal_count * 3):
p_normals[i] = CTMfloat(normals[i])
p_normals[i] = CTMfloat(normals[i].item())
else:
p_normals = None

ctmDefineMesh(ctm_context, p_vertices, CTMuint(vertex_count), p_faces, CTMuint(face_count), p_normals)
ctmDefineMesh(ctm_context, p_vertices, CTMuint(vertex_count), p_faces,
CTMuint(face_count), p_normals)
ctmSave(ctm_context, ctypes.c_char_p(_encode(_filename)))
finally:
ctmFreeContext(ctm_context)


def _encode(_filename):
try:
return str(_filename).encode("utf-8")
Expand All @@ -98,4 +102,3 @@ def _encode(_filename):
pass

return str(_filename).encode("utf-8", "surrogateescape")

22 changes: 17 additions & 5 deletions openctm/openctm.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@

# depending on os chose you binary ...
if sys.platform == 'darwin':
_ctm_lib_path = os.path.join(os.path.dirname(__file__), 'libs/libopenctm.dylib')
_ctm_lib_path = os.path.join(os.path.dirname(__file__), 'libs', 'libopenctm.dylib')
elif sys.platform.startswith('linux'):
_ctm_lib_path = os.path.join(os.path.dirname(__file__), 'libs/libopenctm.so')
_ctm_lib_path = os.path.join(os.path.dirname(__file__), 'libs', 'libopenctm.so')
elif sys.platform.startswith('win32'):
_ctm_lib_path = os.path.join(os.path.dirname(__file__), 'libs', 'openctm.dll')
else:
raise NotImplementedError(sys.platform)

Expand Down Expand Up @@ -187,14 +189,24 @@
ctmFileComment.argtypes = [CTMcontext, ctypes.c_char_p]

ctmDefineMesh = _ctm_lib.ctmDefineMesh
ctmDefineMesh.argtypes = [CTMcontext, ctypes.POINTER(CTMfloat), CTMuint, ctypes.POINTER(CTMuint), CTMuint, ctypes.POINTER(CTMfloat)]
ctmDefineMesh.argtypes = [
CTMcontext,
ctypes.POINTER(CTMfloat), CTMuint,
ctypes.POINTER(CTMuint), CTMuint,
ctypes.POINTER(CTMfloat)
]

ctmAddUVMap = _ctm_lib.ctmAddUVMap
ctmAddUVMap.argtypes = [CTMcontext, ctypes.POINTER(CTMfloat), ctypes.c_char_p, ctypes.c_char_p]
ctmAddUVMap.argtypes = [
CTMcontext,
ctypes.POINTER(CTMfloat), ctypes.c_char_p, ctypes.c_char_p
]
ctmAddUVMap.restype = CTMenum

ctmAddAttribMap = _ctm_lib.ctmAddAttribMap
ctmAddAttribMap.argtypes = [CTMcontext, ctypes.POINTER(CTMfloat), ctypes.c_char_p]
ctmAddAttribMap.argtypes = [
CTMcontext, ctypes.POINTER(CTMfloat), ctypes.c_char_p
]
ctmAddAttribMap.restype = CTMenum

ctmLoad = _ctm_lib.ctmLoad
Expand Down
2 changes: 1 addition & 1 deletion openctm/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.10'
__version__ = '1.0.11'
Loading

0 comments on commit 9900173

Please sign in to comment.