Beispiel #1
0
nSamples            = 100
vertices            = geom.evaluate(    np.linspace(geom._domain[0][0],geom._domain[0][1],num=nSamples),
                                        np.linspace(geom._domain[1][0],geom._domain[1][1],num=nSamples) )
geometry            = convertToSurfaceMesh( vertices )

# Texture - geometry map
textureCoordinates  = np.stack( np.meshgrid(    np.linspace(0.0,1.0,num=nSamples),
                                                np.linspace(0.0,1.0,num=nSamples) ),
                                axis=2 )
textureCoordinates  = np.reshape( textureCoordinates, (textureCoordinates.shape[0]*textureCoordinates.shape[1],2) )

# Pack geometry in a mesh node, and create corresponding texture aggregate
root                = MeshNode( vertices=geometry["vertices"], 
                                faces=geometry["faces"],
                                materialID=0,
                                textureCoordinates=textureCoordinates   )

aggregatedTexture   = AggregatedTexture( shape=(2*len(texture), 2*len(texture[0])) )
aggregatedTexture.registerTexture( texture, 0 )

# Create OpenGL window
meshApp             = MeshApp3D(    root,
                                    aggregatedTexture=aggregatedTexture,
                                    light=TimedSpotLight )

meshApp.view.camera.center          = np.asarray( [0.0,0.0,0.0], dtype=np.float32 )
meshApp.mesh.light._colorFunctor    = lambda t : (1.0,1.0,1.0)
meshApp.mesh.light._posFunctor      = lambda t : (0.0,0.0,10*np.cos(t))
meshApp.mesh.light._color           = (1.0,1.0,1.0)

meshApp.run()
Beispiel #2
0
textureDim = (1.5 * textureXY.shape[0], 1.5 * textureXY.shape[1])

agg = AggregatedTexture(shape=textureDim)
agg.registerTexture(textureXY,
                    0,
                    ambientMaterialConstant=0.5,
                    diffuseMaterialConstant=0.5,
                    specularMaterialConstant=1.0)

# -----------------------------------------------------------
root = MeshNode(vertices=v1,
                faces=f1,
                textureCoordinates=tc1,
                objectID=0,
                materialID=0)

# -----------------------------------------------------------
mApp = MeshApp3D(root, agg)

mApp.mesh.light._pos = np.array((0.5, 0.5, 0.5), dtype=np.float32)

floatSize = 4
pointSize = 3 * floatSize
triangleSize = 3 * pointSize

print(mApp.mesh._vertexBuffer.nbytes)
newPos = np.array(((0.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 0.0, 0.0)),
                  dtype=np.float32)
mApp.mesh._vertexBuffer.set_subdata(newPos, offset=3)

mApp.run()
Beispiel #3
0
# --- Lighting imports ---
from ciegl.lighting import TimedSpotLight

# -----------------------------------------------------------
# Torus parameters
radius1 = 1.0
radius2 = 0.2

U = np.linspace(0.0, 2 * np.pi, 100)
V = np.linspace(0.0, -2 * np.pi, 100)

torus = ParametricSurface(
    (lambda u, v: np.cos(u) *
     (radius1 + radius2 * np.cos(v)), lambda u, v: np.sin(u) *
     (radius1 + radius2 * np.cos(v)), lambda u, v: radius2 * np.sin(v)),
    domain=((min(U), max(U)), (min(V), max(V))))
# -----------------------------------------------------------
# Pack geometry in a mesh node
geometry = convertToSurfaceMesh(torus.evaluate(U, V))
root = MeshNode(vertices=geometry["vertices"], faces=geometry["faces"])

# Create GL window
meshApp = MeshApp3D(root, light=TimedSpotLight)

meshApp.view.camera.center = np.asarray([0.0, 0.0, 0.0], dtype=np.float32)
meshApp.mesh.light._colorFunctor = lambda t: (1.0, 1.0, 1.0)
meshApp.mesh.light._posFunctor = lambda t: (0.0, 0.0, 10 *
                                            (radius1 + radius2) * np.cos(t))

meshApp.run()
Beispiel #4
0
                objectID=0,
                materialID=0)

root.addChild(
    MeshNode(parent=root,
             vertices=sphere2["vertices"],
             faces=sphere2["faces"],
             objectID=1,
             materialID=0))

# Get mesh sizes
meshSizes = (root.computeCompiledMeshSize(),
             root.child(0).computeCompiledMeshSize())

# Create app
meshApp = MeshApp3D(root)
meshApp.view.camera.center = [1.5, 0.0, 0.0]
meshApp.mesh.light._pos = [1.5, 0.0, 0.0]

# Define translation function
t0 = default_timer()


def translateMesh(translation):
    for triangleIndex in range(len(root._vertices)):
        for componentIndex, displacementComponent in enumerate(translation):
            root._vertices[triangleIndex][
                componentIndex] = displacementComponent


def on_timer(event):