This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** return whether arg is T or an iterable of T | |
* for the flat function */ | |
function isIterable<T>(arg: T | Iterable<T>): arg is Iterable<T> { | |
return typeof arg === "object" && Symbol.iterator in arg; | |
} | |
/** iterable wrapper for functional programming with lazy composition */ | |
export default class Lazy<T> implements Iterator<T> { | |
static from<T>(iterable: Iterable<T>) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import { BeButtonEvent, DecorateContext, Decorator, Marker, IModelApp } from "@bentley/imodeljs-frontend"; | |
import { Point3d, XAndY, XYAndZ } from "@bentley/geometry-core"; | |
// a weak map would probably be better to prevent leaks | |
const reactSetHoverStateMap = new Map<PinMarker, (val: boolean) => void>(); | |
function InMarkerComponent(props: {markerInstance: PinMarker}) { | |
const [isHovered, setIsHovered] = React.useState(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import { Point3d } from "@bentley/geometry-core"; | |
import { useMarker } from "@bentley/imodel-react-hooks"; | |
const MyJsxMarker = (props: { worldLocation: Point3d }) => { | |
const [isHovered, setIsHovered] = useState(false); | |
useMarker({ | |
worldLocation: props.worldLocation, | |
size: [70, 20], | |
onMouseEnter: () => setIsHovered(true), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ViewportComponent } from "@bentley/ui-components"; | |
import { myIModel, myViewDefId, iModelInnerModels, useFetchAppMarkers, ElemMarkerData } from "./my-app-state"; | |
import { FeatureOverrideReactProvider, useFeatureOverrides, useMarker, IModelJsViewProvider } from "@bentley/imodel-react-hooks"; | |
import { FeatureAppearance } from "@bentley/imodeljs-common"; | |
import { Id64Array } from "@bentley/bentleyjs-core"; | |
function RedElementMarker(props: ElemMarkerData) { | |
const RED = {r: 255, g: 0, b: 0}; | |
useMarker({ worldLocation: props.worldLocation, image: props.someSvgPath }); | |
useFeatureOverrides({ // override the one element to be red |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
lp_meshes = [obj for obj in bpy.data.collections['lp'].all_objects if obj.type == 'MESH'] | |
bpy.ops.object.select_all(action='DESELECT') | |
for obj in bpy.data.collections['bake'].all_objects: | |
if (obj.type == 'MESH' | |
and obj.name not in ('combined_cage', 'combined_lp')): | |
bpy.data.objects.remove(obj, do_unlink=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = require("express")(); | |
app.use(require('cors')()); | |
app.get("/tank-params", (req, res) => { | |
res.json({ | |
level: Math.random(), | |
pressure: Math.random(), | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yarn add express@^4.16.0 cors @bentley/imodel-react-hooks @bentley/react-hooks | |
node src/server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { Marker } from "@bentley/imodel-react-hooks"; | |
import { useAsyncInterval } from "@bentley/react-hooks"; | |
import { Point3d } from "@bentley/geometry-core"; | |
export default function TankMarker({tankParamType}: {tankParamType: "level" | "pressure"}) { | |
const [tankParamValue, setTankParamValue] = React.useState<number>(); | |
useAsyncInterval( | |
async ({ isStale, setCancel }) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// at the top add these imports | |
import TankMarker from "./TankMarker.tsx"; | |
import { Viewer } from "@bentley/itwin-viewer-react"; | |
import { IModelJsViewProvider } from "@bentley/imodel-react-hooks"; | |
const App = () => {//... | |
//... at the bottom of the file replace the return statement with this | |
const [imjsInited, setImjsInited] = useState(false); | |
const [tankParamType, setTankParamType] = useState<"level" | "pressure">("level"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useAsyncInterval } from "@bentley/react-hooks"; | |
//... | |
useAsyncInterval( | |
async ({isStale, setCancel}) => { | |
const aborter = new AbortController(); | |
setCancel(() => aborter.abort()); | |
const response = await fetch("http://localhost:3001/tank-params", { signal: aborter.signal }); | |
const result = await response.json(); | |
if (!isStale()) setTankParamValue(result[tankParamType]); | |
}, |
OlderNewer