--[[
Adorns a 3D model to a frame.
Returns a Model3D object.
--]]

function Module3DRotating:Attach3D(Frame,Model)
	--Create the base 3D item.
	local Model3D = Module3D:Attach3D(Frame,Model)
	local BaseEnd = Model3D.End
	local Ended = false
	
	--Set the default field of view and depth multiplier.
	Model3D.Camera.FieldOfView = 10
	Model3D:SetDepthMultiplier(1.2)
	
	--Set the ZIndex.
	Model3D.AdornFrame.ZIndex = Frame.ZIndex
	local ZIndexEvent = Frame:GetPropertyChangedSignal("ZIndex"):Connect(function()
		Model3D.AdornFrame.ZIndex = Frame.ZIndex
	end)
	
	--Set up the rotation.
	local UpwardRotation = CFrame.Angles(-ROTATION_UP,0,0)
	spawn(function()
		while not Ended do
			Model3D:SetCFrame(CFrame.Angles(0,(tick() * ROTATION_SPEED_MULTIPLIER) % (math.pi * 2),0) * UpwardRotation)
			RunService.Stepped:Wait()
		end
	end)
	Model3D:SetCFrame(CFrame.Angles(0,(tick() * ROTATION_SPEED_MULTIPLIER) % (math.pi * 2),0) * UpwardRotation)
	
	--[[
	Destroys the frame and unparents the model.
	--]]
	function Model3D:End()
		if not Ended then
			Ended = true
			ZIndexEvent:Disconnect()
			
			BaseEnd(self)
		end
	end
	
	--Return the 3D item.
	return Model3D
end

return Module3DRotating
