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

tristrips not working because MESH_PARAMETERS not defined for it #79

Closed
j4yk opened this issue Dec 2, 2014 · 2 comments
Closed

tristrips not working because MESH_PARAMETERS not defined for it #79

j4yk opened this issue Dec 2, 2014 · 2 comments
Milestone

Comments

@j4yk
Copy link
Contributor

j4yk commented Dec 2, 2014

I am currently investigating XML3D as an export option for a 3D graphics application. For prototyping I generated the following xml3d:

    <xml3d xmlns="http://www.xml3d.org/2009/xml3d">
        <view position="0 0 1"/>
        <shader id="mapShader" script="urn:xml3d:shader:flat">
            <bool name="useVertexColor">true</bool>
        </shader>
        <mesh type="tristrips" shader="#mapShader">
            <int name="index">0 6 4 5 0 <!-- etc. --></int>
            <float3 name="position">-0.5 -0.5 -0.025 -0.5 -0.5 0.025 -0.5 0.5 -0.025 -0.5 0.5 0.025 0.5 -0.5 -0.025 0.5 -0.5 0.025 0.5 0.5 -0.025 0.5 0.5 0.025 0.155431 0.156691 0.025 0.155431 0.156691 0.075 0.155431 0.357603 <!-- etc --> </float3>
            <float3 name="color">0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 <!-- etc --></float3>
        </mesh>
    </xml3d>

Without a little modification in xml3d.js this will not work in Chrome, however. For gl.TRIANGLE_STRIP no MESH_PARAMETERS are defined which leads to the following error in Chrome:

Unsupported Mesh request: GLMesh {context: GLContext, glType: 5, buffers: Object, uniformOverride: Object, minIndex: 0…} 5

...and subsequently errors of the type Cannot read property ... of null.

These lines are in xml3d.js but leave out triangle strips:

MESH_PARAMETERS[WebGLRenderingContext.TRIANGLES] = {
    attributeData: {"position": Xflow.DATA_TYPE.FLOAT3 },
    typeData: {
        "index": Xflow.DATA_TYPE.INT,
        "solid": Xflow.DATA_TYPE.BOOL,
        "vertexCount": Xflow.DATA_TYPE.INT
    },
    bboxFix: {
        "boundingBox" : Xflow.DATA_TYPE.FLOAT3
    },
    bboxCompute: {
        "position" : Xflow.DATA_TYPE.FLOAT3
    } };
MESH_PARAMETERS[WebGLRenderingContext.LINE_STRIP] = MESH_PARAMETERS[WebGLRenderingContext.TRIANGLES];
MESH_PARAMETERS[WebGLRenderingContext.LINES] = MESH_PARAMETERS[WebGLRenderingContext.TRIANGLES];
MESH_PARAMETERS[WebGLRenderingContext.POINTS] = MESH_PARAMETERS[WebGLRenderingContext.TRIANGLES];

adding this line seems to solve my problem:

MESH_PARAMETERS[WebGLRenderingContext.TRIANGLE_STRIP] = MESH_PARAMETERS[WebGLRenderingContext.TRIANGLES];

Can you tell me if triangle strips were left out there by intention or if they have just been forgotten?

Minimal example:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script src="http://www.xml3d.org/xml3d/script/xml3d.js" type="text/javascript"/>
        <script src="http://www.xml3d.org/xml3d/script/tools/camera.js" type="text/javascript"/>
    </head>
    <body>
        <xml3d xmlns="http://www.xml3d.org/2009/xml3d">
            <view position="0 0 1"/>
            <mesh type="tristrips">
                <int name="index">0 1 2 3</int>
                <float3 name="position">
                -1 -1 0
                 1 -1 0
                -1  1 0
                 1  1 0
                 </float3>
            </mesh>
        </xml3d>
    </body>
</html>

I would expect a rectangle but get the above error message.

@ksons
Copy link

ksons commented Dec 2, 2014

@j4yk: No, triangles strips are not ommited intenionally. However, the solution that you skecth above would allow a single strip only and your exporter to create degenerated triangles in the strip in order to export a complex geometry in a single mesh element.

A good solution would be to have an additional (optional) count entry that triggers multiple triangle strip calls. Similar to the last parameter of glMultiDrawElements), which is not available in current WebGL but easy to emulate.

I'd suggest to add the additional line you suggested and open an enhancment issue for a way to draw multiple primitives (would also apply to other primitives).

What do you think? Do you want to create a pull requrest?

@j4yk
Copy link
Contributor Author

j4yk commented Dec 2, 2014

Thank you for your reply. As my work is in a very early stage and I still have much to learn about XML3D that exporter really creates degenerated triangles at the moment.

I can certainly open a pull request later but I will have to search for the appropriate source file. Feel free to add that line yourself if you want and have time and I have not opened a request yet. ;-)

I think I do not understand your count proposal. Where should that count go (an attribute of mesh or an element of something)? Staying close to glMultiDrawElements, how would you separate the index arrays? Maybe you could also just allow multiple int subelements with the name "index". What I would have liked to have in the first place was primitive restart which is unfortunately also not available in WebGL afaik. But maybe you could even emulate that, depending on what solution for multi drawing you have in mind.

ksons pushed a commit that referenced this issue Dec 5, 2014
Added test that fails without fix
Fixed #79
@ksons ksons added this to the 4.8 Release milestone Dec 5, 2014
ksons pushed a commit that referenced this issue Dec 5, 2014
Added test that fails without fix
Fixed #79
ksons pushed a commit that referenced this issue Dec 15, 2014
Added test that fails without fix
Fixed #79
@ksons ksons closed this as completed in aebba13 Dec 19, 2014
ksons pushed a commit that referenced this issue Jan 6, 2015
Added test that fails without fix
Fixed #79
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants