Giter Site home page Giter Site logo

fsfence / libsavitar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ultimaker/libsavitar

0.0 1.0 0.0 200 KB

libSavitar is a c++ implementation of 3mf loading with SIP python bindings.

License: GNU Lesser General Public License v3.0

CMake 3.44% Python 0.48% C++ 95.85% C 0.23%

libsavitar's Introduction

Introduction

libSavitar is a c++ implementation of 3mf loading with SIP python bindings.

Requirements

libSavitar requires SIP version 4.19.2 or higher: https://www.riverbankcomputing.com/software/sip/download

Build instructions Windows with MSVC

Make sure you have run something like:

โ€œc:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

Next, git clone libSavitar and from the directory:

mkdir build
mkdir install_dir
cd build
cmake -DCMAKE_INSTALL_PREFIX=../install_dir -DBUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" ..
nmake
nmake install

Now copy the site-packages contents from the install_dir into your site-packages dir.

Usage

Reading 3mf's 3dmodel.model file.

file_name = "project.3mf"
archive = zipfile.ZipFile(file_name, "r")
parser = Savitar.ThreeMFParser()
scene_3mf = parser.parse(archive.open("3D/3dmodel.model").read())
for node in scene_3mf.getSceneNodes():
    my_node = convertSavitarNodeToMyNode(node)

Writing

archive = zipfile.ZipFile(stream, "w", compression = zipfile.ZIP_DEFLATED)
model_file = zipfile.ZipInfo("3D/3dmodel.model")
savitar_scene = Savitar.Scene()
#construct your node
savitar_scene.addSceneNode(savitar_node)

import numpy
mesh = savitar_node.getMeshData()

# We use zero data, but when using lib savitar, replace this with your data.
vertices = numpy.zeros((9, 3), dtype = numpy.float32)  
faces = numpy.zeros((4, 2), dtype=numpy.int32)

mesh.setVerticesFromBytes(vertices.tobytes())
mesh.setFacesFromBytes(faces.tobytes())

parser = Savitar.ThreeMFParser()

# Generate XML string 
scene_string = parser.sceneToString(savitar_scene)  
archive.writestr(model_file, scene_string)

libsavitar's People

Contributors

nallath avatar rburema avatar ghostkeeper avatar onitake avatar appesteijn avatar awhiemstra avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.