regl-worldview
Advanced tools
Comparing version 0.7.4 to 0.8.0
{ | ||
"name": "regl-worldview", | ||
"version": "0.7.4", | ||
"version": "0.8.0", | ||
"description": "A reusable component for rendering 2D and 3D views using regl", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -10,6 +10,15 @@ // @flow | ||
import flatten from "lodash/flatten"; | ||
import memoize from "lodash/memoize"; | ||
import * as React from "react"; | ||
import type { Line, Vec4, Color, Pose } from "../types"; | ||
import { defaultBlend, withPose, toRGBA, shouldConvert, pointToVec3 } from "../utils/commandUtils"; | ||
import type { Line, Vec4, Color, Pose, DepthState, BlendState } from "../types"; | ||
import { | ||
defaultBlend, | ||
withPose, | ||
toRGBA, | ||
shouldConvert, | ||
pointToVec3, | ||
defaultReglDepth, | ||
defaultReglBlend, | ||
} from "../utils/commandUtils"; | ||
import { nonInstancedGetChildrenForHitmap } from "../utils/getChildrenForHitmapDefaults"; | ||
@@ -459,8 +468,20 @@ import Command, { type CommonCommandProps } from "./Command"; | ||
// Create a new render function based on rendering settings | ||
// Memoization is required in order to prevent creating too many functions | ||
// that use the same arguments, potentially leading to memory leaks. | ||
const memoizedRender = memoize( | ||
(props: { depth?: DepthState, blend?: BlendState }) => { | ||
const { depth = defaultReglDepth, blend = defaultReglBlend } = props; | ||
return regl({ depth, blend }); | ||
}, | ||
(...args) => JSON.stringify(args) | ||
); | ||
// Disable depth for debug rendering (so lines stay visible) | ||
const render = (debug, commands) => { | ||
const render = (props: { debug?: boolean, depth?: DepthState, blend?: BlendState }, commands: any) => { | ||
const { debug } = props; | ||
if (debug) { | ||
regl({ depth: { enable: false } })(commands); | ||
memoizedRender({ depth: { enable: false } })(commands); | ||
} else { | ||
commands(); | ||
memoizedRender(props)(commands); | ||
} | ||
@@ -471,3 +492,3 @@ }; | ||
function renderLine(props) { | ||
const { debug, primitive = "lines", scaleInvariant = false } = props; | ||
const { debug, primitive = "lines", scaleInvariant = false, depth, blend } = props; | ||
const numInputPoints = props.points.length; | ||
@@ -508,3 +529,3 @@ | ||
render(debug, () => { | ||
render({ debug, depth, blend }, () => { | ||
// Use Object.assign because it's actually faster than babel's object spread polyfill. | ||
@@ -511,0 +532,0 @@ command( |
@@ -56,2 +56,30 @@ // Copyright (c) 2018-present, GM Cruise LLC | ||
); | ||
}) | ||
.add("<Lines> with custom depth and blend values", () => { | ||
return ( | ||
<Worldview defaultCameraState={DEFAULT_CAMERA}> | ||
<Lines> | ||
{[ | ||
{ | ||
primitive: "line strip", | ||
pose: { | ||
position: { x: 0, y: 0, z: 0 }, | ||
orientation: { x: 0, y: 0, z: 0, w: 1 }, | ||
}, | ||
scale: { x: 2, y: 0, z: 0 }, | ||
points: [[0, -4, 0], [0, 4, 0]], | ||
color: [1, 1, 1, 1], | ||
blend: { | ||
enable: true, | ||
func: { | ||
src: "constant color", | ||
dst: "one", | ||
}, | ||
color: [1, 0, 0, 1], | ||
}, | ||
}, | ||
]} | ||
</Lines> | ||
</Worldview> | ||
); | ||
}); |
@@ -210,2 +210,25 @@ // @flow | ||
export type DepthState = { | ||
enable?: boolean, | ||
mask?: boolean, | ||
}; | ||
export type BlendFuncValue = string | number; | ||
export type BlendState = { | ||
enable?: boolean, | ||
func?: | ||
| BlendFuncValue | ||
| { | ||
src?: BlendFuncValue, | ||
dst?: BlendFuncValue, | ||
srcAlpha?: BlendFuncValue, | ||
srcRGB?: BlendFuncValue, | ||
dstRGB?: BlendFuncValue, | ||
dstAlpha?: BlendFuncValue, | ||
}, | ||
equation?: string | { rgb: string, alpha: string }, | ||
color?: Vec4, | ||
}; | ||
export type ObjectHitmapId = number; | ||
@@ -212,0 +235,0 @@ /* |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 3 instances in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 3 instances in 1 package
4770111
86
19569