Jump to content

Stop drawing multiple objects on the same position


Brunex92
 Share

Recommended Posts

Hey!

So, I've programming on javascript for not so long, and I'm trying to do this simple project where I get data from a matrix and draw in canvas, just like this playground:

http://playground.babylonjs.com/#191SVM#0

Problem is...  Everytime I call the function, it will always draw the center sphere, multiple times, which obviously is not what is intendend...

Anyone can help me with that? Like using an exception everytime it tries to draw an object where it alredy is

This looks really simple to do, but I have not idea how do I get the data from the object before I draw it


Thanks :)

Link to comment
Share on other sites

On 12/8/2016 at 12:41 PM, JohnK said:

Not entirely sure what you are trying to achieve. Have given each row of the matrix a different colour and where y variables for matrix[4] gave same positions changed them by radius of sphere. Hope that this might help.

http://playground.babylonjs.com/#191SVM#1

I actually need that these objects are linked through a center object, so changing its position won't work for me, the point is everytime I call the function to draw it, the center object will be rendered over and over again, until the loop is over, because that's how my code works.

First I set its color, using the matrix[6], matrix[7], matrix[8], then I draw the the external sphere using the matrix[0],[1],[2], then the center one with the rest of it, linking both of the spheres.

So what I want is once I draw the center one time, it won't be rendered again when the loop finds it again, only the external sphere

Link to comment
Share on other sites

On 12/9/2016 at 12:27 AM, Nabroski said:

@Brunex92 Can't see any sphere in the middle can you comment the problematic code out, so i can comment it in again and debug

Sure!
http://playground.babylonjs.com/#191SVM#3

Lines 69-80

There you go, the center spheres in this playground are [10, 0, 10,] and [0, 0, 0] they are linked to external spheres.
Imagine it as a cluster or a network, every PC is connected to a router, the router is the center sphere, the PCs are the external ones.

Link to comment
Share on other sites

Ahhh now I understand in your scene there are two center sphere, one for the grey network and one for the black network, whereas I and, perhaps, Nabroski were wondering where this group of overlapping sphere were in your scene.

An example like this may have helped http://playground.babylonjs.com/#191SVM#5

Unless you are firmly wedded to the data structure you have currently then maybe a different data structure would be better.

Link to comment
Share on other sites

On 12/9/2016 at 12:34 PM, JohnK said:

Ahhh now I understand in your scene there are two center sphere, one for the grey network and one for the black network, whereas I and, perhaps, Nabroski were wondering where this group of overlapping sphere were in your scene.

An example like this may have helped http://playground.babylonjs.com/#191SVM#5

Unless you are firmly wedded to the data structure you have currently then maybe a different data structure would be better.

Hmm, they're still there, on this PG you provided, there are 6 center spheres at the [0, 0, 0], and that is exactly what I dont want, there are 5 unnecessary objects

Also, which data structure you think it would be better to use?

Link to comment
Share on other sites

Sorry perhaps I wasn't clear, I did not say the playground solved your problem only that it was much clearer in showing what the problem is. Each cylinder has a central red mesh which is drawn for each cylinder. What is required is that the central red mesh is only drawn once.

Cannot help with a new data structure now as my dinner is about to be served. I will have a look after dinner. In the meantiime perhaps someone else will have a look at the thread.

Link to comment
Share on other sites

On 12/9/2016 at 2:22 PM, JohnK said:

A change of data structure - centre only drawn once

http://playground.babylonjs.com/#191SVM#6

Hmmm, that will only work if I know the centers, my project is a little bit different, I load a text file with the matrix, read it and the draw it, so I don't know what are the centers.

On 12/9/2016 at 3:55 PM, Nabroski said:

if its possible to redefine your matrix you can stop in a for loop like this
http://playground.babylonjs.com/#191SVM#7

http://www.w3schools.com/js/js_break.asp

I can't as said above.

Link to comment
Share on other sites

On 12/9/2016 at 5:30 PM, Brunex92 said:

Hmmm, that will only work if I know the centers, my project is a little bit different, I load a text file with the matrix, read it and the draw it, so I don't know what are the centers.

So keep the same incoming data structure, do a conversion into a data structure where the centres and colours are only stored once and then draw networks.

http://playground.babylonjs.com/#191SVM#10

This time with a more random selection of nodes and centres.

http://playground.babylonjs.com/#191SVM#11

Link to comment
Share on other sites

On 12/10/2016 at 3:54 AM, JohnK said:

So keep the same incoming data structure, do a conversion into a data structure where the centres and colours are only stored once and then draw networks.

http://playground.babylonjs.com/#191SVM#10

This time with a more random selection of nodes and centres.

http://playground.babylonjs.com/#191SVM#11

http://playground.babylonjs.com/#191SVM#11  - That works perfectly! Thanks a lot :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...