teienlib 0.0.1-x86-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +31 -0
- data/ext/teienlib/extconf.rb +35 -0
- data/ext/teienlib/interface/AnimationBlender.i +8 -0
- data/ext/teienlib/interface/CollisionChecker.i +22 -0
- data/ext/teienlib/interface/DebugDrawer.i +8 -0
- data/ext/teienlib/interface/MeshStrider.i +8 -0
- data/ext/teienlib/interface/Rakefile +27 -0
- data/ext/teienlib/interface/SoftBody.i +9 -0
- data/ext/teienlib/interface/teienlib.i +36 -0
- data/ext/teienlib/src/AnimationBlender.cc +141 -0
- data/ext/teienlib/src/AnimationBlender.h +41 -0
- data/ext/teienlib/src/Collision.cc +797 -0
- data/ext/teienlib/src/Collision.h +130 -0
- data/ext/teienlib/src/CollisionChecker.cc +67 -0
- data/ext/teienlib/src/CollisionChecker.h +33 -0
- data/ext/teienlib/src/DebugDrawer.h +66 -0
- data/ext/teienlib/src/MeshStrider.cc +112 -0
- data/ext/teienlib/src/MeshStrider.h +48 -0
- data/ext/teienlib/src/Shape.cc +9 -0
- data/ext/teienlib/src/Shape.h +186 -0
- data/ext/teienlib/src/SimpleCollisionLibrary.h +7 -0
- data/ext/teienlib/src/SoftBody.cc +148 -0
- data/ext/teienlib/src/SoftBody.h +14 -0
- data/ext/teienlib/src/Vector3D.h +92 -0
- data/lib/Teienlib.so +0 -0
- data/lib/teienlib/version.rb +3 -0
- data/lib/teienlib.rb +5 -0
- data/teienlib.gemspec +33 -0
- metadata +98 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
#include "SoftBody.h"
|
2
|
+
|
3
|
+
#include "MeshStrider.h"
|
4
|
+
|
5
|
+
#include "btBulletCollisionCommon.h"
|
6
|
+
#include "btBulletDynamicsCommon.h"
|
7
|
+
#include "btSoftBodyHelpers.h"
|
8
|
+
|
9
|
+
btSoftBody*
|
10
|
+
SoftBody::createFromMesh(Ogre::Mesh* mesh, btSoftBodyWorldInfo* worldInfo)
|
11
|
+
{
|
12
|
+
|
13
|
+
std::cout << __PRETTY_FUNCTION__ << std::endl;
|
14
|
+
|
15
|
+
MeshStrider meshStrider(mesh);
|
16
|
+
|
17
|
+
|
18
|
+
std::cout << meshStrider.getNumSubParts() << std::endl;
|
19
|
+
|
20
|
+
const unsigned char *vertexbase;
|
21
|
+
int numverts;
|
22
|
+
PHY_ScalarType type;
|
23
|
+
int stride;
|
24
|
+
|
25
|
+
const unsigned char *indexbase;
|
26
|
+
int indexstride;
|
27
|
+
int numfaces;
|
28
|
+
PHY_ScalarType indicestype;
|
29
|
+
|
30
|
+
btSoftBody *softBody;
|
31
|
+
|
32
|
+
meshStrider.getLockedReadOnlyVertexIndexBase(&vertexbase, numverts, type, stride,
|
33
|
+
&indexbase, indexstride, numfaces, indicestype,
|
34
|
+
0);
|
35
|
+
|
36
|
+
std::cout << "NumVerts: " << numverts << ", " << stride << std::endl;
|
37
|
+
std::cout << "NumFaces: " << numfaces << ", " << indexstride << std::endl;
|
38
|
+
|
39
|
+
|
40
|
+
int* triangles = new int(numfaces * 3);
|
41
|
+
for (int i = 0; i < numfaces * 3; i++) {
|
42
|
+
triangles[i] = ((unsigned short*)indexbase)[i];
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
// *** glibc detected *** ruby: double free or corruption (fasttop): 0x09445008 ***
|
47
|
+
//softBody = btSoftBodyHelpers::CreateFromTriMesh(*worldInfo, (btScalar *)vertexbase, triangles, numfaces);
|
48
|
+
std::cout << "done" << std::endl;
|
49
|
+
|
50
|
+
meshStrider.unLockReadOnlyVertexBase(0);
|
51
|
+
|
52
|
+
return softBody;
|
53
|
+
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
void
|
58
|
+
SoftBody::updateOgreMesh(Ogre::Mesh* mesh, btSoftBody* softBody)
|
59
|
+
{
|
60
|
+
std::cout << __PRETTY_FUNCTION__ << std::endl;
|
61
|
+
|
62
|
+
/*
|
63
|
+
Ogre::Node *ogreNode = mEntity->getParentNode();
|
64
|
+
|
65
|
+
//printf("updateOgreMesh %d %s %s\n", internalId, mEntity->getName().c_str(), ogreNode->getName().c_str());
|
66
|
+
|
67
|
+
MeshPtr mesh = mEntity->getMesh();
|
68
|
+
Mesh::SubMeshIterator subMeshI = mesh->getSubMeshIterator();
|
69
|
+
SubMesh* subMesh = NULL;
|
70
|
+
|
71
|
+
VertexData* vData = NULL;
|
72
|
+
VertexDeclaration* vDeclaration = NULL;
|
73
|
+
const VertexElement* vPosElement = NULL;
|
74
|
+
|
75
|
+
bool isSharedVerticesAdded = false;
|
76
|
+
unsigned short bufferIndex = 0;
|
77
|
+
HardwareVertexBufferSharedPtr vBuffer;
|
78
|
+
|
79
|
+
// Can not do arithmetic operations on void*
|
80
|
+
unsigned char* lockedMem = NULL;
|
81
|
+
float* vPosition;
|
82
|
+
|
83
|
+
btSoftBody::tNodeArray& btNodes = mSoftBody->m_nodes;
|
84
|
+
//printf("Bullet nodes size %d\n", btNodes.size());
|
85
|
+
|
86
|
+
int ogreVertexIdx = 0;
|
87
|
+
btVector3 btPosOffset;
|
88
|
+
|
89
|
+
while (subMeshI.hasMoreElements()) {
|
90
|
+
subMesh = subMeshI.getNext();
|
91
|
+
|
92
|
+
if (subMesh->useSharedVertices) {
|
93
|
+
|
94
|
+
if (isSharedVerticesAdded) {
|
95
|
+
continue;
|
96
|
+
}
|
97
|
+
|
98
|
+
vData = mesh->sharedVertexData;
|
99
|
+
|
100
|
+
// We need to add shared vertices only once
|
101
|
+
isSharedVerticesAdded = true;
|
102
|
+
} else {
|
103
|
+
vData = subMesh->vertexData;
|
104
|
+
}
|
105
|
+
|
106
|
+
vDeclaration = vData->vertexDeclaration;
|
107
|
+
vPosElement = vDeclaration->findElementBySemantic(VES_POSITION);
|
108
|
+
|
109
|
+
bufferIndex = vPosElement->getSource();
|
110
|
+
vBuffer = vData->vertexBufferBinding->getBuffer(bufferIndex);
|
111
|
+
|
112
|
+
// Lock the buffer before reading from it
|
113
|
+
lockedMem = static_cast<unsigned char*>(vBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
// Read each vertex
|
118
|
+
for (unsigned int i = 0; i < vData->vertexCount; ++i) {
|
119
|
+
vPosElement->baseVertexPointerToElement(lockedMem, &vPosition);
|
120
|
+
|
121
|
+
int idx = getBulletIndex(ogreVertexIdx);
|
122
|
+
const btVector3 &btPos = btNodes[idx].m_x;
|
123
|
+
if (ogreVertexIdx == 0) {
|
124
|
+
btPosOffset = btPos;
|
125
|
+
}
|
126
|
+
|
127
|
+
*vPosition++ = btPos.x() - btPosOffset.x();
|
128
|
+
*vPosition++ = btPos.y() - btPosOffset.y();
|
129
|
+
*vPosition = btPos.z() - btPosOffset.z();
|
130
|
+
|
131
|
+
// Point to the next vertex
|
132
|
+
lockedMem += vBuffer->getVertexSize();
|
133
|
+
|
134
|
+
ogreVertexIdx++;
|
135
|
+
}
|
136
|
+
|
137
|
+
vBuffer->unlock();
|
138
|
+
}
|
139
|
+
|
140
|
+
btTransform transform = mSoftBody->getWorldTransform();
|
141
|
+
btQuaternion rot = transform.getRotation();
|
142
|
+
ogreNode->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
|
143
|
+
btVector3 pos = transform.getOrigin();
|
144
|
+
ogreNode->setPosition(pos.x() + btPosOffset.x(), pos.y() + btPosOffset.y(), pos.z() + btPosOffset.z());
|
145
|
+
|
146
|
+
}
|
147
|
+
*/
|
148
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef _UTILS_H
|
2
|
+
#define _UTILS_H
|
3
|
+
|
4
|
+
#include "Ogre.h"
|
5
|
+
#include "btSoftBody.h"
|
6
|
+
|
7
|
+
class SoftBody
|
8
|
+
{
|
9
|
+
public:
|
10
|
+
static btSoftBody* createFromMesh(Ogre::Mesh* mesh, btSoftBodyWorldInfo* worldInfo);
|
11
|
+
static void updateOgreMesh(Ogre::Mesh* mesh, btSoftBody* softBody);
|
12
|
+
};
|
13
|
+
|
14
|
+
#endif
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#ifndef VECTOR3D_H
|
2
|
+
#define VECTOR3D_H
|
3
|
+
|
4
|
+
#include <iostream>
|
5
|
+
#include <sstream>
|
6
|
+
#include <math.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
using namespace std;
|
9
|
+
|
10
|
+
namespace sul
|
11
|
+
{
|
12
|
+
|
13
|
+
template <class T>
|
14
|
+
struct Vector3D{
|
15
|
+
T x;
|
16
|
+
T y;
|
17
|
+
T z;
|
18
|
+
|
19
|
+
Vector3D() { x = 0; y = 0; z = 0; }
|
20
|
+
Vector3D(const Vector3D& pt) { x = pt.x; y = pt.y; z = pt.z; }
|
21
|
+
Vector3D(T in_x, T in_y, T in_z) { x = in_x; y = in_y; z = in_z; }
|
22
|
+
|
23
|
+
void set(T ix, T iy, T iz) { x = ix; y = iy; z = iz; }
|
24
|
+
void set(const Vector3D &pt) { x = pt.x; y = pt.y; z = pt.z; }
|
25
|
+
|
26
|
+
Vector3D operator+(const Vector3D &pt) const
|
27
|
+
{
|
28
|
+
return Vector3D (x + pt.x, y + pt.y, z + pt.z);
|
29
|
+
}
|
30
|
+
Vector3D operator-(const Vector3D &pt) const
|
31
|
+
{
|
32
|
+
return Vector3D (x - pt.x, y - pt.y, z - pt.z);
|
33
|
+
}
|
34
|
+
Vector3D operator-() const { return Vector3D(-x, -y, -z); }
|
35
|
+
Vector3D &operator+=(const Vector3D &pt)
|
36
|
+
{
|
37
|
+
x += pt.x; y += pt.y; z += pt.z; return *this;
|
38
|
+
}
|
39
|
+
Vector3D &operator-=(const Vector3D &pt)
|
40
|
+
{
|
41
|
+
x -= pt.x; y -= pt.y; z -= pt.z; return *this;
|
42
|
+
}
|
43
|
+
Vector3D operator*(const T f) { return Vector3D (x * f, y * f, z *f); }
|
44
|
+
Vector3D &operator*=(const T f) { x *= f; y *= f; z *= f; return *this; }
|
45
|
+
|
46
|
+
Vector3D operator/(const T f) { return Vector3D (x / f, y / f, z / f); }
|
47
|
+
Vector3D &operator/=(const T f) { x /= f; y /= f; z /= f; return *this; }
|
48
|
+
|
49
|
+
Vector3D &operator=(const Vector3D &pt) { x = pt.x; y = pt.y; z = pt.z; return *this; }
|
50
|
+
bool operator==(const Vector3D &pt) { return x == pt.x && y == pt.y && z == pt.z; }
|
51
|
+
|
52
|
+
T len() const { return (T) sqrt(x * x + y * y + z * z); }
|
53
|
+
T lenSquared() const { return x * x + y * y + z * z; }
|
54
|
+
bool normalize()
|
55
|
+
{
|
56
|
+
T l = len();
|
57
|
+
if (l == 0) { x = 0; y = 0; z = 0; return false;}
|
58
|
+
else { l = 1 / l; x *= l; y *= l; z *= l; return true;}
|
59
|
+
}
|
60
|
+
bool normalize(float newLen)
|
61
|
+
{
|
62
|
+
T l = len();
|
63
|
+
if (l == 0) { x = 0; y = 0; z = 0; return false;}
|
64
|
+
else { l = newLen / l; x *= l; y *= l; z *= l; return true;}
|
65
|
+
}
|
66
|
+
void scaleFloorDiv(float scaleFactor, float divFactor)
|
67
|
+
{
|
68
|
+
x = (T) floor(x * scaleFactor + 0.5) * divFactor;
|
69
|
+
y = (T) floor(y * scaleFactor + 0.5) * divFactor;
|
70
|
+
z = (T) floor(z * scaleFactor + 0.5) * divFactor;
|
71
|
+
}
|
72
|
+
T dot(const Vector3D &p) const { return x * p.x + y * p.y + z * p.z; }
|
73
|
+
void read(const char **argv)
|
74
|
+
{
|
75
|
+
x = (T) atof(argv[0]);
|
76
|
+
y = (T) atof(argv[1]);
|
77
|
+
z = (T) atof(argv[2]);
|
78
|
+
}
|
79
|
+
void printPos()
|
80
|
+
{
|
81
|
+
cout << "(" << x << ", " << y << ", " << z << ")";
|
82
|
+
}
|
83
|
+
std::string toString()
|
84
|
+
{
|
85
|
+
std::ostringstream oss;
|
86
|
+
oss << "(" << x << ", " << y << ", " << z << ")";
|
87
|
+
return oss.str();
|
88
|
+
}
|
89
|
+
};
|
90
|
+
|
91
|
+
}
|
92
|
+
#endif // VECTOR3D_H
|
data/lib/Teienlib.so
ADDED
Binary file
|
data/lib/teienlib.rb
ADDED
data/teienlib.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'teienlib/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "teienlib"
|
7
|
+
gem.version = Teienlib::VERSION
|
8
|
+
gem.authors = ["abexsoft works"]
|
9
|
+
gem.email = ["abexsoft@gmail.com"]
|
10
|
+
gem.description = %q{An extension library for Teien.}
|
11
|
+
gem.summary = %q{An extension library for Teien.}
|
12
|
+
gem.homepage = "https://github.com/abexsoft/teienlib"
|
13
|
+
gem.platform = Gem::Platform::CURRENT
|
14
|
+
|
15
|
+
gem.files = Dir['Gemfile',
|
16
|
+
'LICENSE.txt',
|
17
|
+
'README.md',
|
18
|
+
'Rakefile',
|
19
|
+
'teienlib.gemspec',
|
20
|
+
'ext/teienlib/extconf.rb',
|
21
|
+
'ext/teienlib/interface/*.i',
|
22
|
+
'ext/teienlib/interface/Rakefile',
|
23
|
+
'ext/teienlib/src/*.{cc,h}',
|
24
|
+
'lib/**/*',
|
25
|
+
]
|
26
|
+
|
27
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
28
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
29
|
+
gem.require_paths = ["lib"]
|
30
|
+
|
31
|
+
gem.add_dependency 'ruby-ogre'
|
32
|
+
gem.add_dependency 'ruby-bullet'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: teienlib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: x86-linux
|
7
|
+
authors:
|
8
|
+
- abexsoft works
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ruby-ogre
|
16
|
+
requirement: &82505360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *82505360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ruby-bullet
|
27
|
+
requirement: &82505070 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *82505070
|
36
|
+
description: An extension library for Teien.
|
37
|
+
email:
|
38
|
+
- abexsoft@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- Gemfile
|
44
|
+
- LICENSE.txt
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- teienlib.gemspec
|
48
|
+
- ext/teienlib/extconf.rb
|
49
|
+
- ext/teienlib/interface/AnimationBlender.i
|
50
|
+
- ext/teienlib/interface/SoftBody.i
|
51
|
+
- ext/teienlib/interface/teienlib.i
|
52
|
+
- ext/teienlib/interface/MeshStrider.i
|
53
|
+
- ext/teienlib/interface/DebugDrawer.i
|
54
|
+
- ext/teienlib/interface/CollisionChecker.i
|
55
|
+
- ext/teienlib/interface/Rakefile
|
56
|
+
- ext/teienlib/src/SoftBody.cc
|
57
|
+
- ext/teienlib/src/Shape.cc
|
58
|
+
- ext/teienlib/src/CollisionChecker.cc
|
59
|
+
- ext/teienlib/src/Collision.cc
|
60
|
+
- ext/teienlib/src/MeshStrider.cc
|
61
|
+
- ext/teienlib/src/AnimationBlender.cc
|
62
|
+
- ext/teienlib/src/SimpleCollisionLibrary.h
|
63
|
+
- ext/teienlib/src/Collision.h
|
64
|
+
- ext/teienlib/src/SoftBody.h
|
65
|
+
- ext/teienlib/src/AnimationBlender.h
|
66
|
+
- ext/teienlib/src/CollisionChecker.h
|
67
|
+
- ext/teienlib/src/Shape.h
|
68
|
+
- ext/teienlib/src/MeshStrider.h
|
69
|
+
- ext/teienlib/src/Vector3D.h
|
70
|
+
- ext/teienlib/src/DebugDrawer.h
|
71
|
+
- lib/teienlib/version.rb
|
72
|
+
- lib/Teienlib.so
|
73
|
+
- lib/teienlib.rb
|
74
|
+
homepage: https://github.com/abexsoft/teienlib
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.11
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: An extension library for Teien.
|
98
|
+
test_files: []
|