Python: Cube created in py not showing up in the viewer

trying to cobble together a few samples but I cant get the actual mesh to show up. the stream is created, the properties are there. but the viewer online has no geometry

def CreateCube():

            # Create a SpeckleMesh

            sm = so.Mesh()

            sm.vertices = [0,0,0,1,0,0,1,1,0,0,1,0]

            sm.faces=[1,0,1,2,3]

            sm.name = "the mesh"

            return sm

        class Block(Base):

            length: float

            width: float

            height: float

            origin: so.Point = None

            def __init__(self, length=1.0, width=1.0, height=1.0, origin=so.Point(), **kwargs) -> None:

                super().__init__(**kwargs)

                # mark the origin as a detachable attribute

                cube = CreateCube()

                self.add_detachable_attrs({"cube"})

                self.length = length

                self.width = width

                self.height = height

                self.origin = origin

Send us a link to the offending cube and we’ll try to poke at it and see what’s going wrong!

never mind, i forgot to add the mesh as an argument
def init(self, length=1.0, width=1.0, height=1.0, origin=so.Point(), cube=None, **kwargs) → None:

now on to the real work

2 Likes

hello again!

what is the best way to send a list of objects over

I currently have this

  # next create a server transport - this is the vehicle through which you will send and receive
        transport = ServerTransport(client, new_stream_id)

        # this serialises the block and sends it to the transport
        hash = operations.send(base=convertedMeshes[0], transports=[transport])

        # you can now create a commit on your stream with this object
        commid_id = client.commit.create(
            stream_id= new_stream_id, 
            object_id= hash, 
            message= "this is a block I made in speckle-py",
            )

ConvertedMeshes is an array, it works for 1 but how about many? maybe point to a sample?

Not a py expert here, but something like this should do:

base_obj = Base()
base_obj.name = "my base"
base_obj["@mylist"] = mylist

By using the @ before the prop name Speckle will detach your objects, which is recommended for geometry. You can read about it here.

Let us know if you’d like to see more examples in our docs and we’ll add them!

cc @gergo @izzylys

perfect, that worked. all meshes successfully sent. next problem
none show up in the view. am I not building the mesh right?

A sample mesh would be really really helpful… - of the top of my head it looks right, besides the faces list! What’s that array doing in there?

image

Sample object please!

from what I saw in the documents you just output a list of ints for the face list, is this not right, what should the face list look like? is it [[0,2,1], [2.4.1]] like that?

it looks like

  • 3, index, index, index - if it’s a triangle, (old: 0, index, index, index - 0 stands for triangles)
  • 4, index, index, index, index - if it’s a quad, (old: 1, index, index, index - 1 stands for quads)
  • n, index, index, …, index_n - for ngons

Edit: all into one flat array, not an array of arrays.

@Jedd should correct me if i’m wrong :sweat_smile:

so the array should look like this?
[[0, 2,3,5],[1,4,3,6,5], [n,3,2,4,3,6,7]]

or this
[0,2,3,5,1,4,3,6,5,n,3,2,4,3,6,7]

second option is the winner :+1:t3:

1 Like

just to confirm i don’t actually use “n” I use the actual face vert count right?

1 Like

That’s correct.
So for example, for a pentagon you would use 5, hexagon 6, etc.

I’m not sure if this helps, but I have this crudely drawn diagram.

It shows n=1 for quads and n=0 for triangles, which was our older system before we supported n-gons.
n = 1 and n = 4 are equivalent, as is 0 and 3 to retain backwards compatiblity.

3 Likes

perfect, so i don’t have to use 0 and 1 I can actually just use 3 and 4 now

1 Like

As a note though - @Jedd made me check just now :smiley: - we haven’t really gotten to implement that in the viewer yet:

We’re still stuck with the 1 for quads and 0s for triangles. I can prob push a very fast hotfix now, but it will only be deployed on to our staging server.

Sorry for backtracking on this!

Edit: issue raised here for the viewer.

1 Like

i assume if i have 10 meshes and 5 of them are tri or quads and the other 5 have ngons that only the 5 will show up. which for me right now is ok

thanks for the great help all works as expected now…no… all works better than expected now!

3 Likes