Skip to content

Commit

Permalink
added alternative background
Browse files Browse the repository at this point in the history
  • Loading branch information
maxibenner committed Aug 6, 2021
1 parent 6af3090 commit 902e5de
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 13 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^12.8.3",
"ray-tracing-renderer": "^0.10.15",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.2.0",
Expand Down
17 changes: 17 additions & 0 deletions src/components/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function ControlPanel({ activeDecalPath, setActiveDecalPath }) {
setBackgroundColor,
setDecalPath,
setModelColor,
setSet,
} = useStore()

// SET ACTIVE DECAL PATH
Expand Down Expand Up @@ -73,6 +74,22 @@ export default function ControlPanel({ activeDecalPath, setActiveDecalPath }) {
setColor={setBackgroundColor}
/>
</Card>
<Card title="Backgrounds">
<button
onClick={() => {
setSet("PlainBg")
}}
>
Plain
</button>
<button
onClick={() => {
setSet("ShapesBg")
}}
>
Shapes
</button>
</Card>

{decalPath && (
<Card title="Design">
Expand Down
5 changes: 3 additions & 2 deletions src/components/PhotoButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const PhotoButton = ({ gl }) => {

// Take screenshot
const screenshot = () => {
var strMime = "image/jpeg"
const imgData = gl.domElement.toDataURL(strMime)
var strMime = "image/png"
const imgData = gl.domElement.toDataURL(strMime, { pixelRatio: 4 })
var a = document.createElement("a")

a.setAttribute("download", "fotura.png")
a.setAttribute("href", imgData)
a.click()
Expand Down
10 changes: 0 additions & 10 deletions src/components/three/Back.js

This file was deleted.

23 changes: 23 additions & 0 deletions src/components/three/Scenes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react"
import PlainBg from "./sets/PlainBg"
import Lights from "./Lights"
import ShapesBg from "./sets/ShapesBg"
import useStore from "../../states/modelState"

const Scenes = () => {
const { backgroundColor, set } = useStore()
return (
<>
{set == "PlainBg" && <group>
<PlainBg backgroundColor={backgroundColor} />
<Lights />
</group>}
{set == "ShapesBg" && <group>
<ShapesBg backgroundColor={backgroundColor} />
<Lights />
</group>}
</>
)
}

export default Scenes
4 changes: 3 additions & 1 deletion src/components/three/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Canvas } from "@react-three/fiber"
import { Suspense, useEffect, useState } from "react"
import { useSpring } from "react-spring/three"
import Fps from "../../helpers/Fps"
import { RayTracingRenderer } from 'ray-tracing-renderer'

import useStore from "../../states/modelState"
import ControlPanel from "../ControlPanel"
Expand Down Expand Up @@ -53,11 +54,12 @@ const Viewer = () => {
<>
<Fps />
<Canvas
pixelRatio={window.devicePixelRatio}
onCreated={({ gl }) => setGl(gl)}
style={decalPath && { cursor: "none" }}
gl={{
pixelratio: window.devicePixelRatio,
preserveDrawingBuffer: true,
antialias: false,
}}
camera={{ position: [0, 0, 2.2], fov: 50 }}
//frameloop="demand"
Expand Down
10 changes: 10 additions & 0 deletions src/components/three/sets/PlainBg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const PlainBg = ({backgroundColor}) => {
return (
<mesh position={[0, 0, -.5]} receiveShadow>
<planeBufferGeometry args={[100, 100]} />
<meshStandardMaterial color={backgroundColor} />
</mesh>
);
};

export default PlainBg;
52 changes: 52 additions & 0 deletions src/components/three/sets/ShapesBg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const ShapesBg = ({backgroundColor}) => {

return (
<group>
<mesh position={[0, 0, -0.5]} receiveShadow>
<planeBufferGeometry args={[10, 10]} />
<meshStandardMaterial
attach="material"
color={backgroundColor}
/>
</mesh>
<mesh position={[0.5, 0, 0.5]} rotation={[4, 0, 0]} receiveShadow>
<boxBufferGeometry args={[0.06, 0.06, 0.06]} />
<meshStandardMaterial
attach="material"
color={backgroundColor}
/>
</mesh>
<mesh position={[-0.5, -0.2, 0.5]} receiveShadow>
<sphereBufferGeometry args={[0.05, 20, 20]} />
<meshStandardMaterial
attach="material"
color={backgroundColor}
/>
</mesh>
<mesh
position={[-0.5, 0.6, 0]}
rotation={[3, 5.5, 0]}
receiveShadow
>
<torusBufferGeometry args={[0.07, 0.03, 10, 30]} />
<meshStandardMaterial
attach="material"
color={backgroundColor}
/>
</mesh>
<mesh
position={[0.15, -0.45, 0.3]}
rotation={[2.2, 3.5, 2]}
receiveShadow
>
<torusBufferGeometry args={[0.05, 0.02, 10, 30]} />
<meshStandardMaterial
attach="material"
color={backgroundColor}
/>
</mesh>
</group>
)
}

export default ShapesBg
2 changes: 2 additions & 0 deletions src/states/modelState.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const useStore = create((set) => ({
initialDecalSize: initialDecalSize,
decalSize: initialDecalSize,
modelColor: "#ffffff",
set: "ShapesBg",
setBackgroundColor: (color) =>
set((state) => (state.backgroundColor = color)),
addDecal: (decalObject) =>
Expand All @@ -29,6 +30,7 @@ const useStore = create((set) => ({
set((state) => (state.decalSize = state.decalSize - value)),
setDecalSize: (size) => set((state) => (state.decalSize = size)),
setModelColor: (color) => set((state) => (state.modelColor = color)),
setSet: (componentName) => set((state) => (state.set = componentName)),
}))

export default useStore

0 comments on commit 902e5de

Please sign in to comment.