Skip to content

Commit

Permalink
Merge branch 'main' into feat/visualizer-image-based-lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice committed Jun 28, 2023
2 parents 36e1f5f + 748d9db commit e607408
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 327 deletions.
7 changes: 6 additions & 1 deletion server/internal/adapter/gql/loader_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/reearth/reearth/server/internal/adapter/gql/gqldataloader"
"github.com/reearth/reearth/server/internal/adapter/gql/gqlmodel"
"github.com/reearth/reearth/server/internal/usecase/interfaces"
"github.com/reearth/reearth/server/pkg/log"
"github.com/reearth/reearthx/util"
)

Expand All @@ -23,7 +24,11 @@ func (c *PluginLoader) Fetch(ctx context.Context, ids []gqlmodel.ID) ([]*gqlmode
return nil, []error{err}
}

res, err := c.usecase.Fetch(ctx, ids2, getOperator(ctx))
op := getOperator(ctx)
log.Infof("TEMP: PluginLoader.Fetch op: %#v", op)
log.Infof("TEMP: PluginLoader.Fetch ids: %v", ids)

res, err := c.usecase.Fetch(ctx, ids2, op)
if err != nil {
return nil, []error{err}
}
Expand Down
7 changes: 6 additions & 1 deletion server/internal/adapter/gql/loader_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/reearth/reearth/server/internal/adapter/gql/gqlmodel"
"github.com/reearth/reearth/server/internal/usecase/interfaces"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/log"
"github.com/reearth/reearthx/util"
)

Expand All @@ -24,7 +25,11 @@ func (c *PropertyLoader) Fetch(ctx context.Context, ids []gqlmodel.ID) ([]*gqlmo
return nil, []error{err}
}

res, err := c.usecase.Fetch(ctx, ids2, getOperator(ctx))
op := getOperator(ctx)
log.Infof("TEMP: PropertyLoader.Fetch op: %#v", op)
log.Infof("TEMP: PropertyLoader.Fetch ids: %v", ids)

res, err := c.usecase.Fetch(ctx, ids2, op)
if err != nil {
return nil, []error{err}
}
Expand Down
10 changes: 10 additions & 0 deletions server/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func initEcho(ctx context.Context, cfg *ServerConfig) *echo.Echo {

func errorHandler(next func(error, echo.Context)) func(error, echo.Context) {
return func(err error, c echo.Context) {
ctx := c.Request().Context()
if c.Response().Committed {
return
}
Expand All @@ -147,6 +148,15 @@ func errorHandler(next func(error, echo.Context)) func(error, echo.Context) {
err = rerror.ErrNotFound
}

if err := rerror.UnwrapErrInternal(err); err != nil {
au := adapter.GetAuthInfo(ctx)
u := adapter.User(ctx)
op := adapter.Operator(ctx)
c.Echo().Logger.Errorf("AUTH: %#v", au)
c.Echo().Logger.Errorf("USER: %#v", u)
c.Echo().Logger.Errorf("OP: %#v", op)
}

code, msg := errorMessage(err, func(f string, args ...interface{}) {
c.Echo().Logger.Errorf(f, args...)
})
Expand Down
5 changes: 5 additions & 0 deletions server/internal/infrastructure/mongo/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/reearth/reearth/server/pkg/builtin"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/plugin"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/mongox"
"github.com/reearth/reearthx/rerror"
)
Expand Down Expand Up @@ -76,12 +77,16 @@ func (r *Plugin) FindByIDs(ctx context.Context, ids []id.PluginID) ([]*plugin.Pl
var err error

if len(ids2) > 0 {
log.Infof("TEMP: plugin mongo find by ids %v", ids2)

res, err = r.find(ctx, bson.M{
"id": bson.M{"$in": id.PluginIDsToStrings(ids2)},
})
if err != nil {
return nil, err
}

log.Infof("TEMP: plugin mongo find by ids OK")
}

return res.Concat(b.List()).MapToIDs(ids), nil
Expand Down
6 changes: 6 additions & 0 deletions server/internal/infrastructure/mongo/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/reearth/reearth/server/internal/usecase/repo"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/property"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/mongox"
"github.com/reearth/reearthx/rerror"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -68,6 +69,8 @@ func (r *Property) FindByIDs(ctx context.Context, ids id.PropertyIDList) (proper
return nil, nil
}

log.Infof("TEMP: property mongo find by ids %v", ids)

filter := bson.M{
"id": bson.M{
"$in": ids.Strings(),
Expand All @@ -77,6 +80,9 @@ func (r *Property) FindByIDs(ctx context.Context, ids id.PropertyIDList) (proper
if err != nil {
return nil, err
}

log.Infof("TEMP: property mongo find by ids OK")

return filterProperties(ids, res), nil
}

Expand Down
25 changes: 6 additions & 19 deletions web/src/beta/features/Navbar/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useGetProjectBySceneQuery,
useGetTeamsQuery,
} from "@reearth/services/gql";
import { useProject, useSessionWorkspace, useWorkspace } from "@reearth/services/state";
import { useProject, useWorkspace } from "@reearth/services/state";

type User = {
name: string;
Expand All @@ -16,9 +16,8 @@ type User = {
export default (sceneId: string) => {
const { logout: handleLogout } = useAuth();

const [currentWorkspace, setWorkspace] = useSessionWorkspace();
const [currentWorkspace, setCurrentWorkspace] = useWorkspace();
const [currentProject, setProject] = useProject();
const [lastWorkspace, setLastWorkspace] = useWorkspace();

const [workspaceModalVisible, setWorkspaceModalVisible] = useState(false);

Expand Down Expand Up @@ -58,16 +57,6 @@ export default (sceneId: string) => {
const handleWorkspaceModalOpen = useCallback(() => setWorkspaceModalVisible(true), []);
const handleWorkspaceModalClose = useCallback(() => setWorkspaceModalVisible(false), []);

useEffect(() => {
if (!currentWorkspace && lastWorkspace && workspaceId == lastWorkspace.id)
setWorkspace(lastWorkspace);
else {
const workspace = workspaces?.find(workspace => workspace.id === workspaceId);
setWorkspace(workspace);
setLastWorkspace(workspace);
}
}, [currentWorkspace, lastWorkspace, setLastWorkspace, setWorkspace, workspaceId, workspaces]);

useEffect(() => {
setProject(p =>
p?.id !== project?.id
Expand All @@ -87,13 +76,12 @@ export default (sceneId: string) => {
(workspaceId: string) => {
const workspace = workspaces?.find(team => team.id === workspaceId);
if (workspace && workspaceId !== currentWorkspace?.id) {
setWorkspace(workspace);
setLastWorkspace(currentWorkspace);
setCurrentWorkspace(workspace);

navigate(`/dashboard/${workspaceId}`);
}
},
[workspaces, currentWorkspace, setWorkspace, setLastWorkspace, navigate],
[workspaces, currentWorkspace, setCurrentWorkspace, navigate],
);

const [createTeamMutation] = useCreateTeamMutation();
Expand All @@ -105,13 +93,12 @@ export default (sceneId: string) => {
refetchQueries: ["GetTeams"],
});
if (results.data?.createTeam) {
setWorkspace(results.data.createTeam.team);
setLastWorkspace(results.data.createTeam.team);
setCurrentWorkspace(results.data.createTeam.team);

navigate(`/dashboard/${results.data.createTeam.team.id}`);
}
},
[createTeamMutation, setWorkspace, setLastWorkspace, navigate],
[createTeamMutation, setCurrentWorkspace, navigate],
);

return {
Expand Down
3 changes: 3 additions & 0 deletions web/src/beta/lib/core/Map/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ export type SceneProperty = {
ground_atmosphere?: boolean;
sky_atmosphere?: boolean;
shadows?: boolean;
shadowResolution?: 1024 | 2048 | 4096;
softShadow?: boolean;
shadowDarkness?: number;
fog?: boolean;
fog_density?: number;
brightness_shift?: number;
Expand Down
62 changes: 61 additions & 1 deletion web/src/beta/lib/core/engines/Cesium/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SunLight,
DirectionalLight,
} from "cesium";
import type { Viewer as CesiumViewer } from "cesium";
import type { Viewer as CesiumViewer, ShadowMap } from "cesium";
import CesiumDnD, { Context } from "cesium-dnd";
import { isEqual } from "lodash-es";
import { RefObject, useCallback, useEffect, useMemo, useRef } from "react";
Expand Down Expand Up @@ -181,6 +181,66 @@ export default ({
[property?.light?.specularEnvironmentMaps],
);

// shadow map
type ShadowMapBias = {
polygonOffsetFactor: number;
polygonOffsetUnits: number;
normalOffsetScale: number;
normalShading: boolean;
normalShadingSmooth: number;
depthBias: number;
};

useEffect(() => {
const shadowMap = cesium?.current?.cesiumElement?.shadowMap as
| (ShadowMap & {
_terrainBias: ShadowMapBias;
_pointBias: ShadowMapBias;
_primitiveBias: ShadowMapBias;
})
| undefined;
if (!shadowMap) return;
shadowMap.softShadows = property?.atmosphere?.softShadow ?? false;
shadowMap.darkness = property?.atmosphere?.shadowDarkness ?? 0.3;
shadowMap.size = property?.atmosphere?.shadowResolution ?? 2048;
shadowMap.fadingEnabled = true;
shadowMap.maximumDistance = 5000;
shadowMap.normalOffset = true;

// bias
const defaultTerrainBias: ShadowMapBias = {
polygonOffsetFactor: 1.1,
polygonOffsetUnits: 4.0,
normalOffsetScale: 0.5,
normalShading: true,
normalShadingSmooth: 0.3,
depthBias: 0.0001,
};
const defaultPrimitiveBias: ShadowMapBias = {
polygonOffsetFactor: 1.1,
polygonOffsetUnits: 4.0,
normalOffsetScale: 0.1 * 100,
normalShading: true,
normalShadingSmooth: 0.05,
depthBias: 0.00002 * 10,
};
const defaultPointBias: ShadowMapBias = {
polygonOffsetFactor: 1.1,
polygonOffsetUnits: 4.0,
normalOffsetScale: 0.0,
normalShading: true,
normalShadingSmooth: 0.1,
depthBias: 0.0005,
};
Object.assign(shadowMap._terrainBias, defaultTerrainBias);
Object.assign(shadowMap._primitiveBias, defaultPrimitiveBias);
Object.assign(shadowMap._pointBias, defaultPointBias);
}, [
property?.atmosphere?.softShadow,
property?.atmosphere?.shadowDarkness,
property?.atmosphere?.shadowResolution,
]);

useEffect(() => {
engineAPI.changeSceneMode(property?.default?.sceneMode, 0);
}, [property?.default?.sceneMode, engineAPI]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { useNavigate } from "react-router-dom";
import { useAuth, useCleanUrl } from "@reearth/services/auth";
import { useGetTeamsQuery } from "@reearth/services/gql";
import { useT } from "@reearth/services/i18n";
import {
useWorkspace,
useNotification,
useUserId,
useSessionWorkspace,
} from "@reearth/services/state";
import { useWorkspace, useNotification, useUserId } from "@reearth/services/state";

export type Mode = "layer" | "widget";

Expand All @@ -19,54 +14,20 @@ export default () => {
const navigate = useNavigate();
const { isAuthenticated, isLoading, error: authError, login, logout } = useAuth();
const [error, isErrorChecked] = useCleanUrl();
const [currentWorkspace, setWorkspace] = useSessionWorkspace();
const [currentWorkspace, setCurrentWorkspace] = useWorkspace();
const [currentUserId, setCurrentUserId] = useUserId();
const [, setNotification] = useNotification();
const [lastWorkspace, setLastWorkspace] = useWorkspace();

const { data, loading } = useGetTeamsQuery({ skip: !isAuthenticated });

if (isAuthenticated && !currentUserId) {
setCurrentUserId(data?.me?.id);
}
useEffect(() => {
if (!currentWorkspace && lastWorkspace) setWorkspace(lastWorkspace);
}, [currentWorkspace, lastWorkspace, setWorkspace]);

const workspaceId = useMemo(() => {
return currentWorkspace?.id || data?.me?.myTeam.id;
}, [currentWorkspace?.id, data?.me?.myTeam.id]);

const handleRedirect = useCallback(() => {
if (currentUserId === data?.me?.id) {
setWorkspace(
workspaceId
? data?.me?.teams.find(t => t.id === workspaceId) ?? data?.me?.myTeam
: undefined,
);
setLastWorkspace(currentWorkspace);

navigate(`/dashboard/${workspaceId}`);
} else {
setCurrentUserId(data?.me?.id);
setWorkspace(data?.me?.myTeam);
setLastWorkspace(currentWorkspace);

navigate(`/dashboard/${data?.me?.myTeam.id}`);
}
}, [
currentUserId,
data?.me?.id,
data?.me?.teams,
data?.me?.myTeam,
setWorkspace,
workspaceId,
setLastWorkspace,
currentWorkspace,
navigate,
setCurrentUserId,
]);

const verifySignup = useCallback(
async (token: string) => {
const res = await axios.post(
Expand Down Expand Up @@ -103,21 +64,22 @@ export default () => {
} else if (!isAuthenticated && !isLoading) {
login();
} else {
if (!data || !workspaceId) return;
handleRedirect();
if (currentWorkspace || !data || !workspaceId) return;
setCurrentWorkspace(data.me?.myTeam);
navigate(`/dashboard/${workspaceId}`);
}
}, [
isAuthenticated,
login,
isLoading,
verifySignup,
navigate,
currentWorkspace,
handleRedirect,
data,
isErrorChecked,
error,
workspaceId,
login,
verifySignup,
navigate,
setCurrentWorkspace,
]);

useEffect(() => {
Expand Down
Loading

0 comments on commit e607408

Please sign in to comment.