mirror of
https://github.com/bloeys/assimp-go.git
synced 2025-12-29 08:28:20 +00:00
Compare commits
13 Commits
v0.3.1
...
41995b60bb
| Author | SHA1 | Date | |
|---|---|---|---|
| 41995b60bb | |||
| e6f5dca6da | |||
| 0bc81ac5ba | |||
| 6bb760fc0a | |||
| 362558c877 | |||
| 7e82370f34 | |||
| 58e13d1c5a | |||
| bfa7357ea2 | |||
| dd346de9de | |||
| babf9c3926 | |||
| 0fdd5d479c | |||
| 7efa9c31f4 | |||
| 02fd276728 |
20
.github/workflows/run-assimp-go.yml
vendored
Executable file
20
.github/workflows/run-assimp-go.yml
vendored
Executable file
@ -0,0 +1,20 @@
|
||||
name: Build-AssImp
|
||||
on:
|
||||
create:
|
||||
|
||||
jobs:
|
||||
Run-assimp-go-macos:
|
||||
runs-on: macos-10.15
|
||||
steps:
|
||||
- name: Install golang 1.17
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '^1.17'
|
||||
- name: Clone assimp-go
|
||||
run: git clone https://github.com/bloeys/assimp-go
|
||||
- name: Copy dylib
|
||||
working-directory: assimp-go
|
||||
run: sudo mkdir -p /usr/local/lib && sudo cp asig/libs/libassimp_darwin_amd64.dylib /usr/local/lib/libassimp.5.dylib
|
||||
- name: Run assimp-go
|
||||
working-directory: assimp-go
|
||||
run: go run .
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@ -11,8 +11,12 @@
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# Custom
|
||||
vendor/
|
||||
.DS_Store
|
||||
*.obj
|
||||
!obj.obj
|
||||
*.fbx
|
||||
*.glb
|
||||
!libassimp_darwin_arm64.dylib
|
||||
!libassimp_darwin_amd64.dylib
|
||||
42
README.md
42
README.md
@ -1,5 +1,7 @@
|
||||
# assimp-go
|
||||
|
||||
[](https://github.com/bloeys/assimp-go/actions/workflows/run-assimp-go.yml)
|
||||
|
||||
A Handcrafted Open Asset Import Library (AssImp) wrapper for Go.
|
||||
|
||||
## Features
|
||||
@ -25,19 +27,32 @@ Unimplemented (yet) AssImp Scene objects:
|
||||
|
||||
To run the project you need:
|
||||
|
||||
* A 64-bit machine (32-bit machines should be supportable if we get help adding the needed libs)
|
||||
* A recent version of [Go](https://golang.org/) installed (1.17+)
|
||||
* A C/C++ compiler installed and in your path
|
||||
* Windows: [MingW](https://www.mingw-w64.org/downloads/#mingw-builds) or similar
|
||||
* Mac/Linux: Should be installed by default, but if not try [GCC](https://gcc.gnu.org/) or [Clang](https://releases.llvm.org/download.html)
|
||||
* Download the appropriate DLL for your version and put it in the root of your Go project
|
||||
* **Windows**: [MingW](https://www.mingw-w64.org/downloads/#mingw-builds) or similar
|
||||
* **Mac/Linux**: Should be installed by default, but if not try [GCC](https://gcc.gnu.org/) or [Clang](https://releases.llvm.org/download.html)
|
||||
|
||||
Then simply clone and use `go run .`
|
||||
Now to be able to run assimp-go you will need the AssImp shared libraries (DLLs/DyLibs), which you can
|
||||
download from the GitHub releases page.
|
||||
|
||||
### Installing on Windows
|
||||
|
||||
Download the **.dll** of the [release you want](https://github.com/bloeys/assimp-go/releases), and place it in the **root** of your Go project.
|
||||
|
||||
### Installing on MacOS
|
||||
|
||||
First, download the appropriate **.dylib** for your device (`_amd64` for Intel CPUs and `_arm64` for Apple CPUs).
|
||||
Next you will need to rename the lib to `libassimp.5.dylib` and move it to `/usr/local/lib` or `/usr/lib`.
|
||||
|
||||
You can use this command to do it: `sudo mkdir -p /usr/local/lib && sudo cp libassimp_darwin*.dylib /usr/local/lib/libassimp.5.dylib`
|
||||
|
||||
### Running assimp-go
|
||||
|
||||
Use `go run .` to run the simple example in `main.go` ;)
|
||||
|
||||
> Note: that it might take a while to run the first time because of downloading/compiling dependencies.
|
||||
|
||||
`assimp-go` dynamically links (e.g. through a DLL) AssImp using platform dependent libraries, which are made available with the GitHub releases.
|
||||
Currently only `Windows` libraries are available, but more should be easy to add by compiling AssImp on the wanted platform. (Make a PR if you can help us get those binaries!)
|
||||
|
||||
### Getting Started
|
||||
|
||||
```Go
|
||||
@ -85,14 +100,13 @@ While `asig` functions should NOT be called on a Scene (or its objects) after th
|
||||
|
||||
## Developing assimp-go
|
||||
|
||||
We link against assimp libraries that are built for each platform and the `*.a` files are added to the `asig/libs` package.
|
||||
Depending on the platform we select one of them and link against it when doing `go build`.
|
||||
We link against assimp libraries that are built for each platform and the `.a`/`.dylib` files are added to the `asig/libs` package.
|
||||
At build time, the `#cgo` directive choose the appropriate libs and links against them.
|
||||
|
||||
The general steps are:
|
||||
|
||||
* Copy assimp includes into `asig/assimp`
|
||||
* Copy `zlib.h`, `zconf.h` and `irrXML.h` into `asig/zlib` and `asig/irrxml` respectively.
|
||||
* Copy static libraries and DLL import libraries into `asig/libs`
|
||||
* Copy libraries and DLL import libraries into `asig/libs`
|
||||
|
||||
> Note: When dealing with libraries the compiler will probably (e.g. MinGW does this) ignore `lib` prefixes and `.a`/`.lib` suffixes.
|
||||
So if your lib name is `libassimp.a` you need to pass it to CGO as `-l assimp`, otherwise you will get an error about library not found.
|
||||
@ -111,3 +125,9 @@ Now assuming you are using MinGW on windows:
|
||||
* Run `cmake --build . --parallel 6`
|
||||
* Copy the generated `*.lib` (or `*.a`) files from the `lib` folder and into `asig/libs`, and copy the generated dll from AssImp `bin` folder into the root of `assimp-go`.
|
||||
* Copy the generated `libzlibstatic.a` file from `contrib/zlib` and into the `asig/libs` folder.
|
||||
|
||||
**MacOS**:
|
||||
|
||||
* Clone wanted release of assimp and run `cmake CMakeLists.txt -D ASSIMP_BUILD_ZLIB=ON -D ASSIMP_BUILD_ASSIMP_TOOLS=OFF` in the root folder
|
||||
* Run `cmake --build . --parallel 6`
|
||||
* Copy the generated `*.dylib` files from the `bin` folder and into both `asig/libs` and `/usr/local/lib`
|
||||
|
||||
16
asig/asig.go
16
asig/asig.go
@ -1,12 +1,14 @@
|
||||
package asig
|
||||
|
||||
/*
|
||||
//Note: We don't link directly to libIrrXML and libzlib libraries in `./libs`, but they are required by assimp. Removing them will error on compilation.
|
||||
#cgo CFLAGS: -I .
|
||||
#cgo LDFLAGS: -L ./libs -l assimp_windows_amd64
|
||||
#cgo LDFLAGS: -L libs
|
||||
#cgo windows,amd64 LDFLAGS: -l assimp_windows_amd64
|
||||
#cgo darwin,amd64 LDFLAGS: -l assimp_darwin_amd64
|
||||
#cgo darwin,arm64 LDFLAGS: -l assimp_darwin_arm64
|
||||
|
||||
#include <wrap.cxx>
|
||||
#include <stdlib.h> //Needed for C.free
|
||||
#include "wrap.c"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
@ -213,7 +215,7 @@ func parseNodes(cNodesIn **C.struct_aiNode, parent *Node, parentChildrenCount ui
|
||||
}
|
||||
|
||||
//Parse node's children
|
||||
nodes[i].Children = parseNodes(n.mChildren, nodes[i], parentChildrenCount)
|
||||
nodes[i].Children = parseNodes(n.mChildren, nodes[i], uint(n.mNumChildren))
|
||||
}
|
||||
|
||||
return nodes
|
||||
@ -517,6 +519,10 @@ func parseVertexWeights(cWeights *C.struct_aiVertexWeight, count uint) []VertexW
|
||||
}
|
||||
|
||||
func parseAiString(aiString C.struct_aiString) string {
|
||||
if aiString.length == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
return C.GoStringN(&aiString.data[0], C.int(aiString.length))
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
BIN
asig/libs/libassimp_darwin_amd64.dylib
Executable file
BIN
asig/libs/libassimp_darwin_amd64.dylib
Executable file
Binary file not shown.
BIN
asig/libs/libassimp_darwin_arm64.dylib
Executable file
BIN
asig/libs/libassimp_darwin_arm64.dylib
Executable file
Binary file not shown.
Binary file not shown.
@ -2,26 +2,12 @@ package asig
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I .
|
||||
#cgo LDFLAGS: -L ./libs -l assimp_windows_amd64 -l IrrXML_windows_amd64 -l zlib_windows_amd64
|
||||
#cgo LDFLAGS: -L libs
|
||||
#cgo windows,amd64 LDFLAGS: -l assimp_windows_amd64
|
||||
#cgo darwin,arm64 LDFLAGS: -l assimp_darwin_arm64
|
||||
|
||||
#include <stdlib.h> //Needed for C.free
|
||||
|
||||
#include <assimp/scene.h>
|
||||
|
||||
//Functions
|
||||
unsigned int aiGetMaterialTextureCount(const struct aiMaterial* pMat, enum aiTextureType type);
|
||||
|
||||
enum aiReturn aiGetMaterialTexture(
|
||||
const struct aiMaterial* mat,
|
||||
enum aiTextureType type,
|
||||
unsigned int index,
|
||||
struct aiString* path,
|
||||
enum aiTextureMapping* mapping,
|
||||
unsigned int* uvindex,
|
||||
ai_real* blend,
|
||||
enum aiTextureOp* op,
|
||||
enum aiTextureMapMode* mapmode,
|
||||
unsigned int* flags);
|
||||
#include "wrap.c"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
|
||||
2
main.go
2
main.go
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func main() {
|
||||
|
||||
scene, release, err := asig.ImportFile("obj.fbx", asig.PostProcessTriangulate|asig.PostProcessJoinIdenticalVertices)
|
||||
scene, release, err := asig.ImportFile("obj.obj", asig.PostProcessTriangulate|asig.PostProcessJoinIdenticalVertices)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
46
obj.obj
Executable file
46
obj.obj
Executable file
@ -0,0 +1,46 @@
|
||||
# Blender v2.92.0 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib obj.mtl
|
||||
o Cube
|
||||
v 2.275618 1.000000 0.349413
|
||||
v 3.520138 -1.000000 0.102233
|
||||
v 2.275618 1.000000 0.752820
|
||||
v 3.520138 -1.000000 1.000000
|
||||
v 0.244520 1.000000 0.349413
|
||||
v -1.000000 -1.000000 0.102233
|
||||
v 0.244520 1.000000 0.752820
|
||||
v -1.000000 -1.000000 1.000000
|
||||
vt 0.806168 0.568832
|
||||
vt 0.693832 0.681168
|
||||
vt 0.693832 0.568832
|
||||
vt 0.375000 1.000000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.375000 0.000000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.375000 0.250000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.125000 0.750000
|
||||
vt 0.125000 0.500000
|
||||
vt 0.806168 0.681168
|
||||
vt 0.625000 0.931168
|
||||
vt 0.625000 0.068832
|
||||
vn 0.0000 1.0000 0.0000
|
||||
vn 0.0000 0.1227 0.9924
|
||||
vn -0.8490 0.5283 0.0000
|
||||
vn 0.0000 -1.0000 0.0000
|
||||
vn 0.8490 0.5283 0.0000
|
||||
vn 0.0000 0.1227 -0.9924
|
||||
usemtl Material
|
||||
s off
|
||||
f 5/1/1 3/2/1 1/3/1
|
||||
f 3/2/2 8/4/2 4/5/2
|
||||
f 8/6/3 5/7/3 6/8/3
|
||||
f 2/9/4 8/10/4 6/11/4
|
||||
f 1/3/5 4/5/5 2/9/5
|
||||
f 5/7/6 2/9/6 6/8/6
|
||||
f 5/1/1 7/12/1 3/2/1
|
||||
f 3/2/2 7/13/2 8/4/2
|
||||
f 8/6/3 7/14/3 5/7/3
|
||||
f 2/9/4 4/5/4 8/10/4
|
||||
f 1/3/5 3/2/5 4/5/5
|
||||
f 5/7/6 1/3/6 2/9/6
|
||||
Reference in New Issue
Block a user