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

Shape triangulation with holes error #48

Open
sguionni opened this issue Dec 2, 2015 · 35 comments
Open

Shape triangulation with holes error #48

sguionni opened this issue Dec 2, 2015 · 35 comments
Assignees
Labels

Comments

@sguionni
Copy link
Contributor

sguionni commented Dec 2, 2015

Hello,

i have a problem with the shape with holes extrusion.

I created a shape with a hole inside. But i have a console error : SEVERE: ShapeUtils: removeHoles() ERROR (but not at any time).

My code :

    public static Shape computeShape ( final PWPModelProduct p_product )
    {
        PWPModelLevel level;
        Shape shape;
        List< Vector2 > arrPoint;
        final int xMin, xMax, yMin, yMax;
        // ------------ DECLARE ------------//

        level = p_product.getLevel();
        shape = new Shape();
        arrPoint = new ArrayList< >();

        xMin = p_product.getOffsetLeft();
        xMax = level.getWallWidth() - p_product.getOffsetRight();
        yMin = level.getPlinthHeight() + p_product.getOffsetBottom();
        yMax = level.getWallHeight() - level.getCorniceHeight() - p_product.getOffsetTop();
        // ------------- INIT --------------//

        arrPoint.add( new Vector2( xMin, yMin ) );
        arrPoint.add( new Vector2( xMax, yMin ) );
        arrPoint.add( new Vector2( xMax, yMax ) );
        arrPoint.add( new Vector2( xMin, yMax ) );

        shape.fromPoints( arrPoint );

        PWPManagerProduct.computeHoles( shape, level.getArrFurniture(), p_product.getOffsetFurniture() );

        return shape;
    }

    private static void computeHoles ( final Shape p_shape, final List< PWPModelFurniture > p_arrFurniture,
            final int p_offset )
    {
        List< Path > arrHole;
        Path hole;
        List< Vector2 > arrPoint;
        int xMin, xMax, yMin, yMax;
        // ------------ DECLARE ------------//

        arrHole = p_shape.getHoles();
        // ------------- INIT --------------//

        for ( final PWPModelFurniture furniture : p_arrFurniture )
        {
            // Create bbox.
            xMin = (int)furniture.getPosition().getX() - p_offset;
            xMax = (int)furniture.getPosition().getX() + furniture.getWidth() + p_offset;
            yMin = (int)furniture.getPosition().getY() - p_offset;
            yMax = (int)furniture.getPosition().getY() + furniture.getHeight() + p_offset;

            arrPoint = new ArrayList< >();
            arrPoint.add( new Vector2( xMin, yMin ) );
            arrPoint.add( new Vector2( xMax, yMin ));
            arrPoint.add( new Vector2( xMax, yMax ));
            arrPoint.add( new Vector2( xMin, yMax ) );
            hole = new Path( arrPoint );

            // Add to holes list.
            arrHole.add( hole );
        }
    }

Then i create a geometry with this shape and the error occurs.

ExtrudeGeometryParameters param;
        MeshPhongMaterial mat;
        // ------------ DECLARE ------------//

        param = new ExtrudeGeometryParameters();
        mat = new MeshPhongMaterial();
        // ------------- INIT --------------//

        param.bevelEnabled = false;
        param.amount = 1;

        this.setGeometry( p_shape.extrude( param ) );

Note that the 3D result sometimes seems ok, sometimes not.
Then, if my hole is over a shape edge, i have another message: WARNING: FontUtils: triangulate() - Warning, unable to triangulate polygon!
In this case, the 3D result is always wrong.

EDIT: Some screen shots

Result seems ok but error in console:
Image

Multiple holes problem:
Image

Problem when hole is on a shape edge:
Image

@thothbot
Copy link
Owner

thothbot commented Dec 2, 2015

This is known issue, which occurs when a hole is outside of the element.

@thothbot
Copy link
Owner

thothbot commented Dec 2, 2015

You need to make sure that a hole is inside

@sguionni
Copy link
Contributor Author

sguionni commented Dec 2, 2015

Ok but multiple holes inside a shape causes a bug too as you can see is the second screenshot.
And an error occurs sometimes with hole inside (screenshot 1).

@thothbot
Copy link
Owner

thothbot commented Dec 2, 2015

Ok, I'll investigate this issue during preparing 1.7

@thothbot thothbot added the bug label Dec 2, 2015
@sguionni
Copy link
Contributor Author

sguionni commented Dec 2, 2015

Ok thank you,
i found some reports about these bugs like on this post : mrdoob/three.js#3386

@sguionni
Copy link
Contributor Author

sguionni commented Dec 8, 2015

Do you know if it's possible to put holes on the edge in the last Threejs version ?
I'm investigating in the ShapeUtils code but if no solutions was found i have to find an alternative solution.

@thothbot
Copy link
Owner

thothbot commented Dec 8, 2015

yes it should be possible in threejs, I did this few month ago. I don't remember my approach, but it was working

@sguionni
Copy link
Contributor Author

sguionni commented Dec 8, 2015

Great, so if the Parallax shape/extrude geometry code is updated according Threejs history, all should work.

@thothbot
Copy link
Owner

thothbot commented Dec 8, 2015

Yep, it should be,
As you know I'm working on Parallax 2.0, so I hope all will be there asap. Also I'll update development documentation, so I hope someone will help me with all of this

@sguionni
Copy link
Contributor Author

sguionni commented Dec 8, 2015

Ok, do you think if i start translating ShapeUtils from the last Threejs is a good idea ?

@thothbot
Copy link
Owner

thothbot commented Dec 8, 2015

Yeah, will be cool, but you need to do this on the master branch, dev branch is not ready yet for the new version, later we can merge your changes to the new Parallax version. But as I know you need to update some other libs :) especially under the math package.

So if you ready, make your changes in the master branch.

@sguionni
Copy link
Contributor Author

sguionni commented Dec 8, 2015

Yes ok , i think i'll update FontUtils too, some code has moved to ShapeUtils.

@thothbot
Copy link
Owner

thothbot commented Dec 8, 2015

Will be cool, we need FontUtils as well

@sguionni
Copy link
Contributor Author

sguionni commented Dec 9, 2015

I can't push to the master branch (git-receive-pack not permitted).

@thothbot
Copy link
Owner

thothbot commented Dec 9, 2015

I think you need to make a pull request to the master branch

@sguionni
Copy link
Contributor Author

sguionni commented Dec 9, 2015

Yes ok i was connected to your remote repo instead of my fork.

@sguionni
Copy link
Contributor Author

sguionni commented Dec 9, 2015

I translated the code from Threejs for ShapeUtils but i have some problems, some triangles are not triangulated, or by a bad way.
I have no more time to spend now, do you want a pull request now or later if i have more time ?

@thothbot
Copy link
Owner

thothbot commented Dec 9, 2015

take your time, you can push later, you can write me by email, will be easy to communicate.

@sguionni
Copy link
Contributor Author

I think i will try something else :
Files like ShapeUtils (which only one function is called from ExtrudeGeometry and ShapeGeometry), are not really usefull in java code. I think we can make a JNSI bridge and use the original javascript source file to avoid javacript to java translation that GWT re-translate in javascript.
What do you think about ?

@thothbot
Copy link
Owner

The main question here that we need to use java code to run Parallax on Android etc, not just js. So we need Java version of that stuff

@sguionni
Copy link
Contributor Author

Can you explain me how it works for android ?
Java code is not translated ? I don't understand how you can use Threejs by this way.

@thothbot
Copy link
Owner

In 2.0 we will use Parallax Java library for android to make native applications.

@sguionni
Copy link
Contributor Author

Ok,
i have some results but i have few problems remaining.

Do you know how to properly remove a geometry ?
For example i have to update a shape dynamicaly so i recreate an ExtrudeGeometry in the current mesh but i don't know if the last geometry is correctly diposed, the geometry counter increments each time.

@thothbot
Copy link
Owner

geometry is an instance of WebGLGeometry

just do

geometry.dispose()

@sguionni
Copy link
Contributor Author

I tried but the geometry counter don't decrement.

@thothbot
Copy link
Owner

yes, it is normal

@thothbot
Copy link
Owner

I have merged your last changes to the Parallax master branch. Please make sure there is right author defined in your new files

@thothbot thothbot added this to the ver 2.0 milestone Jan 27, 2016
@thothbot thothbot self-assigned this Jan 27, 2016
@sguionni
Copy link
Contributor Author

Hi, do you have some news about this issue ?
In the version i use, the triangulation is bugged with 1 hole :

sans titre 2

@thothbot
Copy link
Owner

Hi Simon. I thought you are working on this issue.

@sguionni
Copy link
Contributor Author

Alex, I was but I didn't found the bug.
Then you said me that last threejs code will be ported for the V2 so i didn't investigated anymore.

@thothbot
Copy link
Owner

Ah I see, ok I'll update this soon,

btw, basically the issue if the hole coordinates outside of a shape

@sguionni
Copy link
Contributor Author

In my example the hole is inside the shape.

@sguionni
Copy link
Contributor Author

sguionni commented Jan 5, 2017

Hi Alex, do you know if this bug is fixed now ?

@thothbot
Copy link
Owner

thothbot commented Jan 9, 2017

Hi Simon, I guess no, I have no time)

@sguionni
Copy link
Contributor Author

sguionni commented Jan 9, 2017

No problem, my ex boss is just askin but i'm no longer working for him

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

No branches or pull requests

2 participants