Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

computeLineDistances in BufferGeometry? #7013

Closed
tiansijie opened this issue Aug 18, 2015 · 9 comments
Closed

computeLineDistances in BufferGeometry? #7013

tiansijie opened this issue Aug 18, 2015 · 9 comments

Comments

@tiansijie
Copy link

I tried to create an dashed line material using BufferGeometry. For some reason, it looks like whenever you create an line using LineDashedMaterial, you will need to call this computeLineDistances method. Do we want to add this method inside BufferGeometry as well?

@WestLangley
Copy link
Collaborator

This is a bit more complicated than it appears on the surface.

First of all, Geometry.computeLineDistances() is only correct if the vertices are to be connected in order. If the geometry represents pairs of points -- say for rendering edges of a mesh -- then a different computation is required to properly compute line distances.

In the case of BufferGeometry, we need to add a lineDistance attribute and properly calculate it.

If the geometry is indexed, we can't even do this, because the vertices are reused. So to add a lineDistance attribute to BufferGeometry, the geometry must be of the non-indexed type. That is an unfortunate restriction.

We also need to know if the geometry represents a sequence of points, or a sequence of pairs of points -- same issue as before.

Maybe computeLineDistances() should be a method of THREE.Line, and in r.72dev, THREE.LineSegments.

Remember, we do not know if a geometry represents a line, line segments, or a mesh. This has always been an issue -- just not a particularly problematic one.

@tiansijie
Copy link
Author

I do agree put the computeLineDistances inside THREE.Line is make more sense. If we make computeLineDistances inside THREE.Line and THREE.LineSegments, we still need to differentiate the different between Geometry and BufferGeometry?

I also take a look where threejs are using the lineDistances.
https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLRenderer.js#L3994

However, we have different updates for THREE.BufferGeometry and THREE.Line, I am not sure how we going to combine lineDistances even we move this method inside THREE.Line

@andrevega3
Copy link

I have tried implementing my own computelinedistance into the threejs library for BufferGeometry because I know my positions are in order and do not repeat or have indices, but still does not work. I also may be able to provide the line distances before drawing. Any suggestions how I can get around this limitation(knowing my vertices are non-indexed and in order)?

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 25, 2017

@WestLangley
Copy link
Collaborator

>Any suggestions how I can get around this limitation(knowing my vertices are non-indexed and in order)?

// non-indexed BG -> regular G -> compute line distances
geometry = new THREE.Geometry().fromBufferGeometry( geometry );
geometry.computeLineDistances();

@andrevega3
Copy link

Ahh yes I should of mentioned I tried this solution... it leads me to a TypeError: Cannot read property 'x' of undefined.
right here in three.js
`subVectors: function ( a, b ) {

		this.x = a.x - b.x;
		this.y = a.y - b.y;
		this.z = a.z - b.z;

		return this;

	},`

which seemed to be also discussed here: #6610

@WestLangley
Copy link
Collaborator

@andrevega3 If you are not able to get your code to work, please first get help on a help site.

If you can demonstrate a three.js bug, then please make a new post and provide a link to a live example demonstrating it.

@andrevega3
Copy link

Alright I guess it is not possible to compute line distances without converting to geometry first.
I have posted a new thread addressing the error within the three.js code: #11851

@CarlBateman
Copy link
Contributor

Since the lack of lineDistances in BufferGeometry effectively breaks THREE.ShaderLib.dashed (until the feature's added), would it not be a good idea to have some sort of warning in code and console?

(I just fell down the rabbit hole chasing this, and interesting learning experience, but still.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants