Example #1
0
def get_bounds(path):
    pathkey = 'BOUNDS_' + str(path)
    if pathkey not in SHELF:
        metadata, mesh = open3dhub.path_to_mesh(path)
        SHELF[pathkey] = getBoundsInfo(mesh)

    return SHELF[pathkey]
Example #2
0
def get_bounds(path):
    pathkey = 'BOUNDS_' + str(path)
    if pathkey not in SHELF:
        metadata, mesh = open3dhub.path_to_mesh(path)
        SHELF[pathkey] = getBoundsInfo(mesh)
    
    return SHELF[pathkey]
Example #3
0
def getJSON(mesh):
    cameras = []
    for cam in mesh.cameras:
        cameras.append({'id':cam.id})
        
    lights = []
    for light in mesh.lights:
        lights.append({'id':light.id, 'type': type(light).__name__})
        
    materials = []
    for material in mesh.materials:
        materials.append({'id':material.id, 'effect':material.effect.id})
        
    effects = []
    for effect in mesh.effects:
        effects.append({'id':effect.id, 'type':effect.shadingtype})
        
    images = []
    for image in mesh.images:
        images.append({'id':image.id, 'name':image.path})
        
    primitives = []
    for geom in mesh.geometries:
        for i, prim in enumerate(geom.primitives):
            primitives.append({'id':"%s%d" % (geom.id, i),
                               'type':type(prim).__name__,
                               'vertices':len(prim.vertex_index) if prim.vertex_index is not None else 0,
                               'normals': prim.normal_index is not None,
                               'texcoords': len(prim.texcoord_indexset) > 0})
        
    json_ret = {'cameras': cameras,
                'lights': lights,
                'materials': materials,
                'effects': effects,
                'images': images,
                'primitives': primitives}
    
    json_ret.update(getRenderInfo(mesh))
    
    boundsInfo = getBoundsInfo(mesh)
    boundsInfo = {'bounds': [boundsInfo['bounds'][0].tolist(), boundsInfo['bounds'][1].tolist()],
                  'center': boundsInfo['center'].tolist(),
                  'center_farthest': boundsInfo['center_farthest'].tolist(),
                  'center_farthest_distance': float(boundsInfo['center_farthest_distance'])}
    json_ret['bounds_info'] = boundsInfo
    
    return json.dumps(json_ret)
Example #4
0
def getJSON(mesh):
    cameras = []
    for cam in mesh.cameras:
        cameras.append({'id': cam.id})

    lights = []
    for light in mesh.lights:
        lights.append({'id': light.id, 'type': type(light).__name__})

    materials = []
    for material in mesh.materials:
        materials.append({'id': material.id, 'effect': material.effect.id})

    effects = []
    for effect in mesh.effects:
        effects.append({'id': effect.id, 'type': effect.shadingtype})

    images = []
    for image in mesh.images:
        images.append({'id': image.id, 'name': image.path})

    primitives = []
    for geom in mesh.geometries:
        for i, prim in enumerate(geom.primitives):
            primitives.append({
                'id':
                "%s%d" % (geom.id, i),
                'type':
                type(prim).__name__,
                'vertices':
                len(prim.vertex_index) if prim.vertex_index is not None else 0,
                'normals':
                prim.normal_index is not None,
                'texcoords':
                len(prim.texcoord_indexset) > 0
            })

    json_ret = {
        'cameras': cameras,
        'lights': lights,
        'materials': materials,
        'effects': effects,
        'images': images,
        'primitives': primitives
    }

    json_ret.update(getRenderInfo(mesh))

    boundsInfo = getBoundsInfo(mesh)
    boundsInfo = {
        'bounds':
        [boundsInfo['bounds'][0].tolist(), boundsInfo['bounds'][1].tolist()],
        'center':
        boundsInfo['center'].tolist(),
        'center_farthest':
        boundsInfo['center_farthest'].tolist(),
        'center_farthest_distance':
        float(boundsInfo['center_farthest_distance'])
    }
    json_ret['bounds_info'] = boundsInfo

    return json.dumps(json_ret)
Example #5
0
f = open(folder + filename)
mesh = collada.Collada(f)

geom = mesh.geometries[0]
geom.primitives

triset = geom.primitives[0]
trilist = list(triset)
len(trilist)
print len(triset.vertex)

trilist[0]
triset.vertex[triset.vertex_index][0]

taylor = getBoundsInfo(mesh)

print taylor['bounds']












Example #6
0
    def __init__(self, models):
        ShowBase.ShowBase.__init__(self)

        self.models = models

        unique_meshes = set(m.mesh for m in models)
        mesh2nodepath = {}
        for mesh in unique_meshes:
            scene_members = pcore.getSceneMembers(mesh)

            rotateNode = p3d.GeomNode("rotater")
            rotatePath = p3d.NodePath(rotateNode)
            matrix = numpy.identity(4)
            if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
                r = collada.scene.RotateTransform(0, 1, 0, 90)
                matrix = r.matrix
            elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
                r = collada.scene.RotateTransform(1, 0, 0, 90)
                matrix = r.matrix
            rotatePath.setMat(p3d.Mat4(*matrix.T.flatten().tolist()))

            rbc = p3d.RigidBodyCombiner('combiner')
            rbcPath = rotatePath.attachNewNode(rbc)

            for geom, renderstate, mat4 in scene_members:
                node = p3d.GeomNode("primitive")
                node.addGeom(geom)
                if renderstate is not None:
                    node.setGeomState(0, renderstate)
                geomPath = rbcPath.attachNewNode(node)
                geomPath.setMat(mat4)

            rbc.collect()

            mesh2nodepath[mesh] = centerAndScale(
                rotatePath, print_bounds.getBoundsInfo(mesh))

        scenepath = render.attachNewNode("scene")
        for model in self.models:
            np = mesh2nodepath[model.mesh]
            instance = scenepath.attachNewNode("model")
            np.instanceTo(instance)
            instance.setPos(model.x, model.y, model.z)
            instance.setScale(model.scale, model.scale, model.scale)
            q = p3d.Quat()
            q.setI(model.orient_x)
            q.setJ(model.orient_y)
            q.setK(model.orient_z)
            q.setR(model.orient_w)
            instance.setQuat(q)

        base.camLens.setFar(sys.maxint)
        base.camLens.setNear(8.0)

        pcore.attachLights(render)

        render.setShaderAuto()
        render.setTransparency(p3d.TransparencyAttrib.MDual, 1)
        render.setAntialias(p3d.AntialiasAttrib.MAuto)

        controls.KeyboardMovement()
        controls.ButtonUtils(scenepath)
        controls.MouseDrag(scenepath)
        controls.MouseCamera()
        controls.MouseScaleZoom(scenepath)
Example #7
0
    def __init__(self, models):
        ShowBase.ShowBase.__init__(self)
        
        self.models = models
        
        unique_meshes = set(m.mesh for m in models)
        mesh2nodepath = {}
        for mesh in unique_meshes:
            scene_members = pcore.getSceneMembers(mesh)
            
            rotateNode = p3d.GeomNode("rotater")
            rotatePath = p3d.NodePath(rotateNode)
            matrix = numpy.identity(4)
            if mesh.assetInfo.upaxis == collada.asset.UP_AXIS.X_UP:
                r = collada.scene.RotateTransform(0,1,0,90)
                matrix = r.matrix
            elif mesh.assetInfo.upaxis == collada.asset.UP_AXIS.Y_UP:
                r = collada.scene.RotateTransform(1,0,0,90)
                matrix = r.matrix
            rotatePath.setMat(p3d.Mat4(*matrix.T.flatten().tolist()))
            
            rbc = p3d.RigidBodyCombiner('combiner')
            rbcPath = rotatePath.attachNewNode(rbc)
            
            for geom, renderstate, mat4 in scene_members:
                node = p3d.GeomNode("primitive")
                node.addGeom(geom)
                if renderstate is not None:
                    node.setGeomState(0, renderstate)
                geomPath = rbcPath.attachNewNode(node)
                geomPath.setMat(mat4)
                
            rbc.collect()

            mesh2nodepath[mesh] = centerAndScale(rotatePath, print_bounds.getBoundsInfo(mesh))

        scenepath = render.attachNewNode("scene")
        for model in self.models:
            np = mesh2nodepath[model.mesh]
            instance = scenepath.attachNewNode("model")
            np.instanceTo(instance)
            instance.setPos(model.x, model.y, model.z)
            instance.setScale(model.scale, model.scale, model.scale)
            q = p3d.Quat()
            q.setI(model.orient_x)
            q.setJ(model.orient_y)
            q.setK(model.orient_z)
            q.setR(model.orient_w)
            instance.setQuat(q)

        base.camLens.setFar(sys.maxint)
        base.camLens.setNear(8.0)

        pcore.attachLights(render)

        render.setShaderAuto()
        render.setTransparency(p3d.TransparencyAttrib.MDual, 1)
        render.setAntialias(p3d.AntialiasAttrib.MAuto)

        controls.KeyboardMovement()
        controls.ButtonUtils(scenepath)
        controls.MouseDrag(scenepath)
        controls.MouseCamera()
        controls.MouseScaleZoom(scenepath)