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

From single sided to double sided materials #2

Closed
geolocus opened this issue Jul 22, 2019 · 2 comments
Closed

From single sided to double sided materials #2

geolocus opened this issue Jul 22, 2019 · 2 comments

Comments

@geolocus
Copy link

Is it possible to add/adjust code for single sided materials to become double sided?

@javagl javagl transferred this issue from CesiumGS/3d-tiles-validator Oct 3, 2022
javagl added a commit that referenced this issue Apr 14, 2023
Support for implicit tileset traversal (and metadata handling)
@javagl
Copy link
Contributor

javagl commented Apr 17, 2023

The 3d-tiles-tools do very few operations on the glTF itself. Most of the glTF work is delegated to gltf-pipeline right now. Integrating other "glTF modification libraries" is on the radar, but most of them won't offer this operation "out of the box".

If the goal was to integrate this functionality in the 3d-tiles-tools, we'd have to think about how exactly it should be offered. It could be one operation, similar to the current optimize* family of operations. But ... it's a very simple operation, and a very specific operation, so I'm a bit on the fence of whether it's worth integrating that here.

I'm slightly leaning towards closing this issue, but maybe one ("important") question before doing so:

Was the intention to apply this to B3DM/I3DM files?
Or should it be applied to files that already are GLB?

(For the latter, it may be easier and more reasonable to just batch-process them with one of the existing glTF libraries that may be used for this sort of operation...)

@javagl
Copy link
Contributor

javagl commented Aug 8, 2023

As mentioned in the previous comment, operations on the glTF are not the main focus of the 3d-tiles-tools. But some of the functionalities that have been implemented recently did include generalizations of the operations that can be performed on the GLB data.

Some of the functionality that could be useful here is that of the TileContentProcessing and TileContentProcessor. The latter receives a buffer with the tile data, and information about the content data type, and returns "modified" tile data. The modification in this case could easily be done with glTF-Transform.

For example, for a given input tileset with GLB tile content, this would convert all materials in all tiles to be double sided:

import { NodeIO } from "@gltf-transform/core";
import { TileContentProcessing } from "./src/tilesetProcessing/TileContentProcessing";
import { TileContentProcessor } from "./src/tilesetProcessing/TileContentProcessor";
import { ContentDataTypes } from "./src/contentTypes/ContentDataTypes";

async function runExample() {
  const tilesetSourceName = "./input/tileset.json";
  const tilesetTargetName = "./output/tileset.json";
  const overwrite = true;

  // Create the TileContentProcessor that will be 
  // applied to each tile content
  const io = new NodeIO();
  const tileContentProcessor: TileContentProcessor = async (
    content: Buffer,
    type: string | undefined
  ): Promise<Buffer> => {

    // Ignore everything except for GLB
    if (type !== ContentDataTypes.CONTENT_TYPE_GLB) {
      return content;
    }

    // Read the glTF-Transform document of the content
    const document = await io.readBinary(content);
    const root = document.getRoot();

    // Go through all materials and set them to be double sided
    const materials = root.listMaterials();
    for (const material of materials) {
      console.log("Material " + material.getDoubleSided());
      material.setDoubleSided(true);
    }

    // Return a buffer that was created from the modified document
    const modifiedContent = await io.writeBinary(document);
    return Buffer.from(modifiedContent);
  };

  // Process the tileset source, and write it to the tileset target,
  // applying the `TileContentProcessor` to all tile contents
  await TileContentProcessing.process(
    tilesetSourceName,
    tilesetTargetName,
    overwrite,
    tileContentProcessor
  );
}

runExample();

Given that this issue was opened 4 years ago, I assume that it is ... actually "obsolete", but hope that it is OK to close it with the hint: Yes, things like this are now possible with relatively little effort.

@javagl javagl closed this as completed Aug 8, 2023
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

No branches or pull requests

2 participants