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

(uo) export to glb/gltf has incorrect textures #922

Open
kfarr opened this issue Nov 11, 2024 · 0 comments
Open

(uo) export to glb/gltf has incorrect textures #922

kfarr opened this issue Nov 11, 2024 · 0 comments

Comments

@kfarr
Copy link
Collaborator

kfarr commented Nov 11, 2024

As a user exporting a glb from 3dstreet for use in a third-party app like adobe aero, I want the textures from my 3dstreet scene to loop the same.

some of the layers are still exported differently than how they look in 3DStreets, particularly any lane which comes into AR with a center stripe even if one isn't present in 3DStreet. You can see the center stripe in the bike lane above from this Aero-based screenshot.

Image


issue: many third-party apps don't respect gltf material transformations.

instead: use custom UV mappings for street segments instead of relying on three.js shader for texture repeat; ensure that exported geo with custom UV mappings look correct

Below is an example of a working function to repeat texture using uv coords instead of texture repeat shader


// Usage:      <a-entity geometry="primitive: repeating-plane; width: 3; height: 50; segmentsHeight: 5; segmentsWidth: 1" material="src: #seamless-sidewalk"></a-entity>
AFRAME.registerGeometry('repeating-plane', {
  schema: {
    width: { default: 1, min: 0 },
    height: { default: 1, min: 0 },
    segmentsWidth: { default: 1, min: 1, max: 20, type: 'int' },
    segmentsHeight: { default: 1, min: 1, max: 20, type: 'int' }
  },
  init: function (data) {
    // Create base PlaneGeometry
    const geometry = new THREE.PlaneGeometry(
      data.width,
      data.height,
      data.segmentsWidth,
      data.segmentsHeight
    );

    // Calculate number of vertices per row
    const verticesPerRow = data.segmentsWidth + 1;

    // Get UV attribute
    const uvAttribute = geometry.attributes.uv;
    const uvs = uvAttribute.array;

    for (let i = 0; i < uvs.length; i += 2) {
      // Calculate which row this vertex belongs to
      const vertexRow = Math.floor(i / (2 * verticesPerRow));
      
      // Keep the original x-coordinate (u)
      // but modify the y-coordinate (v) based on row
      const u = uvs[i];
      const v = vertexRow % 2 === 0 ? 1 : 0;
      
      // Update UV coordinates
      uvs[i] = u;      // x-coordinate (u) stays the same
      uvs[i + 1] = v;  // y-coordinate (v) alternates between 0 and 1
    }

    // Update UV attribute
    uvAttribute.needsUpdate = true;

    // Center the geometry at origin
    geometry.center();

    this.geometry = geometry;
  }
});
@kfarr kfarr converted this from a draft issue Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To Do - High Prio
Development

No branches or pull requests

1 participant