Exemplo n.º 1
0
                                            domain=((0.0,2*np.pi),(0.0,-2*np.pi)) )

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)
Exemplo n.º 2
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()
Exemplo n.º 3
0
sphere1 = Sphere(1.0, [0.0, 0.0, 0.0])
sphere2 = Sphere(1.0, [3.0, 0.0, 0.0])

# Sample
nSamples = 50
sphere1 = convertToSurfaceMesh(
    sphere1.evaluate(sphere1.u(nSamples=nSamples),
                     sphere1.v(nSamples=nSamples)))
sphere2 = convertToSurfaceMesh(
    sphere2.evaluate(sphere2.u(nSamples=nSamples),
                     sphere2.v(nSamples=nSamples)))

# Load geometries in mesh nodes
root = MeshNode(parent=None,
                vertices=sphere1["vertices"],
                faces=sphere1["faces"],
                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
Exemplo n.º 4
0
# -----------------------------------------------------------
textureXY = loadTexture(textureFolderPath + '/cage.png')
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)
Exemplo n.º 5
0
                    ambientMaterialConstant=0.5,
                    diffuseMaterialConstant=0.5,
                    specularMaterialConstant=1.0)

vertexShader, fragmentShader = agg.generateShaderCode()

with open('AggregatedVertexShader.txt', 'w') as file:
    file.write(vertexShader)

with open('AggregatedFragmentShader.txt', 'w') as file:
    file.write(fragmentShader)

# -----------------------------------------------------------
root = MeshNode(vertices=v1,
                faces=f1,
                textureCoordinates=tc1,
                objectID=0,
                materialID=0)
root.addChild(
    MeshNode(vertices=v2,
             faces=f2,
             textureCoordinates=tc2,
             objectID=1,
             materialID=1))
root.addChild(
    MeshNode(vertices=v3,
             faces=f3,
             textureCoordinates=tc3,
             objectID=2,
             materialID=2))