Skip to content

Commit

Permalink
added basic annotation function
Browse files Browse the repository at this point in the history
  • Loading branch information
sahirgomez1 committed Jun 24, 2021
1 parent c9aa2e5 commit 5da7465
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ To install
`git clone https://github.com/sahirgomez1/ycb_objects.git`

In the project directory :
`cd ycb_objects_app`
you can run to install all dependencies
`npm install`
`cd ycb_objects_app`.\
you can run
`npm install` to install all dependencies.\
then run
`npm start`.

Expand Down
5 changes: 3 additions & 2 deletions src/components/AnnotationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const AnnotationView = ({camPosition, objScale}) => {

const player = useRef()
const {
url,
playing,
played,
duration,
Expand Down Expand Up @@ -70,7 +71,7 @@ const AnnotationView = ({camPosition, objScale}) => {
ref={player}
width='100%'
height='auto'
url={"https://storage.turbo360.co/instagram_clone-vjcpvp/rbgt_banana.mp4"}
url={url}
playing={playing}
controls={false}
loop={loop}
Expand Down Expand Up @@ -116,7 +117,7 @@ const AnnotationView = ({camPosition, objScale}) => {
</div>
<div className='d-flex align-items-center'>
<div className='player-control__time'>
<FormattedTime seconds={ played * duration } />
<FormattedTime seconds={ played * duration} />
{' / ' }
<FormattedTime seconds={ duration } />
</div>
Expand Down
8 changes: 6 additions & 2 deletions src/components/EnvironmentContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Canvas, useFrame, useThree, extend } from "@react-three/fiber";
import { useGLTF, Environment, Html, softShadows, Shadow } from "@react-three/drei";
import { useObjectStore } from '../stores/ObjectStore';
import { useAnnotationStore } from '../stores/AnnotationStore';
import { useVideoStore } from '../stores/VideoStore';
import { ObjectControls } from '../ObjectControls';
import { DragControls } from 'three-stdlib';
extend({ DragControls, ObjectControls })
Expand All @@ -16,6 +17,7 @@ const Banana = ({camPosition, ...props}) => {
const [ hovered, setHover ] = useState(false)

const { objPosition, objRotation, handleTranslation, handleRotation } = useObjectStore();
const videoState = useVideoStore()
const { addAnnotation } = useAnnotationStore()

const { camera, gl: { domElement }} = useThree();
Expand Down Expand Up @@ -47,13 +49,15 @@ const Banana = ({camPosition, ...props}) => {

const annotateFrame = () => {
console.log(object.current)
let video_metadata = { url: videoState.url }
let dataAnnotation = {
id:1,
id: videoState.played,
time: (videoState.played * videoState.duration),
position: object.current.position,
rotation: object.current.rotation,
scale: object.current.scale
}
addAnnotation(dataAnnotation)
addAnnotation(video_metadata, dataAnnotation)
}

return (
Expand Down
1 change: 1 addition & 0 deletions src/components/OutputContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const OutputContainer = () => {
<Row className="section-wrapper">
<div className="output">
<code>Output: </code>
<br/>
<code>{outputJSON}</code>

</div>
Expand Down
22 changes: 13 additions & 9 deletions src/stores/AnnotationStore.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import create from 'zustand';

const addRecord = (list, annotation) => {
let ann_found = list.some(o => o.id === annotation.id);
if (!ann_found) list.push(annotation);
list.map(o => (o.id === annotation.id) ? annotation : o)
return list;
}

const useAnnotationStore = create(set => ({
outputAnnotation : {url: "https://camera1-video.mp4", videoWidth: 500, videoHeight: 400 },
addAnnotation : (value) =>
outputAnnotation : { url: "", videoWidth: 500, videoHeight: 400, annotations:[] },
addAnnotation : (video_metadata, annotation) =>
set(state => ({
outputAnnotation: {
...state.outputAnnotation,
annotations: [{
id:value.id,
position: value.position,
rotation: value.rotation
}]
...state.outputAnnotation,
url: video_metadata.url,
annotations: addRecord(state.outputAnnotation.annotations, annotation)
}
})),

}))


export { useAnnotationStore };
export { useAnnotationStore };
2 changes: 1 addition & 1 deletion src/stores/VideoStore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import create from 'zustand';

const useVideoStore = create(set => ({
url: '',
url: "https://storage.turbo360.co/instagram_clone-vjcpvp/rbgt_banana.mp4",
duration: 0,
id :'react-player',
played: 0,
Expand Down

0 comments on commit 5da7465

Please sign in to comment.