Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@shopware-ag/dive

Package Overview
Dependencies
Maintainers
0
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopware-ag/dive - npm Package Compare versions

Comparing version 1.9.0 to 1.10.0

5

build/dive.d.ts

@@ -229,2 +229,3 @@ import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Box3, Vector3Like, Texture, Mesh, ColorRepresentation, Object3D, Intersection, Vector2, Raycaster, Vector3 } from 'three';

loaded: boolean;
material?: COMMaterial;
};

@@ -240,5 +241,5 @@ type COMGeometry = {

roughness: number;
roughnessMap: Texture | null;
roughnessMap?: Texture;
metalness: number;
metalnessMap: Texture | null;
metalnessMap?: Texture;
};

@@ -245,0 +246,0 @@ type COMPrimitive = COMBaseEntity & {

2

package.json
{
"name": "@shopware-ag/dive",
"version": "1.9.0",
"version": "1.10.0",
"description": "Shopware Spatial Framework",

@@ -5,0 +5,0 @@ "type": "module",

@@ -29,2 +29,3 @@ import { type Texture, type Vector3Like } from "three";

loaded: boolean;
material?: COMMaterial;
};

@@ -42,5 +43,5 @@

roughness: number;
roughnessMap: Texture | null;
roughnessMap?: Texture;
metalness: number;
metalnessMap: Texture | null;
metalnessMap?: Texture;
}

@@ -47,0 +48,0 @@

@@ -5,3 +5,4 @@ import Model from '../Model';

import DIVEScene from '../../scene/Scene';
import { Vector3, Box3, Mesh } from 'three';
import { Vector3, Box3, Mesh, MeshStandardMaterial, type Texture, Color } from 'three';
import { type COMMaterial } from '../../com/types';

@@ -139,2 +140,13 @@ const intersectObjectsMock = jest.fn();

}),
MeshStandardMaterial: jest.fn(function () {
this.color = new Color();
this.roughness = 1;
this.roughnessMap = undefined;
this.metalness = 0;
this.metalnessMap = undefined;
return this;
}),
Color: jest.fn(function () {
return this;
}),
}

@@ -155,2 +167,3 @@ });

scene: {
isMesh: true,
isObject3D: true,

@@ -162,2 +175,3 @@ parent: null,

},
material: {},
updateWorldMatrix: jest.fn(),

@@ -173,2 +187,3 @@ children: [

updateWorldMatrix: jest.fn(),
isMesh: true,
},

@@ -185,3 +200,9 @@ ],

let model: Model;
describe('dive/model/DIVEModel', () => {
beforeEach(() => {
model = new Model();
});
afterEach(() => {

@@ -192,3 +213,2 @@ jest.clearAllMocks();

it('should instantiate', () => {
const model = new Model();
expect(model).toBeDefined();

@@ -198,3 +218,2 @@ });

it('should set model', () => {
const model = new Model();
expect(() => model.SetModel(gltf)).not.toThrow();

@@ -204,3 +223,2 @@ });

it('should set position', () => {
const model = new Model();
expect(() => model.SetPosition({ x: 0, y: 0, z: 0 })).not.toThrow();

@@ -210,3 +228,2 @@ });

it('should set rotation', () => {
const model = new Model();
expect(() => model.SetRotation({ x: 0, y: 0, z: 0 })).not.toThrow();

@@ -216,3 +233,2 @@ });

it('should set scale', () => {
const model = new Model();
expect(() => model.SetScale({ x: 1, y: 1, z: 1 })).not.toThrow();

@@ -222,3 +238,2 @@ });

it('should set visibility', () => {
const model = new Model();
expect(() => model.SetVisibility(true)).not.toThrow();

@@ -228,3 +243,2 @@ });

it('should set to world origin', () => {
const model = new Model();
model.userData.id = 'something';

@@ -242,3 +256,2 @@

it('should place on floor', () => {
const model = new Model();
model.userData.id = 'something';

@@ -264,3 +277,2 @@

const model = new Model();
model.userData.id = 'something';

@@ -319,3 +331,2 @@ model.position.set(0, 4, 0);

it('should onMove', () => {
const model = new Model();
model.userData.id = 'something';

@@ -330,20 +341,58 @@

it('should onSelect', () => {
const testLight = new Model();
testLight.userData.id = 'something';
model.userData.id = 'something';
expect(() => testLight.onSelect()).not.toThrow();
expect(() => model.onSelect()).not.toThrow();
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
expect(() => testLight.onSelect()).not.toThrow();
expect(() => model.onSelect()).not.toThrow();
});
it('should onDeselect', () => {
const testLight = new Model();
testLight.userData.id = 'something';
model.userData.id = 'something';
expect(() => testLight.onDeselect()).not.toThrow();
expect(() => model.onDeselect()).not.toThrow();
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
expect(() => testLight.onDeselect()).not.toThrow();
expect(() => model.onDeselect()).not.toThrow();
});
it('should set material', () => {
// apply invalid material should not crash
expect(() => model.SetMaterial({} as COMMaterial)).not.toThrow();
expect(model['_material']).not.toBeNull();
expect(() => model.SetMaterial({
color: 0xffffff,
roughness: 0,
metalness: 1,
} as COMMaterial)).not.toThrow();
expect((model['_material'] as MeshStandardMaterial).roughness).toBe(0);
expect((model['_material'] as MeshStandardMaterial).roughnessMap).toBeUndefined();
expect((model['_material'] as MeshStandardMaterial).metalness).toBe(1);
expect((model['_material'] as MeshStandardMaterial).metalnessMap).toBeUndefined();
expect(() => model.SetMaterial({
color: 0xff00ff,
roughness: 0,
roughnessMap: 'this is a Texture' as unknown as Texture,
metalness: 1,
metalnessMap: 'this is a Texture' as unknown as Texture,
} as COMMaterial)).not.toThrow();
expect((model['_material'] as MeshStandardMaterial).roughness).toBe(1);
expect((model['_material'] as MeshStandardMaterial).roughnessMap).toBeDefined();
expect((model['_material'] as MeshStandardMaterial).metalness).toBe(0);
expect((model['_material'] as MeshStandardMaterial).metalnessMap).toBeDefined();
});
it('should set model material when material already set before', () => {
model.SetMaterial({ roughness: 0.5 } as COMMaterial);
expect(() => model.SetModel(gltf)).not.toThrow();
expect((model['_mesh']?.material as MeshStandardMaterial).roughness).toBe(0.5);
});
it('should set material to model when model already set before', () => {
model.SetModel(gltf);
expect(() => model.SetMaterial({ roughness: 0.5 } as COMMaterial)).not.toThrow();
expect((model['_mesh']?.material as MeshStandardMaterial).roughness).toBe(0.5);
});
});

@@ -1,2 +0,2 @@

import { Box3, type Mesh, Object3D, Raycaster, Vector3, Vector3Like } from 'three';
import { Box3, Color, Mesh, MeshStandardMaterial, Object3D, Raycaster, Vector3, Vector3Like } from 'three';
import { DIVESelectable } from '../interface/Selectable';

@@ -8,2 +8,3 @@ import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';

import { findSceneRecursive } from '../helper/findSceneRecursive/findSceneRecursive';
import { type COMMaterial } from '../com/types';

@@ -27,2 +28,5 @@ /**

private _mesh: Mesh | null = null;
private _material: MeshStandardMaterial | null = null;
constructor() {

@@ -45,2 +49,14 @@ super();

this.boundingBox.expandByObject(child);
// only search for first mesh for now
if (!this._mesh && 'isMesh' in child) {
this._mesh = child as Mesh;
// if the material is already set, use it, otherwise set it from the model's material
if (this._material) {
this._mesh.material = this._material;
} else {
this._material = (child as Mesh).material as MeshStandardMaterial;
}
}
});

@@ -69,2 +85,35 @@

public SetMaterial(material: COMMaterial): void {
console.error('HERE', this._mesh);
// if there is no material, create a new one
if (!this._material) {
this._material = new MeshStandardMaterial();
}
this._material.color = new Color(material.color);
// if there is a roughness map, use it, otherwise use the roughness value
if (material.roughnessMap) {
this._material.roughnessMap = material.roughnessMap;
this._material.roughness = 1.0;
} else {
this._material.roughness = material.roughness;
}
// if there is a metalness map, use it, otherwise use the metalness value
if (material.metalnessMap) {
this._material.metalnessMap = material.metalnessMap;
this._material.metalness = 0.0;
} else {
this._material.metalness = material.metalness;
}
// if the mesh is already set, update the material
if (this._mesh) {
this._mesh.material = this._material;
}
}
public SetToWorldOrigin(): void {

@@ -71,0 +120,0 @@ this.position.set(0, 0, 0);

@@ -165,5 +165,5 @@ import { DIVEPrimitive } from '../Primitive';

this.roughness = 0;
this.roughnessMap = null;
this.roughnessMap = undefined;
this.metalness = 0;
this.metalnessMap = null;
this.metalnessMap = undefined;
return this;

@@ -414,5 +414,3 @@ }),

roughness: 0,
roughnessMap: null,
metalness: 1,
metalnessMap: null,
} as COMMaterial)).not.toThrow();

@@ -419,0 +417,0 @@ expect(material.roughness).toBe(0);

@@ -5,2 +5,3 @@ import DIVEModelRoot from '../ModelRoot';

import type DIVEScene from '../../../Scene';
import { type COMMaterial } from '../../../../com/types';

@@ -50,2 +51,3 @@ const mock_LoadGLTF = jest.fn().mockResolvedValue({});

this.SetVisibility = jest.fn();
this.SetMaterial = jest.fn();
this.PlaceOnFloor = mock_PlaceOnFloor;

@@ -100,2 +102,3 @@ this.removeFromParent = jest.fn();

scale: { x: 1, y: 2, z: 3 },
material: {} as COMMaterial,
})).not.toThrow();

@@ -102,0 +105,0 @@

@@ -55,2 +55,3 @@ import { Object3D } from "three";

if (object.visible !== undefined) (sceneObject as Model).SetVisibility(object.visible);
if (object.material !== undefined) (sceneObject as Model).SetMaterial(object.material);
}

@@ -57,0 +58,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc