Skip to content

Commit

Permalink
Remote item grabbables in AvStandardGrabbable
Browse files Browse the repository at this point in the history
Switched whiteboard over to use AvStandardGrabbable for its networked item grabbables, and then fixed the bugs that popped up. Deleted the sketch of AvRemoteGrabbable in whiteboard_main.tsx.
  • Loading branch information
JoeLudwig committed Oct 1, 2020
1 parent 163e1c1 commit 75e0021
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 90 deletions.
17 changes: 8 additions & 9 deletions packages/aardvark-react/src/aardvark_standard_grabbable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,6 @@ export class AvStandardGrabbable extends React.Component< StandardGrabbableProps
infoVolume.nodeFromVolume.scale.z *= highlightScale;
}

let volume: AvVolume = this.remoteComponent ? emptyVolume() : infoVolume;

let constraint: AvConstraint = null;
if( this.props.gravityAligned )
{
Expand Down Expand Up @@ -482,7 +480,7 @@ export class AvStandardGrabbable extends React.Component< StandardGrabbableProps
else
{
outerComponent = this.moveableComponent;
outerVolume = volume;
outerVolume = infoVolume;
outerConstraint = constraint;

if( this.networkedComponent )
Expand All @@ -495,36 +493,37 @@ export class AvStandardGrabbable extends React.Component< StandardGrabbableProps

case GrabbableStyle.LocalItem:
outerComponent = this.moveableComponent;
outerVolume = volume;
outerVolume = infoVolume;
outerConstraint = constraint;
break;

case GrabbableStyle.NetworkedItem:
if( AvGadget.instance().isRemote )
{
outerComponent = this.remoteItemComponent;
outerVolume = infoVolume;
outerVolume = emptyVolume();

innerComponent = this.moveableComponent;
innerVolume = volume;
innerVolume = infoVolume;
innerConstraint = constraint;

if( this.moveableComponent.state == MoveableComponentState.Grabbed )
{
let lock = { ...this.remoteComponent.interfaceLocks[0] };
let lock = { ...this.remoteItemComponent.interfaceLocks[0] };
lock.iface = k_remoteGrabbableInterface;
locatorEntity = <AvInterfaceEntity volume={ emptyVolume() }
locatorEntity = <AvInterfaceEntity volume={ infoVolume }
transmits={ [ { iface: k_remoteGrabbableInterface } ] }
interfaceLocks={ [ lock ] }/>
}
}
else
{
outerComponent = this.moveableComponent;
outerVolume = volume;
outerVolume = infoVolume;
outerConstraint = constraint;

innerComponent = this.networkedItemComponent;
innerVolume = infiniteVolume();
}
break;
}
Expand Down
97 changes: 16 additions & 81 deletions websrc/whiteboard/src/whiteboard_main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkedItemComponent, ActiveInterface, AvComposedEntity, AvGadget, AvInterfaceEntity, AvLine, AvModel, AvPrimitive, AvStandardGrabbable, AvTransform, MoveableComponent, PrimitiveType, PrimitiveYOrigin, PrimitiveZOrigin, DefaultLanding, RemoteItemComponent, MoveableComponentState, k_remoteGrabbableInterface, GrabbableStyle } from '@aardvarkxr/aardvark-react';
import { ShowGrabbableChildren, NetworkedItemComponent, ActiveInterface, AvComposedEntity, AvGadget, AvInterfaceEntity, AvLine, AvModel, AvPrimitive, AvStandardGrabbable, AvTransform, MoveableComponent, PrimitiveType, PrimitiveYOrigin, PrimitiveZOrigin, DefaultLanding, RemoteItemComponent, MoveableComponentState, k_remoteGrabbableInterface, GrabbableStyle } from '@aardvarkxr/aardvark-react';
import { Av, AvNodeTransform, AvVector, AvVolume, endpointAddrToString, EVolumeType, g_builtinModelBox, InitialInterfaceLock, infiniteVolume } from '@aardvarkxr/aardvark-shared';
import { vec2 } from '@tlaukkan/tsm';
import bind from 'bind-decorator';
Expand Down Expand Up @@ -80,78 +80,6 @@ interface MarkerProps
thickness: number;
}

interface AvRemoteGrabbableProps
{
itemId: string;
volume: AvVolume | AvVolume[];
}

interface AvRemoteGrabbableState
{
moveableState: MoveableComponentState;
}

class AvNetworkedGrabbable extends React.Component< AvRemoteGrabbableProps, AvRemoteGrabbableState >
{
private moveableComponent = new MoveableComponent( this.onMoveableUpdate, false, false );
private remoteComponent: RemoteItemComponent = null;
private networkComponent: NetworkedItemComponent = null

constructor( props: any )
{
super( props );

this.state =
{
moveableState: MoveableComponentState.Idle,
};

if( AvGadget.instance().isRemote )
{
this.remoteComponent = new RemoteItemComponent( this.props.itemId, () => {} );
}
else
{
this.networkComponent = new NetworkedItemComponent( this.props.itemId, () => {} );
}
}

@bind
private onMoveableUpdate()
{
this.setState( { moveableState: this.moveableComponent.state } );
}

render()
{
if( AvGadget.instance().isRemote )
{
let lock = { ...this.remoteComponent.interfaceLocks[0] };
lock.iface = k_remoteGrabbableInterface;
return <AvComposedEntity components={ [ this.remoteComponent ]} volume={ this.props.volume }>
<AvComposedEntity components={ [ this.moveableComponent ]} volume={ this.props.volume }>
{

this.state.moveableState == MoveableComponentState.Grabbed &&
<AvInterfaceEntity volume={ this.props.volume }
transmits={ [ { iface: k_remoteGrabbableInterface } ] }
interfaceLocks={ [ lock ] }/>
}
{ this.props.children }
</AvComposedEntity>
</AvComposedEntity>;
}
else
{
return <AvComposedEntity components={ [ this.moveableComponent ]} volume={ this.props.volume }>
<AvComposedEntity components={ [ this.networkComponent ] } volume={ infiniteVolume() }>
{ this.props.children }
</AvComposedEntity>
</AvComposedEntity>;
}
}
}


function Marker( props: MarkerProps )
{
Expand Down Expand Up @@ -192,19 +120,26 @@ function Marker( props: MarkerProps )
} as AvVolume;

return <AvTransform translateX={ props.initialXOffset } translateY={ 0.005 }>
<AvNetworkedGrabbable volume={ k_grabVolume } itemId = { "marker" + props.initialXOffset } >
<AvTransform translateY={ markerTipRadius } >
<AvPrimitive type={PrimitiveType.Cylinder} originY={ PrimitiveYOrigin.Bottom }
radius={ markerRadius } height={0.065 } color={ color } />
</AvTransform>
<AvPrimitive type={PrimitiveType.Sphere} width={ props.thickness } height={ props.thickness }
depth={ props.thickness } color={props.initialColor }/>
<AvStandardGrabbable style={ GrabbableStyle.NetworkedItem } itemId = { "marker" + props.initialXOffset }
volume={ k_grabVolume } showChildren={ ShowGrabbableChildren.OnlyWhenGrabbed}
canDropIntoContainers={ false }
appearance={
<>
<AvTransform translateY={ markerTipRadius } >
<AvPrimitive type={PrimitiveType.Cylinder} originY={ PrimitiveYOrigin.Bottom }
radius={ markerRadius } height={0.065 } color={ color } />
</AvTransform>
<AvPrimitive type={PrimitiveType.Sphere} width={ props.thickness } height={ props.thickness }
depth={ props.thickness } color={props.initialColor }/>
</>
}>
<AvInterfaceEntity transmits={
[
{ iface: "color-picker@1", processor: onColorPicker },
{ iface: "surface-drawing@1", processor: onSurfaceDrawing },
] } volume={ k_tipVolume }/>
</AvNetworkedGrabbable>

</AvStandardGrabbable>
</AvTransform>;
}

Expand Down

0 comments on commit 75e0021

Please sign in to comment.