Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.appendFileSync(objFile, `vt ${uv[i].toFixed(3)} ${uv[i + 1].toFixed(3)}\n`);
const indices = info.mesh.indices;
for (let i = 0; i < indices.length; i += 3) {
const p1 = pointOffset + indices[i];
const p2 = pointOffset + indices[i + 1];
const p3 = pointOffset + indices[i + 2];
fs.appendFileSync(objFile, `f ${p1}/${p1}/${p1} ${p2}/${p2}/${p2} ${p3}/${p3}/${p3}\n`);
}
pointOffset += info.mesh.points.length / 3;
};
fs.appendFileSync(objFile, `mtllib ${mtlName}\n`);
// Set angleTol to arbitrary large value so chordTol is deciding factor.
iModel.exportGraphics(({ onGraphics, elementIdArray, chordTol: 0.01, angleTol: Angle.degreesToRadians(45) }));
process.stdout.write(`Wrote ${pointOffset - 1} vertices.\n`);
fs.closeSync(objFile);
materialMap.forEach((materialName: string, color: number) => {
fs.appendFileSync(mtlFile, `newmtl ${materialName}\n`);
const rawColors = new ColorDef(color).colors;
fs.appendFileSync(mtlFile, `Kd ${(rawColors.r / 255).toFixed(2)} ${(rawColors.g / 255).toFixed(2)} ${(rawColors.b / 255).toFixed(2)}\n`);
if (rawColors.t !== 0)
fs.appendFileSync(mtlFile, `Tr ${(rawColors.t / 255).toFixed(2)}\n`);
});
const textureDirectory = path.dirname(mtlName);
const getTextureExt = (format: ImageSourceFormat): string => format === ImageSourceFormat.Jpeg ? ".jpg" : ".png";
textureMap.forEach((materialName: string, textureId: Id64String) => {
const texture = iModel.elements.getElement(textureId) as Texture;
private pointFromCoordinate(coordinates: number[]) {
GeoJsonImporter._scratchCartographic.longitude = Angle.degreesToRadians(coordinates[0]);
GeoJsonImporter._scratchCartographic.latitude = Angle.degreesToRadians(coordinates[1]);
const point = this.iModelDb.cartographicToSpatialFromEcef(GeoJsonImporter._scratchCartographic);
/** the ecef Transform (particularly if it appending) may introduce some deviation from 0 x-y plane. */
if (this._forceZeroHeight)
point.z = 0.0;
return point;
}
private convertPoint(inPoint: GeoJson.Point): Loop {
private pointFromCoordinate(coordinates: number[]) {
GeoJsonImporter._scratchCartographic.longitude = Angle.degreesToRadians(coordinates[0]);
GeoJsonImporter._scratchCartographic.latitude = Angle.degreesToRadians(coordinates[1]);
const point = this.iModelDb.cartographicToSpatialFromEcef(GeoJsonImporter._scratchCartographic);
/** the ecef Transform (particularly if it appending) may introduce some deviation from 0 x-y plane. */
if (this._forceZeroHeight)
point.z = 0.0;
return point;
}
private convertPoint(inPoint: GeoJson.Point): Loop {
private extendRangeForCoordinate(featureMin: Cartographic, featureMax: Cartographic, point: GeoJson.Point) {
const longitude = Angle.degreesToRadians(point[0]);
const latitude = Angle.degreesToRadians(point[1]);
featureMin.longitude = Math.min(longitude, featureMin.longitude);
featureMin.latitude = Math.min(latitude, featureMin.latitude);
featureMax.longitude = Math.max(longitude, featureMax.longitude);
featureMax.latitude = Math.max(latitude, featureMax.latitude);
}
private extendRangeForCoordinates(featureMin: Cartographic, featureMax: Cartographic, lineString: GeoJson.LineString) {
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
import {
IModelHost, IModelDb, ECSqlStatement, ExportGraphicsInfo, ExportGraphicsMesh, ExportPartInstanceInfo,
ExportPartInfo, ExportGraphics, ExportLinesInfo, ExportGraphicsLines, ExportPartLinesInfo, Texture,
} from "@bentley/imodeljs-backend";
import { DbResult, Id64Array, Logger, LogLevel, Id64String } from "@bentley/bentleyjs-core";
import { ColorDef, ImageSourceFormat } from "@bentley/imodeljs-common";
import { Matrix3d, Angle, Geometry } from "@bentley/geometry-core";
import * as fs from "fs";
import * as path from "path";
import * as yargs from "yargs";
const CHORD_TOL = 0.001;
const ANGLE_TOL = Angle.degreesToRadians(45);
const MIN_BREP_SIZE = 0.01;
class GltfGlobals {
public static iModel: IModelDb;
public static gltf: Gltf;
public static binFile: number;
public static texturesDir: string;
public static binBytesWritten: number;
public static colorToMaterialMap: Map;
public static textureToMaterialMap: Map;
public static initialize(iModelName: string, gltfName: string) {
GltfGlobals.iModel = IModelDb.openSnapshot(iModelName);
process.stdout.write(`Opened ${iModelName} successfully...\n`);
const gltfPathParts = path.parse(gltfName);
public static fromDegrees(longitude: number, latitude: number, height: number, result?: Cartographic) {
return Cartographic.fromRadians(Angle.degreesToRadians(longitude), Angle.degreesToRadians(latitude), height, result);
}
export function calculateSolarDirection(date: Date, location: Cartographic): Vector3d {
const azimuthElevation = calculateSolarAngles(date, location);
const azimuth = Angle.degreesToRadians(azimuthElevation.azimuth);
const elevation = Angle.degreesToRadians(azimuthElevation.elevation);
const cosElevation = Math.cos(elevation);
const sinElevation = Math.sin(elevation);
return Vector3d.create(-Math.sin(azimuth) * cosElevation, -Math.cos(azimuth) * cosElevation, -sinElevation);
}
export function calculateSolarDirection(date: Date, location: Cartographic): Vector3d {
const azimuthElevation = calculateSolarAngles(date, location);
const azimuth = Angle.degreesToRadians(azimuthElevation.azimuth);
const elevation = Angle.degreesToRadians(azimuthElevation.elevation);
const cosElevation = Math.cos(elevation);
const sinElevation = Math.sin(elevation);
return Vector3d.create(-Math.sin(azimuth) * cosElevation, -Math.cos(azimuth) * cosElevation, -sinElevation);
}