Esempio n. 1
0
    def execute(self, context):
        for object in context.selected_objects:

            bpy.ops.object.transform_apply(location=True,
                                           rotation=True,
                                           scale=True)
            depsgraph = bpy.context.evaluated_depsgraph_get()
            object = object.evaluated_get(depsgraph)
            # Get a BMesh representation
            bm = bmesh.new()  # create an empty BMesh
            bm.from_mesh(object.data)  # fill it in from a Mesh
            bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.001)
            bm.verts.ensure_lookup_table()

            vertices = []

            for v in bm.verts:
                coor = v.co[:]
                vertex = Vertex.ByCoordinates(coor[0], coor[1], coor[2])
                vertices.append(vertex)

            faces = cppyy.gbl.std.list[Face.Ptr]()

            for f in bm.faces:
                vertices_face = []
                for v in f.verts:
                    vertex = vertices[v.index]
                    vertices_face.append(vertex)
                edges = edgesByVertices(vertices_face)
                face = Face.ByEdges(edges)
                faces.push_back(face)

            cc = CellComplex.ByFaces(faces, 0.0001)
            cc1 = TopologyUtility.Translate(cc, 5, 0, 0)
            centroid = Topology.Centroid(cc1)
            cc2 = TopologyUtility.Scale(cc1, centroid, 0.4, 0.4, 1.5)
            cc3 = TopologyUtility.Translate(cc2, -0.45, -0.45, 0)
            cc4 = TopologyUtility.Translate(cc2, 0.45, 0.45, 0)
            cc5 = Topology.Difference(cc1, cc3)
            cc6 = Topology.Difference(cc5, cc4)
            md = meshData(cc6)

            try:
                mesh = bpy.data.meshes.new(name="TopologicMesh")
                mesh.from_pydata(md[0], [], md[1])
                # useful for development when the mesh may be invalid.
                #mesh.validate(verbose=True)
                object_data_add(context, mesh)
                print("success")
            except:
                print("error")
        return {'FINISHED'}
Esempio n. 2
0
def convert_to_py_list(stl_list):
    py_list = []
    i  =  stl_list.begin()
    while (i != stl_list.end()):
        py_list.append( Topology.DeepCopy(i.__deref__()) )
        _ = i.__preinc__()
    return py_list
Esempio n. 3
0
    def execute(self, context):
        for object in context.selected_objects:

            bpy.ops.object.transform_apply(location = True, rotation = True, scale = True)
            depsgraph = bpy.context.evaluated_depsgraph_get()
            object = object.evaluated_get(depsgraph)
            # Get a BMesh representation
            bm = bmesh.new()   # create an empty BMesh
            bm.from_mesh(object.data)   # fill it in from a Mesh
            bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.001)
            bm.verts.ensure_lookup_table()

            vertices = []

            for v in bm.verts:
                coor = v.co[:]
                vertex = Vertex.ByCoordinates(coor[0], coor[1], coor[2])
                vertices.append(vertex)

            faces = cppyy.gbl.std.list[Face.Ptr]()

            for f in bm.faces:
                vertices_face = []
                for v in f.verts:
                    vertex = vertices[v.index]
                    vertices_face.append(vertex)
                edges = edgesByVertices(vertices_face)
                face = Face.ByEdges(edges)
                faces.push_back(face)

            cc = CellComplex.ByFaces(faces, 0.0001)
            cc1 = TopologyUtility.Translate(cc, 5, 0, 0)
            cc2 = TopologyUtility.Translate(cc1, 0.75, 0.75, 0.75)
            cc3 = Topology.Merge(cc1, cc2)

            cells = getSubTopologies(cc3, Cell)   #Cell is the imported class from topologic
            print(str(len(cells))+" cells")
            for i in range(len(cells)):
                print(str(i+1)+". "+cells[i].GetTypeAsString())
                cFaces = getSubTopologies(cells[i], Face)
                print("  "+str(len(cFaces))+" faces")
                for j in range(len(cFaces)):
                    print("   "+str(j+1)+". "+cFaces[j].GetTypeAsString())
                    fVertices = getSubTopologies(cFaces[j], Vertex)
                    print("    "+str(len(fVertices))+" vertices")
                    for k in range(len(fVertices)):
                        print("     "+str(k+1)+". "+fVertices[k].GetTypeAsString())

            md = meshData(cc3)
            print(md)
            try:
                mesh = bpy.data.meshes.new(name="TopologicMesh")
                mesh.from_pydata(md[0], [], md[1])
                # useful for development when the mesh may be invalid.
                #mesh.validate(verbose=True)
                object_data_add(context, mesh)
                print("success")
            except:
                print("error")
        return {'FINISHED'}
Esempio n. 4
0
def triangulate(faces):
    py_triangles = []
    for aFace in faces:
        stl_triangles = cppyy.gbl.std.list[Face.Ptr]()
        FaceUtility.Triangulate(aFace, 0.0, stl_triangles)
        i = stl_triangles.begin()
        while (i != stl_triangles.end()):
            py_triangles.append(
                fixTopologyClass(Topology.DeepCopy(i.__deref__())))
            _ = i.__preinc__()
    return py_triangles
Esempio n. 5
0
 def execute(self, context):
     try:
         f = open("/home/wassim/Downloads/Tower.brep", "r")
         brepString = f.read()
         cc = Topology.ByString(brepString)
         md = meshData(cc)
         mesh = bpy.data.meshes.new(name="TopologicTower")
         mesh.from_pydata(md[0], md[1], md[2])
         object_data_add(context, mesh)
         g = Graph.ByTopology(cc, False, True, False, True, False, False, 0.0001)
         gw = g.Topology()
         mesh = bpy.data.meshes.new(name="TopologicDualGraph")
         md = meshData(gw)
         mesh.from_pydata(md[0], md[1], md[2])
         object_data_add(context, mesh)
         print("success")
     except:
         print("error")
     return {'FINISHED'}
Esempio n. 6
0
def getSubTopologies(topology, subTopologyClass):
  pointer = subTopologyClass.Ptr
  values = cppyy.gbl.std.list[pointer]()
  if subTopologyClass == Vertex:
    _ = topology.Vertices(values)
  elif subTopologyClass == Edge:
    _ = topology.Edges(values)
  elif subTopologyClass == Wire:
    _ = topology.Wires(values)
  elif subTopologyClass == Face:
    _ = topology.Faces(values)
  elif subTopologyClass == Shell:
    _ = topology.Shells(values)
  elif subTopologyClass == Cell:
    _ = topology.Cells(values)
  elif subTopologyClass == CellComplex:
    _ = topology.CellComplexes(values)
 
  py_list = []
  i  =  values.begin()
  while (i != values.end()):
    py_list.append(fixTopologyClass(Topology.DeepCopy(i.__deref__())))
    _ = i.__preinc__()
  return py_list
Esempio n. 7
0
        values.push_back( i )
    return values

def convert_to_py_list(stl_list):
    py_list = []
    i  =  stl_list.begin()
    while (i != stl_list.end()):
        py_list.append( Topology.DeepCopy(i.__deref__()) )
        _ = i.__preinc__()
    return py_list

# Convert Tower to CellComplex
tower = App.ActiveDocument.getObject("tower")
tower.ViewObject.Transparency = 75
towerString = tower.Shape.exportBrepToString()
cellComplex = Topology.ByString(towerString)
cellComplex.__class__ = cppyy.gbl.TopologicCore.Topology
apertures = App.ActiveDocument.getObject("apertures")
apertures.ViewObject.Transparency = 20
aperturesString = apertures.Shape.exportBrepToString()
apertures = Topology.ByString(aperturesString)

apertureFaces = cppyy.gbl.std.list[Face.Ptr]()
apertures.Faces(apertureFaces)

apList = convert_to_py_list(apertureFaces)
for anAperture in apList:
    Aperture.ByTopologyContext(anAperture, cellComplex)

#cellComplex = Topology.AddApertures(cellComplex, apertureFaces)
graph = Graph.ByTopology(cellComplex, False, True, False, False, True, False, 0.0001)
def processItem(item):
    return topologic.Topology.DeepCopy(Topology.ByString(item))
def topologyByGeometry(vts, eds, fcs, tol):
	py_vertices = []
	vertices = cppyy.gbl.std.list[Vertex.Ptr]()

	for v in vts:
		vertex = Vertex.ByCoordinates(v[0], v[1], v[2])
		py_vertices.append(vertex)
		vertices.push_back(vertex)

	edges = cppyy.gbl.std.list[Edge.Ptr]()
	for e in eds:
		sv = py_vertices[e[0]]
		ev = py_vertices[e[1]]
		edge = Edge.ByStartVertexEndVertex(sv, ev)
		edges.push_back(edge)

	faces = cppyy.gbl.std.list[Face.Ptr]()
	for f in fcs:
		faceVertices = []
		for v in f:
			vertex = py_vertices[v]
			faceVertices.append(vertex)
		faceEdges = edgesByVertices(faceVertices)
		face = Face.ByEdges(faceEdges)
		faces.push_back(face)

	result = []
	if len(faces) > 0:
		try:
			cc = CellComplex.ByFaces(faces, tol)
			cells = cppyy.gbl.std.list[Cell.Ptr]()
			_ = cc.Cells(cells)
			if (len(cells) == 1):
				result.append(cells.front())
			else:
				result.append(cc)
		except:
			try:
				c = Cell.ByFaces(faces, tol)
				result.append(c)
			except:
				try:
					s = Shell.ByFaces(faces, tol)
					result.append(s)
				except:
					facesAsTopologies = cppyy.gbl.std.list[Topology.Ptr]()
					for aFace in faces:
						facesAsTopologies.push_back(aFace)
					faceCluster = Cluster.ByTopologies(facesAsTopologies)
					mergedTopology = Topology.SelfMerge(faceCluster)
					mergedTopology.__class__ = classByType(mergedTopology.GetType())
					result.append(mergedTopology)

	elif len(edges) > 1:
		edgesAsTopologies = cppyy.gbl.std.list[Topology.Ptr]()
		for anEdge in edges:
			edgesAsTopologies.push_back(anEdge)
		edgeCluster = Cluster.ByTopologies(edgesAsTopologies)
		mergedTopology = Topology.SelfMerge(edgeCluster)
		mergedTopology.__class__ = classByType(mergedTopology.GetType())
		result.append(mergedTopology)
	elif len(edges) == 1:
		result.append(edges.front())
	elif len(vertices) > 1:
		verticesAsTopologies = cppyy.gbl.std.list[Topology.Ptr]()
		for aVertex in vertices:
			verticesAsTopologies.push_back(aVertex)
		vertexCluster = Cluster.ByTopologies(verticesAsTopologies)
		result.append(vertexCluster)
	elif len(vertices) == 1:
		result.append(vertices.front())
	return result
Esempio n. 10
0
def processItem(item):
	topology = Topology.ByString(item)
	topology = fixTopologyClass(topology)
	return topology
def getTopology(settings, product):
    shape = ifcopenshell.geom.create_shape(settings, product)
    brepString = shape.geometry.brep_data

    return Topology.ByString(brepString)
Esempio n. 12
0
from topologic import Vertex, Edge, Topology
print("START")
print("1. Create Vertex (v1) at 0 0 0")
v1 = Vertex.ByCoordinates(0,0,0)
print("2. Create Vertex (v2) at 20 20 20")
v2 = Vertex.ByCoordinates(20,20,20)
print("3. Create an Edge (e1) connecting v1 to v2")
e1 = Edge.ByStartVertexEndVertex(v1, v2)
print("4. Print the coordinates of the start vertext of e1:")
sv = e1.StartVertex()
print("   "+str([sv.X(), sv.Y(), sv.Z()]))
print("5. Print the coordinates of the end vertext of e1:")
ev = e1.EndVertex()
print("   "+str([ev.X(), ev.Y(), ev.Z()]))
print("6. Print the coordinates of the centroid of e1:")
cv = Topology.Centroid(e1)
print("   "+str([cv.X(), cv.Y(), cv.Z()]))
print("DONE")
Esempio n. 13
0
contract_address = "0x76c2E322138b6cC9D5Fa6D759f4B06BCB5B08b2B"
wallet_private_key = "XXXXXXXXX"
wallet_address = "0x7E01CF301C0F55f0A50100D67cA16aCcD75aE1d8"
infura_url = "https://ropsten.infura.io/v3/bc0151acb1204cacadd049ab3ac000eb"
path = "C:\\Users\\wassimj\\.conda\\envs\\Blender377\\lib\\site-packages"
#message = "Hello From Blender"
number = 377;

contract_abi = "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"IPFSHash\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getIPFSHash\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"myUint\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_IPFSHash\",\"type\":\"string\"}],\"name\":\"setIPFSHash\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_myUint\",\"type\":\"uint256\"}],\"name\":\"setMyUint\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
import time
import sys
sys.path.append(path)
from web3 import Web3, HTTPProvider

from topologic import Vertex, Topology
import cppyy


w3 = Web3(HTTPProvider(infura_url))

smartContract = w3.eth.contract(address=contract_address, abi=contract_abi)
brepString =  smartContract.functions.getIPFSHash().call()
print(brepString)
v2 = Topology.ByString(brepString)
v2.__class__ = Vertex
print([v2.X(), v2.Y(), v2.Z()])
Esempio n. 14
0
v2 = Vertex.ByCoordinates(10, 0, 0)
v3 = Vertex.ByCoordinates(10, 10, 0)

# Connect the vertices by two Edges
e1 = Edge.ByStartVertexEndVertex(v1, v2)
e2 = Edge.ByStartVertexEndVertex(v2, v3)

# Create a Wire from the two connected Edges
edges = cppyy.gbl.std.list[Edge.Ptr]()
edges.push_back(e1)
edges.push_back(e2)
w1 = Wire.ByEdges(edges)

# Compute the Centroid (Vertex) of the Wire
c1 = w1.Centroid()

# Add the Centroid to the Contents of the Wire
contents = cppyy.gbl.std.list[Topology.Ptr]()
contents.push_back(c1)
w1 = w1.AddContents(contents, Wire.Type())

# Retrieve the Contents of the Wire
wireContents = cppyy.gbl.std.list[Topology.Ptr]()
_ = Topology.Contents(w1, wireContents)

# Print the Contents and if they area Vertex, print their coordinates
for aContent in wireContents:
    aContent = fixTopologyClass(aContent)
    if aContent.GetType() == 1:
        print([aContent.X(), aContent.Y(), aContent.Z()])
def getCell(settings, product):
    shape = ifcopenshell.geom.create_shape(settings, product)
    brepString = shape.geometry.brep_data
    topology = Topology.ByString(brepString)

    return getSubTopologies(topology, Cell)[0]