このコードに問題があります:
#include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/SimpleVolume.h"
#include "geomVertexData.h"
#include "geomVertexWriter.h"
#include "geomTriangles.h"
#include "py_panda.h"
#include "pandaNode.h"
#include "geomNode.h"
//Use the PolyVox namespace
using namespace PolyVox;
using namespace std;
static void createSphereInVolume(SimpleVolume<MaterialDensityPair44>& volData, float fRadius)
{
//This vector hold the position of the center of the volume
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
//This three-level for loop iterates over every voxel in the volume
for (int z = 0; z < volData.getWidth(); z++)
{
for (int y = 0; y < volData.getHeight(); y++)
{
for (int x = 0; x < volData.getDepth(); x++)
{
//Store our current position as a vector...
Vector3DFloat v3dCurrentPos(x,y,z);
//And compute how far the current position is from the center of the volume
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
uint8_t uDensity = 0;
uint8_t uMaterial = 0;
//If the current voxel is less than 'radius' units from the center then we make it solid.
if(fDistToCenter <= fRadius)
{
//Our new density value
uDensity = VoxelTypeTraits<MaterialDensityPair44>::maxDensity();
uMaterial = 1;
}
//Get the old voxel
MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z);
//Modify the density and material
voxel.setDensity(uDensity);
voxel.setMaterial(uMaterial);
//Write the voxel value into the volume
volData.setVoxelAt(x, y, z, voxel);
}
}
}
}
static PyObject* CreateSphere(PyObject* self, PyObject* args)
{
PyObject* pandaNodeWrapper;
if (!PyArg_ParseTuple(args, "0", &pandaNodeWrapper))
return NULL;
//Create an empty volume and then place a sphere in it
SimpleVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
createSphereInVolume(volData, 30);
//Extract the surface
SurfaceMesh<PositionMaterialNormal> mesh;
CubicSurfaceExtractorWithNormals<SimpleVolume, MaterialDensityPair44 > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
surfaceExtractor.execute();
const vector<PositionMaterialNormal>& vertices = mesh.getVertices();
const vector<uint32_t>& indices = mesh.getIndices();
CPT(GeomVertexFormat) vertexFormat = GeomVertexFormat::get_v3n3();
PT(GeomVertexData) vertexData = new GeomVertexData("ProceduralMesh", vertexFormat, GeomEnums::UH_static);
GeomVertexWriter vertex, normal;
vertex = GeomVertexWriter(vertexData, "vertex");
normal = GeomVertexWriter(vertexData, "normal");
for(vector<PositionMaterialNormal>::const_iterator it = vertices.begin(); it != vertices.end(); ++it)
{
vertex.add_data3f(it->position.getX(), it->position.getY(), it->position.getZ());
normal.add_data3f(it->normal.getX(), it->position.getY(), it->position.getZ());
}
PT(GeomTriangles) chunk = new GeomTriangles(GeomEnums::UH_static);
for(int i = 0; i < indices.size(); ++i)
{
chunk->add_vertex(indices[i]);
}
PT(Geom) geom = new Geom(vertexData);
geom->add_primitive(chunk);
PT(GeomNode) geomNode = new GeomNode("chunk");
PandaNode* node = ((PandaNode*)((Dtool_PyInstDef*)pandaNodeWrapper)->_ptr_to_object);
node->add_child(geomNode);
Py_RETURN_NONE;
}
static PyMethodDef module_methods[] = {
{"CreateSphere", CreateSphere, METH_VARARGS, "CreateSphere"},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
initpolyvox(void)
{
(void) Py_InitModule("polyvox", module_methods);
}
これは、私が書こうとしている C++ 拡張モジュールです。setup.py メソッドを使用してコンパイルし、インストールしました。問題は、それを Python にインポートして実行すると、Python が「SystemError: dynamic module not initialized correctly (システム エラー: 動的モジュールが正しく初期化されていません)」と言う"。
このエラーは、モジュール名が init 関数名と一致しないということであることはわかっていますが、コードを見るとそうではありません。では、何が問題になるのでしょうか?
私はWindows 7でpython 2.7.2を使用しています。モジュールはVS2008でコンパイルされていますが、最新のc ++機能が必要なため、vs2010でコンパイルする必要があった.libが必要です。